From adaf1c5fad422eb4eade51841f9cd72ef93c3652 Mon Sep 17 00:00:00 2001 From: Alex Kirk Date: Tue, 18 Feb 2025 15:17:09 +0100 Subject: [PATCH] Add args for EMA --- integrations/class-enable-mastodon-apps.php | 45 +++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/integrations/class-enable-mastodon-apps.php b/integrations/class-enable-mastodon-apps.php index a21d4025..98e726f7 100644 --- a/integrations/class-enable-mastodon-apps.php +++ b/integrations/class-enable-mastodon-apps.php @@ -21,6 +21,8 @@ public static function init() { add_filter( 'mastodon_api_timelines_args', array( get_called_class(), 'mastodon_api_timelines_args' ) ); add_filter( 'mastodon_api_account_statuses_args', array( get_called_class(), 'mastodon_api_timelines_args' ) ); add_filter( 'mastodon_api_view_post_types', array( get_called_class(), 'mastodon_api_view_post_types' ) ); + add_filter( 'mastodon_api_favourites_args', array( get_called_class(), 'mastodon_api_favourites_args' ), 10, 2 ); + add_filter( 'mastodon_api_bookmarks_args', array( get_called_class(), 'mastodon_api_bookmarks_args' ), 10, 2 ); } public static function mastodon_api_account_follow( $user_id ) { @@ -55,4 +57,47 @@ public static function mastodon_api_view_post_types( $view_post_types ) { $view_post_types[] = Friends::CPT; return $view_post_types; } + + public static function mastodon_api_favourites_args( $args, $user_id ) { + return self::mastodon_api_reaction_args( + apply_filters( 'friends_favourites_emoji', '2764' ), // ❤️ + $args, + $user_id + ); + } + public static function mastodon_api_bookmarks_args( $args, $user_id ) { + return self::mastodon_api_reaction_args( + apply_filters( 'friends_bookmarks_emoji', '2b50' ), // ⭐ + $args, + $user_id + ); + } + + protected static function mastodon_api_reaction_args( $reaction, $args, $user_id ) { + $tax_query = array(); + if ( isset( $args['tax_query'] ) ) { + $tax_query = $args['tax_query']; + } + + if ( ! empty( $tax_query ) ) { + $tax_query['relation'] = 'AND'; + } + Reactions::register_user_taxonomy( $user_id ); + + $reaction_query = array( + 'taxonomy' => 'friend-reaction-' . $user_id, + 'field' => 'slug', + 'terms' => array( strval( $reaction ) ), + ); + + if ( ! empty( $tax_query ) ) { + $tax_query[] = $reaction_query; + } else { + $tax_query = array( $reaction_query ); + } + + $args['tax_query'] = $tax_query; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query + + return $args; + } }