diff --git a/activitypub.php b/activitypub.php index e394dba11..ee61f22b6 100644 --- a/activitypub.php +++ b/activitypub.php @@ -39,21 +39,21 @@ * Initialize REST routes. */ function rest_init() { - Rest\Actors::init(); - Rest\Outbox::init(); - Rest\Inbox::init(); - Rest\Followers::init(); - Rest\Following::init(); - Rest\Webfinger::init(); - Rest\Comment::init(); - Rest\Server::init(); - Rest\Collection::init(); - Rest\Interaction::init(); - Rest\Post::init(); + ( new Rest\Actors() )->register_routes(); + ( new Rest\Outbox() )->register_routes(); + ( new Rest\Inbox() )->register_routes(); + ( new Rest\Followers() )->register_routes(); + ( new Rest\Following() )->register_routes(); + ( new Rest\Webfinger() )->register_routes(); + ( new Rest\Comment() )->register_routes(); + ( new Rest\Server() )->register_routes(); + ( new Rest\Collection() )->register_routes(); + ( new Rest\Interaction() )->register_routes(); + ( new Rest\Post() )->register_routes(); // Load NodeInfo endpoints only if blog is public. if ( is_blog_public() ) { - Rest\NodeInfo::init(); + ( new Rest\NodeInfo() )->register_routes(); } } \add_action( 'rest_api_init', __NAMESPACE__ . '\rest_init' ); diff --git a/includes/rest/class-actors.php b/includes/rest/class-actors.php index 0b56e2256..ddbee9f07 100644 --- a/includes/rest/class-actors.php +++ b/includes/rest/class-actors.php @@ -34,14 +34,6 @@ class Actors extends \WP_REST_Controller { */ protected $rest_base = '(?:users|actors)/(?P[\w\-\.]+)'; - /** - * Initialize the class, registering WordPress hooks. - */ - public static function init() { - $controller = new self(); - $controller->register_routes(); - } - /** * Register routes. */ diff --git a/includes/rest/class-collection.php b/includes/rest/class-collection.php index d06d116a1..721c9c691 100644 --- a/includes/rest/class-collection.php +++ b/includes/rest/class-collection.php @@ -34,14 +34,6 @@ class Collection extends \WP_REST_Controller { */ protected $namespace = ACTIVITYPUB_REST_NAMESPACE; - /** - * Initialize the class, registering WordPress hooks. - */ - public static function init() { - $controller = new self(); - $controller->register_routes(); - } - /** * Register routes. */ diff --git a/includes/rest/class-comment.php b/includes/rest/class-comment.php index 5fb071448..aacdfa243 100644 --- a/includes/rest/class-comment.php +++ b/includes/rest/class-comment.php @@ -25,14 +25,6 @@ class Comment extends \WP_REST_Controller { */ protected $namespace = ACTIVITYPUB_REST_NAMESPACE; - /** - * Initialize the class, registering WordPress hooks. - */ - public static function init() { - $controller = new self(); - $controller->register_routes(); - } - /** * Register routes. */ diff --git a/includes/rest/class-followers.php b/includes/rest/class-followers.php index 659178765..7aac1a917 100644 --- a/includes/rest/class-followers.php +++ b/includes/rest/class-followers.php @@ -35,14 +35,6 @@ class Followers extends \WP_REST_Controller { */ protected $rest_base = '(?:users|actors)/(?P[\w\-\.]+)/followers'; - /** - * Initialize the class, registering WordPress hooks. - */ - public static function init() { - $controller = new self(); - $controller->register_routes(); - } - /** * Register routes. */ diff --git a/includes/rest/class-following.php b/includes/rest/class-following.php index ce851a1bb..257836f21 100644 --- a/includes/rest/class-following.php +++ b/includes/rest/class-following.php @@ -38,10 +38,7 @@ class Following extends \WP_REST_Controller { /** * Initialize the class, registering WordPress hooks. */ - public static function init() { - $controller = new self(); - $controller->register_routes(); - + public function __construct() { \add_filter( 'activitypub_rest_following', array( self::class, 'default_following' ), 10, 2 ); } diff --git a/includes/rest/class-inbox.php b/includes/rest/class-inbox.php index 8c509f11d..4f7335950 100644 --- a/includes/rest/class-inbox.php +++ b/includes/rest/class-inbox.php @@ -38,17 +38,6 @@ class Inbox extends \WP_REST_Controller { */ protected $rest_base = '(?:users|actors)/(?P[\w\-\.]+)/inbox'; - /** - * Initialize the class, registering WordPress hooks. - */ - public static function init() { - $controller = new self(); - $controller->register_routes(); - - $server = new Server(); - $server->add_hooks(); - } - /** * Register routes. */ diff --git a/includes/rest/class-interaction.php b/includes/rest/class-interaction.php index 6bcd0a214..5f412a655 100644 --- a/includes/rest/class-interaction.php +++ b/includes/rest/class-interaction.php @@ -21,12 +21,11 @@ class Interaction extends \WP_REST_Controller { protected $namespace = ACTIVITYPUB_REST_NAMESPACE; /** - * Initialize the class, registering WordPress hooks. + * The base of this controller's route. + * + * @var string */ - public static function init() { - $controller = new self(); - $controller->register_routes(); - } + protected $rest_base = 'interactions'; /** * Register routes. @@ -34,7 +33,7 @@ public static function init() { public function register_routes() { \register_rest_route( $this->namespace, - '/interactions', + '/' . $this->rest_base, array( array( 'methods' => \WP_REST_Server::READABLE, diff --git a/includes/rest/class-nodeinfo.php b/includes/rest/class-nodeinfo.php index a6b5ff7e7..a3919bc5a 100644 --- a/includes/rest/class-nodeinfo.php +++ b/includes/rest/class-nodeinfo.php @@ -27,14 +27,6 @@ class Nodeinfo extends \WP_REST_Controller { */ protected $namespace = ACTIVITYPUB_REST_NAMESPACE; - /** - * Initialize the class, registering WordPress hooks. - */ - public static function init() { - $controller = new self(); - $controller->register_routes(); - } - /** * Register routes. */ diff --git a/includes/rest/class-outbox.php b/includes/rest/class-outbox.php index 3a9975366..523f917cf 100644 --- a/includes/rest/class-outbox.php +++ b/includes/rest/class-outbox.php @@ -33,14 +33,6 @@ class Outbox extends \WP_REST_Controller { */ protected $rest_base = '(?:users|actors)/(?P[\w\-\.]+)/outbox'; - /** - * Initialize the class, registering WordPress hooks. - */ - public static function init() { - $controller = new self(); - $controller->register_routes(); - } - /** * Register routes. */ diff --git a/includes/rest/class-server.php b/includes/rest/class-server.php index 6357f020a..0d8026a4b 100644 --- a/includes/rest/class-server.php +++ b/includes/rest/class-server.php @@ -30,10 +30,8 @@ class Server extends \WP_REST_Controller { /** * Initialize the class, registering WordPress hooks. */ - public static function init() { - $controller = new self(); - $controller->register_routes(); - $controller->add_hooks(); + public function __construct() { + $this->add_hooks(); } /** diff --git a/includes/rest/class-webfinger.php b/includes/rest/class-webfinger.php index 67a6a006d..33bb52f65 100644 --- a/includes/rest/class-webfinger.php +++ b/includes/rest/class-webfinger.php @@ -22,13 +22,6 @@ class Webfinger extends \WP_REST_Controller { */ protected $namespace = ACTIVITYPUB_REST_NAMESPACE; - /** - * Initialize the class, registering WordPress hooks. - */ - public static function init() { - ( new self() )->register_routes(); - } - /** * Register routes. */