1717
1818use function Activitypub \site_supports_blocks ;
1919
20- \defined ( ' ACTIVITYPUB_REST_NAMESPACE ' ) || \define ( ' ACTIVITYPUB_REST_NAMESPACE ' , ' activitypub/1.0 ' ) ;
20+ require_once __DIR__ . ' /includes/functions.php ' ;
2121
2222/**
23- * Initialize plugin
23+ * Initialize the plugin constants.
2424 */
25- function init () {
25+ function define_constants () {
26+ \defined ( 'ACTIVITYPUB_REST_NAMESPACE ' ) || \define ( 'ACTIVITYPUB_REST_NAMESPACE ' , 'activitypub/1.0 ' );
2627 \defined ( 'ACTIVITYPUB_EXCERPT_LENGTH ' ) || \define ( 'ACTIVITYPUB_EXCERPT_LENGTH ' , 400 );
2728 \defined ( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS ' ) || \define ( 'ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS ' , true );
2829 \defined ( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ' ) || \define ( 'ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ' , 3 );
@@ -35,13 +36,12 @@ function init() {
3536 \define ( 'ACTIVITYPUB_PLUGIN_BASENAME ' , plugin_basename ( __FILE__ ) );
3637 \define ( 'ACTIVITYPUB_PLUGIN_FILE ' , plugin_dir_path ( __FILE__ ) . '/ ' . basename ( __FILE__ ) );
3738 \define ( 'ACTIVITYPUB_PLUGIN_URL ' , plugin_dir_url ( __FILE__ ) );
39+ }
3840
39- Migration::init ();
40- Activitypub::init ();
41- Activity_Dispatcher::init ();
42- Collection \Followers::init ();
43-
44- // Configure the REST API route
41+ /**
42+ * Initialize REST routes.
43+ */
44+ function rest_init () {
4545 Rest \Users::init ();
4646 Rest \Outbox::init ();
4747 Rest \Inbox::init ();
@@ -51,23 +51,46 @@ function init() {
5151 Rest \Server::init ();
5252 Rest \Collection::init ();
5353
54- Admin::init ();
55- Hashtag::init ();
56- Shortcodes::init ();
57- Mention::init ();
58- Health_Check::init ();
59- Scheduler::init ();
54+ // load NodeInfo endpoints only if blog is public
55+ if ( \get_option ( 'blog_public ' , 1 ) ) {
56+ Rest \NodeInfo::init ();
57+ }
58+ }
59+ \add_action ( 'rest_api_init ' , __NAMESPACE__ . '\rest_init ' );
60+
61+ /**
62+ * Initialize plugin.
63+ */
64+ function plugin_init () {
65+ define_constants ();
66+
67+ \add_action ( 'init ' , array ( __NAMESPACE__ . '\Migration ' , 'init ' ) );
68+ \add_action ( 'init ' , array ( __NAMESPACE__ . '\Activitypub ' , 'init ' ) );
69+ \add_action ( 'init ' , array ( __NAMESPACE__ . '\Activity_Dispatcher ' , 'init ' ) );
70+ \add_action ( 'init ' , array ( __NAMESPACE__ . '\Collection\Followers ' , 'init ' ) );
71+ \add_action ( 'init ' , array ( __NAMESPACE__ . '\Admin ' , 'init ' ) );
72+ \add_action ( 'init ' , array ( __NAMESPACE__ . '\Hashtag ' , 'init ' ) );
73+ \add_action ( 'init ' , array ( __NAMESPACE__ . '\Shortcodes ' , 'init ' ) );
74+ \add_action ( 'init ' , array ( __NAMESPACE__ . '\Mention ' , 'init ' ) );
75+ \add_action ( 'init ' , array ( __NAMESPACE__ . '\Health_Check ' , 'init ' ) );
76+ \add_action ( 'init ' , array ( __NAMESPACE__ . '\Scheduler ' , 'init ' ) );
6077
6178 if ( site_supports_blocks () ) {
62- Blocks::init ();
79+ \add_action ( 'init ' , array ( __NAMESPACE__ . '\Blocks ' , 'init ' ) );
80+ }
81+
82+ $ debug_file = __DIR__ . '/includes/debug.php ' ;
83+ if ( \WP_DEBUG && file_exists ( $ debug_file ) && is_readable ( $ debug_file ) ) {
84+ require_once $ debug_file ;
85+ Debug::init ();
6386 }
6487}
65- \add_action ( 'init ' , __NAMESPACE__ . '\init ' );
88+ \add_action ( 'plugins_loaded ' , __NAMESPACE__ . '\plugin_init ' );
6689
6790/**
6891 * Class Autoloader
6992 */
70- spl_autoload_register (
93+ \ spl_autoload_register (
7194 function ( $ full_class ) {
7295 $ base_dir = __DIR__ . '/includes/ ' ;
7396 $ base = 'Activitypub \\' ;
@@ -100,19 +123,6 @@ function ( $full_class ) {
100123 }
101124);
102125
103- require_once __DIR__ . '/includes/functions.php ' ;
104-
105- // load NodeInfo endpoints only if blog is public
106- if ( \get_option ( 'blog_public ' , 1 ) ) {
107- Rest \NodeInfo::init ();
108- }
109-
110- $ debug_file = __DIR__ . '/includes/debug.php ' ;
111- if ( \WP_DEBUG && file_exists ( $ debug_file ) && is_readable ( $ debug_file ) ) {
112- require_once $ debug_file ;
113- Debug::init ();
114- }
115-
116126/**
117127 * Add plugin settings link
118128 */
0 commit comments