From a4d72b5fb6db0a230e4f43d9d478793f79cdd787 Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Thu, 7 Nov 2024 13:21:57 +0100 Subject: [PATCH 1/5] instantiate objects only if is_admin() --- classes/class-base.php | 47 ++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/classes/class-base.php b/classes/class-base.php index 7160e05974..3296910eb6 100644 --- a/classes/class-base.php +++ b/classes/class-base.php @@ -51,34 +51,37 @@ public function init() { } // Basic classes. - if ( \is_admin() && \current_user_can( 'publish_posts' ) ) { - $this->cached['admin__page'] = new \Progress_Planner\Admin\Page(); - $this->cached['admin__tour'] = new \Progress_Planner\Admin\Tour(); - $this->cached['admin__dashboard_widget_score'] = new \Progress_Planner\Admin\Dashboard_Widget_Score(); - $this->cached['admin__dashboard_widget_todo'] = new \Progress_Planner\Admin\Dashboard_Widget_Todo(); - } - $this->cached['admin__editor'] = new \Progress_Planner\Admin\Editor(); + if ( \is_admin() ) { - $this->cached['actions__content'] = new \Progress_Planner\Actions\Content(); - $this->cached['actions__content_scan'] = new \Progress_Planner\Actions\Content_Scan(); - $this->cached['actions__maintenance'] = new \Progress_Planner\Actions\Maintenance(); + if ( \current_user_can( 'publish_posts' ) ) { + $this->cached['admin__page'] = new \Progress_Planner\Admin\Page(); + $this->cached['admin__tour'] = new \Progress_Planner\Admin\Tour(); + $this->cached['admin__dashboard_widget_score'] = new \Progress_Planner\Admin\Dashboard_Widget_Score(); + $this->cached['admin__dashboard_widget_todo'] = new \Progress_Planner\Admin\Dashboard_Widget_Todo(); + } + $this->cached['admin__editor'] = new \Progress_Planner\Admin\Editor(); - // REST API. - $this->cached['rest_api'] = new Rest_API(); + $this->cached['actions__content'] = new \Progress_Planner\Actions\Content(); + $this->cached['actions__content_scan'] = new \Progress_Planner\Actions\Content_Scan(); + $this->cached['actions__maintenance'] = new \Progress_Planner\Actions\Maintenance(); - // Onboarding. - $this->cached['onboard'] = new Onboard(); + // Onboarding. + $this->cached['onboard'] = new Onboard(); - // To-do. - $this->cached['todo'] = new Todo(); + // To-do. + $this->cached['todo'] = new Todo(); - \add_filter( 'plugin_action_links_' . plugin_basename( PROGRESS_PLANNER_FILE ), [ $this, 'add_action_links' ] ); + \add_filter( 'plugin_action_links_' . plugin_basename( PROGRESS_PLANNER_FILE ), [ $this, 'add_action_links' ] ); - // We need to initialize some classes early. - $this->cached['page_types'] = new Page_Types(); - $this->cached['settings'] = new Settings(); - $this->cached['settings_page'] = new \Progress_Planner\Admin\Page_Settings(); - $this->cached['suggested_tasks'] = new Suggested_Tasks(); + // We need to initialize some classes early. + $this->cached['page_types'] = new Page_Types(); + $this->cached['settings'] = new Settings(); + $this->cached['settings_page'] = new \Progress_Planner\Admin\Page_Settings(); + $this->cached['suggested_tasks'] = new Suggested_Tasks(); + } + + // REST API. + $this->cached['rest_api'] = new Rest_API(); } /** From 4c7504f7790149199350691b8873c3b1dbad32c5 Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Thu, 7 Nov 2024 15:16:25 +0100 Subject: [PATCH 2/5] content hooks need to be registered in time --- classes/class-base.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/classes/class-base.php b/classes/class-base.php index 3296910eb6..035268a018 100644 --- a/classes/class-base.php +++ b/classes/class-base.php @@ -51,7 +51,7 @@ public function init() { } // Basic classes. - if ( \is_admin() ) { + if ( \is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) { if ( \current_user_can( 'publish_posts' ) ) { $this->cached['admin__page'] = new \Progress_Planner\Admin\Page(); @@ -61,7 +61,6 @@ public function init() { } $this->cached['admin__editor'] = new \Progress_Planner\Admin\Editor(); - $this->cached['actions__content'] = new \Progress_Planner\Actions\Content(); $this->cached['actions__content_scan'] = new \Progress_Planner\Actions\Content_Scan(); $this->cached['actions__maintenance'] = new \Progress_Planner\Actions\Maintenance(); @@ -80,6 +79,9 @@ public function init() { $this->cached['suggested_tasks'] = new Suggested_Tasks(); } + // Content actions. + $this->cached['actions__content'] = new \Progress_Planner\Actions\Content(); + // REST API. $this->cached['rest_api'] = new Rest_API(); } From d448d72aa56fe325ca6f0ead1f31b634411110ee Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Thu, 7 Nov 2024 15:25:00 +0100 Subject: [PATCH 3/5] another timing --- classes/class-base.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/classes/class-base.php b/classes/class-base.php index 035268a018..c541a420bd 100644 --- a/classes/class-base.php +++ b/classes/class-base.php @@ -73,7 +73,6 @@ public function init() { \add_filter( 'plugin_action_links_' . plugin_basename( PROGRESS_PLANNER_FILE ), [ $this, 'add_action_links' ] ); // We need to initialize some classes early. - $this->cached['page_types'] = new Page_Types(); $this->cached['settings'] = new Settings(); $this->cached['settings_page'] = new \Progress_Planner\Admin\Page_Settings(); $this->cached['suggested_tasks'] = new Suggested_Tasks(); @@ -82,6 +81,8 @@ public function init() { // Content actions. $this->cached['actions__content'] = new \Progress_Planner\Actions\Content(); + $this->cached['page_types'] = new Page_Types(); + // REST API. $this->cached['rest_api'] = new Rest_API(); } From e58bcf0d934da6d38aae1437edcc7299afc6a202 Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Fri, 22 Nov 2024 09:08:21 +0100 Subject: [PATCH 4/5] fix failed tests --- tests/phpunit/test-class-content-badges.php | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/phpunit/test-class-content-badges.php b/tests/phpunit/test-class-content-badges.php index 6244488e99..8271edfc60 100644 --- a/tests/phpunit/test-class-content-badges.php +++ b/tests/phpunit/test-class-content-badges.php @@ -44,6 +44,9 @@ public function test_wonderful_writer_0_progress() { foreach ( $group_badges as $badge ) { if ( 'wonderful-writer' === $badge->get_id() ) { $this->assertEquals( 0, $badge->progress_callback()['progress'] ); + + // Delete the badge value so it can be re-calculated. + $badge->clear_progress(); } } } @@ -65,6 +68,9 @@ public function test_wonderful_writer_50_progress() { foreach ( $group_badges as $badge ) { if ( 'wonderful-writer' === $badge->get_id() ) { $this->assertEquals( 50, $badge->progress_callback()['progress'] ); + + // Delete the badge value so it can be re-calculated. + $badge->clear_progress(); } } } @@ -86,6 +92,9 @@ public function test_wonderful_writer_100_progress() { foreach ( $group_badges as $badge ) { if ( 'wonderful-writer' === $badge->get_id() ) { $this->assertEquals( 100, $badge->progress_callback()['progress'] ); + + // Delete the badge value so it can be re-calculated. + $badge->clear_progress(); } } } @@ -107,6 +116,9 @@ public function test_bold_blogger_50_progress() { foreach ( $group_badges as $badge ) { if ( 'bold-blogger' === $badge->get_id() ) { $this->assertEquals( 50, $badge->progress_callback()['progress'] ); + + // Delete the badge value so it can be re-calculated. + $badge->clear_progress(); } } } @@ -128,6 +140,9 @@ public function test_bold_blogger_100_progress() { foreach ( $group_badges as $badge ) { if ( 'bold-blogger' === $badge->get_id() ) { $this->assertEquals( 100, $badge->progress_callback()['progress'] ); + + // Delete the badge value so it can be re-calculated. + $badge->clear_progress(); } } } @@ -149,6 +164,9 @@ public function test_bold_blogger_over_100_progress() { foreach ( $group_badges as $badge ) { if ( 'bold-blogger' === $badge->get_id() ) { $this->assertEquals( 100, $badge->progress_callback()['progress'] ); + + // Delete the badge value so it can be re-calculated. + $badge->clear_progress(); } } } @@ -170,6 +188,9 @@ public function test_awesome_author_50_progress() { foreach ( $group_badges as $badge ) { if ( 'awesome-author' === $badge->get_id() ) { $this->assertEquals( 50, $badge->progress_callback()['progress'] ); + + // Delete the badge value so it can be re-calculated. + $badge->clear_progress(); } } } @@ -191,6 +212,9 @@ public function test_awesome_author_100_progress() { foreach ( $group_badges as $badge ) { if ( 'awesome-author' === $badge->get_id() ) { $this->assertEquals( 100, $badge->progress_callback()['progress'] ); + + // Delete the badge value so it can be re-calculated. + $badge->clear_progress(); } } } @@ -212,6 +236,9 @@ public function test_awesome_author_over_100_progress() { foreach ( $group_badges as $badge ) { if ( 'awesome-author' === $badge->get_id() ) { $this->assertEquals( 100, $badge->progress_callback()['progress'] ); + + // Delete the badge value so it can be re-calculated. + $badge->clear_progress(); } } } From 3df05952e5d7dbae4c756f917144b75bb2e94ded Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Wed, 23 Jul 2025 09:35:13 +0200 Subject: [PATCH 5/5] not needed --- classes/class-base.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/classes/class-base.php b/classes/class-base.php index 04d5426335..3128cf71d2 100644 --- a/classes/class-base.php +++ b/classes/class-base.php @@ -101,7 +101,7 @@ public function init() { $this->get_actions__maintenance(); // Onboarding. - $this->get_onboard(); + $this->get_utils__onboard(); // To-do. $this->get_todo(); @@ -128,12 +128,6 @@ public function init() { $this->get_rest__stats(); $this->get_rest__tasks(); - // Onboarding. - $this->get_utils__onboard(); - - // To-do. - $this->get_todo(); - // Post-meta. if ( $this->is_pro_site() ) { $this->get_page_todos();