diff --git a/activitypub.php b/activitypub.php index 16aea4687..e789b9f58 100644 --- a/activitypub.php +++ b/activitypub.php @@ -33,6 +33,10 @@ Autoloader::register_path( __NAMESPACE__, __DIR__ . '/includes' ); +\register_activation_hook( __FILE__, array( Activitypub::class, 'activate' ) ); +\register_deactivation_hook( __FILE__, array( Activitypub::class, 'deactivate' ) ); +\register_uninstall_hook( __FILE__, array( Activitypub::class, 'uninstall' ) ); + /** * Initialize REST routes. */ @@ -68,6 +72,7 @@ function plugin_init() { \add_action( 'init', array( __NAMESPACE__ . '\Activitypub', 'init' ) ); \add_action( 'init', array( __NAMESPACE__ . '\Comment', 'init' ) ); \add_action( 'init', array( __NAMESPACE__ . '\Dispatcher', 'init' ) ); + \add_action( 'init', array( __NAMESPACE__ . '\Embed', 'init' ) ); \add_action( 'init', array( __NAMESPACE__ . '\Handler', 'init' ) ); \add_action( 'init', array( __NAMESPACE__ . '\Hashtag', 'init' ) ); \add_action( 'init', array( __NAMESPACE__ . '\Link', 'init' ) ); @@ -127,14 +132,6 @@ function plugin_admin_init() { } \add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_admin_init' ); -\register_activation_hook( - __FILE__, - array( - __NAMESPACE__ . '\Activitypub', - 'activate', - ) -); - /** * Redirect to the welcome page after plugin activation. * @@ -148,22 +145,6 @@ function activation_redirect( $plugin ) { } \add_action( 'activated_plugin', __NAMESPACE__ . '\activation_redirect' ); -\register_deactivation_hook( - __FILE__, - array( - __NAMESPACE__ . '\Activitypub', - 'deactivate', - ) -); - -\register_uninstall_hook( - __FILE__, - array( - __NAMESPACE__ . '\Activitypub', - 'uninstall', - ) -); - // Check for CLI env, to add the CLI commands.Add commentMore actions. if ( defined( 'WP_CLI' ) && WP_CLI ) { \WP_CLI::add_command( diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index a0982a520..be2468915 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -9,10 +9,10 @@ use Activitypub\Activity\Activity; use Activitypub\Collection\Actors; +use Activitypub\Collection\Extra_Fields; +use Activitypub\Collection\Followers; use Activitypub\Collection\Inbox; use Activitypub\Collection\Outbox; -use Activitypub\Collection\Followers; -use Activitypub\Collection\Extra_Fields; /** * ActivityPub Class. @@ -24,6 +24,12 @@ class Activitypub { * Initialize the class, registering WordPress hooks. */ public static function init() { + \add_action( 'init', array( self::class, 'add_rewrite_rules' ), 11 ); + \add_action( 'init', array( self::class, 'theme_compat' ), 11 ); + \add_action( 'init', array( self::class, 'register_user_meta' ), 11 ); + \add_action( 'init', array( self::class, 'register_post_types' ), 11 ); + \add_action( 'init', array( self::class, 'register_oembed_providers' ), 11 ); + \add_filter( 'template_include', array( self::class, 'render_activitypub_template' ), 99 ); \add_action( 'template_redirect', array( self::class, 'template_redirect' ) ); \add_filter( 'redirect_canonical', array( self::class, 'redirect_canonical' ), 10, 2 ); @@ -31,34 +37,21 @@ public static function init() { \add_filter( 'query_vars', array( self::class, 'add_query_vars' ) ); \add_filter( 'pre_get_avatar_data', array( self::class, 'pre_get_avatar_data' ), 11, 2 ); - // Add support for ActivityPub to custom post types. - $post_types = \get_option( 'activitypub_support_post_types', array( 'post' ) ); - - foreach ( $post_types as $post_type ) { - \add_post_type_support( $post_type, 'activitypub' ); - } - \add_action( 'wp_trash_post', array( self::class, 'trash_post' ), 1 ); \add_action( 'untrash_post', array( self::class, 'untrash_post' ), 1 ); - \add_action( 'init', array( self::class, 'add_rewrite_rules' ), 11 ); - \add_action( 'init', array( self::class, 'theme_compat' ), 11 ); - \add_action( 'user_register', array( self::class, 'user_register' ) ); - \add_filter( 'activitypub_get_actor_extra_fields', array( Extra_Fields::class, 'default_actor_extra_fields' ), 10, 2 ); - \add_filter( 'add_post_metadata', array( self::class, 'prevent_empty_post_meta' ), 10, 4 ); \add_filter( 'update_post_metadata', array( self::class, 'prevent_empty_post_meta' ), 10, 4 ); \add_filter( 'default_post_metadata', array( self::class, 'default_post_metadata' ), 10, 3 ); - \add_action( 'init', array( self::class, 'register_user_meta' ), 11 ); - - // Register several post_types. - self::register_post_types(); + \add_filter( 'activitypub_get_actor_extra_fields', array( Extra_Fields::class, 'default_actor_extra_fields' ), 10, 2 ); - self::register_oembed_providers(); - Embed::init(); + // Add support for ActivityPub to custom post types. + foreach ( \get_option( 'activitypub_support_post_types', array( 'post' ) ) as $post_type ) { + \add_post_type_support( $post_type, 'activitypub' ); + } } /** @@ -449,7 +442,7 @@ public static function theme_compat() { /** * Register Custom Post Types. */ - private static function register_post_types() { + public static function register_post_types() { \register_post_type( Actors::POST_TYPE, array( diff --git a/tests/includes/collection/class-test-inbox.php b/tests/includes/collection/class-test-inbox.php index 99968b019..d8325fc7a 100644 --- a/tests/includes/collection/class-test-inbox.php +++ b/tests/includes/collection/class-test-inbox.php @@ -215,7 +215,7 @@ public function test_duplicate_activity_prevention() { * Test post meta registration exists. */ public function test_post_meta_registration() { - Activitypub::init(); + Activitypub::register_post_types(); // Verify that post meta is registered for inbox post type. $registered_meta = \get_registered_meta_keys( 'post', Inbox::POST_TYPE );