From e05176cea54684b95abc652984ddf81390e3726e Mon Sep 17 00:00:00 2001 From: Matt Wiebe Date: Wed, 4 Oct 2023 23:55:13 -0500 Subject: [PATCH] Add a `ACTIVITYPUB_DISABLE_REWRITES` constant (#490) --- activitypub.php | 1 + includes/class-activitypub.php | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/activitypub.php b/activitypub.php index 91d9e0e..38a3d07 100644 --- a/activitypub.php +++ b/activitypub.php @@ -31,6 +31,7 @@ function define_constants() { \defined( 'ACTIVITYPUB_USERNAME_REGEXP' ) || \define( 'ACTIVITYPUB_USERNAME_REGEXP', '(?:([A-Za-z0-9_-]+)@((?:[A-Za-z0-9_-]+\.)+[A-Za-z]+))' ); \defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "[ap_title]\n\n[ap_content]\n\n[ap_hashtags]\n\n[ap_shortlink]" ); \defined( 'ACTIVITYPUB_AUTHORIZED_FETCH' ) || \define( 'ACTIVITYPUB_AUTHORIZED_FETCH', false ); + \defined( 'ACTIVITYPUB_DISABLE_REWRITES' ) || \define( 'ACTIVITYPUB_DISABLE_REWRITES', false ); \define( 'ACTIVITYPUB_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); \define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index 6ac860e..24228f4 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -227,6 +227,12 @@ class Activitypub { * Add rewrite rules */ public static function add_rewrite_rules() { + // If another system needs to take precedence over the ActivityPub rewrite rules, + // they can define their own and will manually call the appropriate functions as required. + if ( ACTIVITYPUB_DISABLE_REWRITES ) { + return; + } + if ( ! \class_exists( 'Webfinger' ) ) { \add_rewrite_rule( '^.well-known/webfinger',