From 47bd6eb3b4a1ebda67cae83f299f2014a2058617 Mon Sep 17 00:00:00 2001 From: Greg Date: Mon, 16 Jan 2023 13:19:26 -0500 Subject: [PATCH] Move the activitypub endpoint rule to the main rewrite addition function. This is for two reasons: - No need to add the endpoint every time the plugin loads. - The old code didn't flush the rewrite rules, making the endpoint non-functional until something did (like the user saving the permalink settings) --- activitypub.php | 2 ++ includes/class-activitypub.php | 8 -------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/activitypub.php b/activitypub.php index d9f2a61..9dd8f82 100644 --- a/activitypub.php +++ b/activitypub.php @@ -116,6 +116,8 @@ function add_rewrite_rules() { \add_rewrite_rule( '^.well-known/nodeinfo', 'index.php?rest_route=/activitypub/1.0/nodeinfo/discovery', 'top' ); \add_rewrite_rule( '^.well-known/x-nodeinfo2', 'index.php?rest_route=/activitypub/1.0/nodeinfo2', 'top' ); } + + \add_rewrite_endpoint( 'activitypub', EP_AUTHORS | EP_PERMALINK | EP_PAGES ); } \add_action( 'init', '\Activitypub\add_rewrite_rules', 1 ); diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index ea3532a..00b413f 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -13,7 +13,6 @@ class Activitypub { public static function init() { \add_filter( 'template_include', array( '\Activitypub\Activitypub', 'render_json_template' ), 99 ); \add_filter( 'query_vars', array( '\Activitypub\Activitypub', 'add_query_vars' ) ); - \add_action( 'init', array( '\Activitypub\Activitypub', 'add_rewrite_endpoint' ) ); \add_filter( 'pre_get_avatar_data', array( '\Activitypub\Activitypub', 'pre_get_avatar_data' ), 11, 2 ); // Add support for ActivityPub to custom post types @@ -96,13 +95,6 @@ class Activitypub { return $vars; } - /** - * Add our rewrite endpoint to permalinks and pages. - */ - public static function add_rewrite_endpoint() { - \add_rewrite_endpoint( 'activitypub', EP_AUTHORS | EP_PERMALINK | EP_PAGES ); - } - /** * Schedule Activities. *