From 6ddbe25852400535c0e9e3ff80d95c0e0b3383b6 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Wed, 21 Jun 2023 15:46:25 +0200 Subject: [PATCH] overwrite activity-object-user on single_user_mode --- includes/class-activitypub.php | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index cd95fc7..733ae00 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -30,6 +30,15 @@ class Activitypub { \add_action( 'init', array( self::class, 'add_rewrite_rules' ) ); \add_action( 'after_setup_theme', array( self::class, 'theme_compat' ), 99 ); + + if ( is_single_user_mode() ) { + add_filter( + 'activitypub_post_user_id', + function( $actor ) { + return User_Factory::BLOG_USER_ID; + } + ); + } } /** @@ -71,12 +80,15 @@ class Activitypub { * @return string The new path to the JSON template. */ public static function render_json_template( $template ) { - if ( ! \is_author() && ! \is_singular() && ! \is_home() ) { + if ( ! is_activitypub_request() ) { return $template; } - // Ensure that edge caches know that this page can deliver both HTML and JSON. - header( 'Vary: Accept' ); + $json_template = false; + + if ( ! \is_author() && ! \is_singular() && ! \is_home() ) { + return $template; + } // check if user can publish posts if ( \is_author() && ! user_can( \get_the_author_meta( 'ID' ), 'publish_posts' ) ) { @@ -91,15 +103,12 @@ class Activitypub { $json_template = ACTIVITYPUB_PLUGIN_DIR . '/templates/blog-json.php'; } - if ( is_activitypub_request() ) { - if ( ACTIVITYPUB_SECURE_MODE ) { - $verification = Signature::verify_http_signature( $_SERVER ); - if ( \is_wp_error( $verification ) ) { - // fallback as template_loader can't return http headers - return $template; - } + if ( ACTIVITYPUB_SECURE_MODE ) { + $verification = Signature::verify_http_signature( $_SERVER ); + if ( \is_wp_error( $verification ) ) { + // fallback as template_loader can't return http headers + return $template; } - return $json_template; }