From 329d97e8c85f90f15f9153273d519a0718feeddf Mon Sep 17 00:00:00 2001 From: Aleksandr Lilik Date: Tue, 12 Dec 2023 20:02:05 +0200 Subject: [PATCH] Hooks. Actions : before_add_favorite, before_remove_favorite and Filter : favorites_before_update_meta added --- app/Entities/Favorite/SyncSingleFavorite.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Entities/Favorite/SyncSingleFavorite.php b/app/Entities/Favorite/SyncSingleFavorite.php index 7652087..15b4e00 100644 --- a/app/Entities/Favorite/SyncSingleFavorite.php +++ b/app/Entities/Favorite/SyncSingleFavorite.php @@ -1,4 +1,4 @@ -user->isFavorite($this->post_id, $this->site_id) ){ + do_action('before_remove_favorite',$this->post_id); $favorites = $this->removeFavorite(); setcookie( 'simplefavorites', json_encode( $favorites ), time() + apply_filters( 'simplefavorites_cookie_expiration_interval', 31556926 ), '/' ); return; } $favorites = $this->addFavorite(); + do_action('before_add_favorite',$this->post_id); setcookie( 'simplefavorites', json_encode( $favorites ), time() + apply_filters( 'simplefavorites_cookie_expiration_interval', 31556926 ), '/' ); return; } @@ -67,6 +69,7 @@ public function cookie() public function updateUserMeta($favorites) { if ( !is_user_logged_in() ) return; + $favorites = apply_filters('favorites_before_update_meta', $favorites); update_user_meta( intval(get_current_user_id()), 'simplefavorites', $favorites ); } @@ -123,11 +126,11 @@ private function addFavorite() ]; } foreach( $favorites[$key]['groups'] as $group_key => $group){ - if ( $group['group_id'] == $this->group_id ) + if ( $group['group_id'] == $this->group_id ) $favorites[$key]['groups'][$group_key]['posts'][] = $this->post_id; } } $this->updateUserMeta($favorites); return $favorites; } -} \ No newline at end of file +}