Plugin loading refactor (#485)
* Plugin loading refactor * changed load order for REST endpoints --------- Co-authored-by: Matthias Pfefferle <pfefferle@users.noreply.github.com>
This commit is contained in:
parent
7b0fc062d7
commit
9907585570
11 changed files with 56 additions and 75 deletions
|
@ -17,12 +17,13 @@ namespace Activitypub;
|
|||
|
||||
use function Activitypub\site_supports_blocks;
|
||||
|
||||
\defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' );
|
||||
require_once __DIR__ . '/includes/functions.php';
|
||||
|
||||
/**
|
||||
* Initialize plugin
|
||||
* Initialize the plugin constants.
|
||||
*/
|
||||
function init() {
|
||||
function define_constants() {
|
||||
\defined( 'ACTIVITYPUB_REST_NAMESPACE' ) || \define( 'ACTIVITYPUB_REST_NAMESPACE', 'activitypub/1.0' );
|
||||
\defined( 'ACTIVITYPUB_EXCERPT_LENGTH' ) || \define( 'ACTIVITYPUB_EXCERPT_LENGTH', 400 );
|
||||
\defined( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS' ) || \define( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS', true );
|
||||
\defined( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS' ) || \define( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS', 3 );
|
||||
|
@ -35,13 +36,12 @@ function init() {
|
|||
\define( 'ACTIVITYPUB_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
|
||||
\define( 'ACTIVITYPUB_PLUGIN_FILE', plugin_dir_path( __FILE__ ) . '/' . basename( __FILE__ ) );
|
||||
\define( 'ACTIVITYPUB_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
||||
}
|
||||
|
||||
Migration::init();
|
||||
Activitypub::init();
|
||||
Activity_Dispatcher::init();
|
||||
Collection\Followers::init();
|
||||
|
||||
// Configure the REST API route
|
||||
/**
|
||||
* Initialize REST routes.
|
||||
*/
|
||||
function rest_init() {
|
||||
Rest\Users::init();
|
||||
Rest\Outbox::init();
|
||||
Rest\Inbox::init();
|
||||
|
@ -51,23 +51,46 @@ function init() {
|
|||
Rest\Server::init();
|
||||
Rest\Collection::init();
|
||||
|
||||
Admin::init();
|
||||
Hashtag::init();
|
||||
Shortcodes::init();
|
||||
Mention::init();
|
||||
Health_Check::init();
|
||||
Scheduler::init();
|
||||
|
||||
if ( site_supports_blocks() ) {
|
||||
Blocks::init();
|
||||
// load NodeInfo endpoints only if blog is public
|
||||
if ( \get_option( 'blog_public', 1 ) ) {
|
||||
Rest\NodeInfo::init();
|
||||
}
|
||||
}
|
||||
\add_action( 'init', __NAMESPACE__ . '\init' );
|
||||
\add_action( 'rest_api_init', __NAMESPACE__ . '\rest_init' );
|
||||
|
||||
/**
|
||||
* Initialize plugin.
|
||||
*/
|
||||
function plugin_init() {
|
||||
define_constants();
|
||||
|
||||
\add_action( 'init', array( __NAMESPACE__ . '\Migration', 'init' ) );
|
||||
\add_action( 'init', array( __NAMESPACE__ . '\Activitypub', 'init' ) );
|
||||
\add_action( 'init', array( __NAMESPACE__ . '\Activity_Dispatcher', 'init' ) );
|
||||
\add_action( 'init', array( __NAMESPACE__ . '\Collection\Followers', 'init' ) );
|
||||
\add_action( 'init', array( __NAMESPACE__ . '\Admin', 'init' ) );
|
||||
\add_action( 'init', array( __NAMESPACE__ . '\Hashtag', 'init' ) );
|
||||
\add_action( 'init', array( __NAMESPACE__ . '\Shortcodes', 'init' ) );
|
||||
\add_action( 'init', array( __NAMESPACE__ . '\Mention', 'init' ) );
|
||||
\add_action( 'init', array( __NAMESPACE__ . '\Health_Check', 'init' ) );
|
||||
\add_action( 'init', array( __NAMESPACE__ . '\Scheduler', 'init' ) );
|
||||
|
||||
if ( site_supports_blocks() ) {
|
||||
\add_action( 'init', array( __NAMESPACE__ . '\Blocks', 'init' ) );
|
||||
}
|
||||
|
||||
$debug_file = __DIR__ . '/includes/debug.php';
|
||||
if ( \WP_DEBUG && file_exists( $debug_file ) && is_readable( $debug_file ) ) {
|
||||
require_once $debug_file;
|
||||
Debug::init();
|
||||
}
|
||||
}
|
||||
\add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_init' );
|
||||
|
||||
/**
|
||||
* Class Autoloader
|
||||
*/
|
||||
spl_autoload_register(
|
||||
\spl_autoload_register(
|
||||
function ( $full_class ) {
|
||||
$base_dir = __DIR__ . '/includes/';
|
||||
$base = 'Activitypub\\';
|
||||
|
@ -100,19 +123,6 @@ spl_autoload_register(
|
|||
}
|
||||
);
|
||||
|
||||
require_once __DIR__ . '/includes/functions.php';
|
||||
|
||||
// load NodeInfo endpoints only if blog is public
|
||||
if ( \get_option( 'blog_public', 1 ) ) {
|
||||
Rest\NodeInfo::init();
|
||||
}
|
||||
|
||||
$debug_file = __DIR__ . '/includes/debug.php';
|
||||
if ( \WP_DEBUG && file_exists( $debug_file ) && is_readable( $debug_file ) ) {
|
||||
require_once $debug_file;
|
||||
Debug::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add plugin settings link
|
||||
*/
|
||||
|
|
|
@ -25,7 +25,7 @@ class Collection {
|
|||
* Initialize the class, registering WordPress hooks
|
||||
*/
|
||||
public static function init() {
|
||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||
self::register_routes();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,7 +22,7 @@ class Followers {
|
|||
* Initialize the class, registering WordPress hooks
|
||||
*/
|
||||
public static function init() {
|
||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||
self::register_routes();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,7 +18,8 @@ class Following {
|
|||
* Initialize the class, registering WordPress hooks
|
||||
*/
|
||||
public static function init() {
|
||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||
self::register_routes();
|
||||
|
||||
\add_filter( 'activitypub_rest_following', array( self::class, 'default_following' ), 10, 2 );
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ class Inbox {
|
|||
* Initialize the class, registering WordPress hooks
|
||||
*/
|
||||
public static function init() {
|
||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||
self::register_routes();
|
||||
|
||||
\add_action( 'activitypub_inbox_create', array( self::class, 'handle_create' ), 10, 2 );
|
||||
}
|
||||
|
|
|
@ -17,7 +17,8 @@ class Nodeinfo {
|
|||
* Initialize the class, registering WordPress hooks
|
||||
*/
|
||||
public static function init() {
|
||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||
self::register_routes();
|
||||
|
||||
\add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_discovery' ), 10, 2 );
|
||||
\add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_discovery' ), 10 );
|
||||
}
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
namespace Activitypub\Rest;
|
||||
|
||||
/**
|
||||
* ActivityPub OStatus REST-Class
|
||||
*
|
||||
* @author Matthias Pfefferle
|
||||
*
|
||||
* @see https://www.w3.org/community/ostatus/
|
||||
*/
|
||||
class Ostatus {
|
||||
/**
|
||||
* Register routes
|
||||
*/
|
||||
public static function register_routes() {
|
||||
\register_rest_route(
|
||||
ACTIVITYPUB_REST_NAMESPACE,
|
||||
'/ostatus/remote-follow',
|
||||
array(
|
||||
array(
|
||||
'methods' => \WP_REST_Server::READABLE,
|
||||
'callback' => array( '\Activitypub\Rest\Ostatus', 'get' ),
|
||||
// 'args' => self::request_parameters(),
|
||||
'permission_callback' => '__return_true',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static function get() {
|
||||
// @todo implement
|
||||
}
|
||||
}
|
|
@ -24,7 +24,7 @@ class Outbox {
|
|||
* Initialize the class, registering WordPress hooks
|
||||
*/
|
||||
public static function init() {
|
||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||
self::register_routes();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,7 +18,8 @@ class Server {
|
|||
* Initialize the class, registering WordPress hooks
|
||||
*/
|
||||
public static function init() {
|
||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||
self::register_routes();
|
||||
|
||||
\add_filter( 'rest_request_before_callbacks', array( self::class, 'authorize_activitypub_requests' ), 10, 3 );
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ class Users {
|
|||
* Initialize the class, registering WordPress hooks
|
||||
*/
|
||||
public static function init() {
|
||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||
self::register_routes();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,7 +19,8 @@ class Webfinger {
|
|||
* @return void
|
||||
*/
|
||||
public static function init() {
|
||||
\add_action( 'rest_api_init', array( self::class, 'register_routes' ) );
|
||||
self::register_routes();
|
||||
|
||||
\add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 10, 3 );
|
||||
\add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 99, 2 );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue