diff --git a/README.md b/README.md index d7a9662..3a3a360 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ In order for webfinger to work, it must be mapped to the root directory of the U Add the following to the .htaccess file in the root directory: - RedirectMatch "^\/\.well-known(.*)$" "\/blog\/\.well-known$1" + RedirectMatch "^\/\.well-known/(webfinger|nodeinfo|x-nodeinfo2)(.*)$" "\/blog\/\.well-known$1$2" Where 'blog' is the path to the subdirectory at which your blog resides. @@ -115,6 +115,8 @@ Project maintained on GitHub at [automattic/wordpress-activitypub](https://githu ### Next ### +* Compatibility: add a new conditional, `\Activitypub\is_activitypub_request()`, to allow third-party plugins to detect ActivityPub requests. +* Compatibility: add hooks to allow modifying images returned in ActivityPub requests. * Compatibility: indicate that the plugin is compatible and has been tested with the latest version of WordPress, 6.2. ### 0.17.0 ### diff --git a/activitypub.php b/activitypub.php index 6d1a793..8ca78f8 100644 --- a/activitypub.php +++ b/activitypub.php @@ -53,7 +53,7 @@ function init() { Health_Check::init(); Scheduler::init(); } -\add_action( 'plugins_loaded', '\Activitypub\init' ); +\add_action( 'plugins_loaded', __NAMESPACE__ . '\init' ); /** * Class Autoloader @@ -142,11 +142,25 @@ function plugin_settings_link( $actions ) { /** * Only load code that needs BuddyPress to run once BP is loaded and initialized. */ -function enable_buddypress_features() { - require_once \dirname( __FILE__ ) . '/integration/class-buddypress.php'; - Integration\Buddypress::init(); -} -add_action( 'bp_include', '\Activitypub\enable_buddypress_features' ); +add_action( + 'bp_include', + function() { + require_once \dirname( __FILE__ ) . '/integration/class-buddypress.php'; + Integration\Buddypress::init(); + }, + 0 +); + +add_action( + 'plugins_loaded', + function() { + if ( defined( 'WP_SWEEP_VERSION' ) ) { + require_once \dirname( __FILE__ ) . '/integration/class-wp-sweep.php'; + Integration\Wp_Sweep::init(); + } + }, + 0 +); /** * `get_plugin_data` wrapper diff --git a/includes/collection/class-followers.php b/includes/collection/class-followers.php index 8a271f6..142a9a1 100644 --- a/includes/collection/class-followers.php +++ b/includes/collection/class-followers.php @@ -19,6 +19,7 @@ use function Activitypub\get_remote_metadata_by_actor; */ class Followers { const TAXONOMY = 'activitypub-followers'; + const CACHE_KEY_INBOXES = 'follower_inboxes_%s'; /** * Register WordPress hooks/actions and register Taxonomy @@ -225,6 +226,7 @@ class Followers { if ( is_wp_error( $result ) ) { return $result; } else { + wp_cache_delete( sprintf( self::CACHE_KEY_INBOXES, $user_id ), 'activitypub' ); return $follower; } } @@ -238,6 +240,7 @@ class Followers { * @return bool|WP_Error True on success, false or WP_Error on failure. */ public static function remove_follower( $user_id, $actor ) { + wp_cache_delete( sprintf( self::CACHE_KEY_INBOXES, $user_id ), 'activitypub' ); return wp_remove_object_terms( $user_id, $actor, self::TAXONOMY ); } @@ -338,6 +341,25 @@ class Followers { return $items; } + /** + * Get all Followers + * + * @param array $args The WP_Term_Query arguments. + * + * @return array The Term list of Followers. + */ + public static function get_all_followers( $args = array() ) { + $defaults = array( + 'taxonomy' => self::TAXONOMY, + 'hide_empty' => false, + ); + + $args = wp_parse_args( $args, $defaults ); + $terms = new WP_Term_Query( $args ); + + return $terms->get_terms(); + } + /** * Count the total number of followers * @@ -357,6 +379,13 @@ class Followers { * @return array The list of Inboxes */ public static function get_inboxes( $user_id ) { + $cache_key = sprintf( self::CACHE_KEY_INBOXES, $user_id ); + $inboxes = wp_cache_get( $cache_key, 'activitypub' ); + + if ( $inboxes ) { + return $inboxes; + } + // get all Followers of a ID of the WordPress User $terms = new WP_Term_Query( array( @@ -390,7 +419,10 @@ class Followers { ) ); - return array_filter( $results ); + $inboxes = array_filter( $results ); + wp_cache_set( $cache_key, $inboxes, 'activitypub' ); + + return $inboxes; } /** diff --git a/integration/class-buddypress.php b/integration/class-buddypress.php index 1087f47..e4ec40e 100644 --- a/integration/class-buddypress.php +++ b/integration/class-buddypress.php @@ -3,7 +3,7 @@ namespace Activitypub\Integration; class Buddypress { public static function init() { - \add_filter( 'activitypub_json_author_array', array( 'Activitypub\Integration\Buddypress', 'add_user_metadata' ), 11, 2 ); + \add_filter( 'activitypub_json_author_array', array( self::class, 'add_user_metadata' ), 11, 2 ); } public static function add_user_metadata( $object, $author_id ) { diff --git a/integration/class-wp-sweep.php b/integration/class-wp-sweep.php new file mode 100644 index 0000000..730edba --- /dev/null +++ b/integration/class-wp-sweep.php @@ -0,0 +1,50 @@ + 'ids' ) ); + + $excluded_term_ids = array_merge( $excluded_term_ids, $followers ); + + return array_unique( $excluded_term_ids ); + } +} diff --git a/readme.txt b/readme.txt index c08f455..0d2727b 100644 --- a/readme.txt +++ b/readme.txt @@ -94,7 +94,7 @@ In order for webfinger to work, it must be mapped to the root directory of the U Add the following to the .htaccess file in the root directory: - RedirectMatch "^\/\.well-known(.*)$" "\/blog\/\.well-known$1" + RedirectMatch "^\/\.well-known/(webfinger|nodeinfo|x-nodeinfo2)(.*)$" "\/blog\/\.well-known$1$2" Where 'blog' is the path to the subdirectory at which your blog resides. diff --git a/templates/settings.php b/templates/settings.php index 2bfaed4..0daca17 100644 --- a/templates/settings.php +++ b/templates/settings.php @@ -120,8 +120,8 @@
  • - name, $support_post_types, true ) ); ?> /> - + name, $support_post_types, true ) ); ?> /> +