is_user_connected() ) ) { \add_filter( 'activitypub_following_row_actions', array( self::class, 'add_reader_link' ), 10, 2 ); \add_filter( 'pre_option_activitypub_following_ui', array( self::class, 'pre_option_activitypub_following_ui' ) ); } \add_action( 'load-post-new.php', array( self::class, 'adapt_post_share' ) ); } /** * Add ActivityPub options to the Jetpack sync allow list. * * @since 8.1.0 * * @param array $allow_list The Jetpack sync options allow list. * * @return array The allow list with ActivityPub options. */ public static function add_sync_options( $allow_list ) { $allow_list[] = 'activitypub_blog_identifier'; $allow_list[] = 'activitypub_blog_description'; $allow_list[] = 'activitypub_header_image'; $allow_list[] = 'activitypub_actor_mode'; return $allow_list; } /** * Add ActivityPub meta keys to the Jetpack sync allow list. * * @param array $allow_list The Jetpack sync allow list. * * @return array The Jetpack sync allow list with ActivityPub meta keys. */ public static function add_sync_meta( $allow_list ) { $allow_list[] = Followers::FOLLOWER_META_KEY; $allow_list[] = Following::FOLLOWING_META_KEY; return $allow_list; } /** * Add ActivityPub comment meta keys to the Jetpack sync allow list. * * @param array $allow_list The Jetpack sync allow list. * * @return array The Jetpack sync allow list with ActivityPub comment meta keys. */ public static function add_sync_comment_meta( $allow_list ) { $allow_list[] = 'avatar_url'; return $allow_list; } /** * Add custom comment types to the list of comment types. * * @param array $comment_types Default comment types. * * @return array The comment types with ActivityPub types added. */ public static function add_comment_types( $comment_types ) { $comment_types[] = 'like'; $comment_types[] = 'quote'; $comment_types[] = 'repost'; return array_unique( $comment_types ); } /** * Add a "Reader" link to the bulk actions dropdown on the following list screen. * * @param array $actions The bulk actions. * @param array $item The current following item. * * @return array The bulk actions with the "Reader" link. */ public static function add_reader_link( $actions, $item ) { // Do not show the link for pending follow requests. if ( 'pending' === $item['status'] ) { return $actions; } $feed = \get_post_meta( $item['id'], '_activitypub_actor_feed', true ); // Generate Reader URL based on environment. if ( \defined( 'IS_WPCOM' ) && IS_WPCOM ) { if ( empty( $feed['feed_id'] ) ) { return $actions; // No feed_id available on WPCOM. } $url = sprintf( 'https://wordpress.com/reader/feeds/%d', (int) $feed['feed_id'] ); } else { $url = sprintf( 'https://wordpress.com/reader/feeds/lookup/%s', rawurlencode( $item['identifier'] ) ); } return array_merge( array( 'reader' => sprintf( '%2$s %3$s', esc_url( $url ), esc_html__( 'View Feed', 'activitypub' ), /* translators: Hidden accessibility text. */ esc_html__( '(opens in a new tab)', 'activitypub' ) ), ), $actions ); } /** * Force the ActivityPub Following UI to be enabled when Jetpack is active. * * @return string '1' to enable the ActivityPub Following UI. */ public static function pre_option_activitypub_following_ui() { return '1'; } /** * Adapt the parameters for a post share request to be compatible with the Federated Reply block. */ public static function adapt_post_share() { if ( ! isset( $_GET['is_post_share'], $_GET['url'] ) || ! $_GET['is_post_share'] ) { // phpcs:ignore WordPress.Security return; } $url = \sanitize_url( \wp_unslash( $_GET['url'] ) ); // phpcs:ignore WordPress.Security.NonceVerification if ( is_activity_object( Http::get_remote_object( $url ) ) ) { $args = array( 'post_type' => 'post', 'in_reply_to' => $url, ); \wp_safe_redirect( \add_query_arg( $args, \admin_url( 'post-new.php' ) ) ); exit; } } }