From ef5449587f7a95869e50e432434fe909c28ff035 Mon Sep 17 00:00:00 2001 From: Filip Ilic Date: Fri, 20 Dec 2024 08:28:14 +0100 Subject: [PATCH] base abstract class for local tasks --- .../providers/class-content-abstract.php | 9 ++++- .../providers/class-content-create.php | 12 +------ .../providers/class-content-update.php | 12 +------ .../providers/class-core-update.php | 20 +++++------ .../providers/class-local-tasks-abstract.php | 34 +++++++++++++++++++ .../providers/class-settings-saved.php | 13 +------ 6 files changed, 53 insertions(+), 47 deletions(-) create mode 100644 classes/suggested-tasks/local-tasks/providers/class-local-tasks-abstract.php diff --git a/classes/suggested-tasks/local-tasks/providers/class-content-abstract.php b/classes/suggested-tasks/local-tasks/providers/class-content-abstract.php index bf6557ae6..29f786efb 100644 --- a/classes/suggested-tasks/local-tasks/providers/class-content-abstract.php +++ b/classes/suggested-tasks/local-tasks/providers/class-content-abstract.php @@ -10,7 +10,14 @@ /** * Add tasks for content updates. */ -abstract class Content_Abstract { +abstract class Content_Abstract extends Local_Tasks_Abstract { + + /** + * The capability required to perform the task. + * + * @var string + */ + protected $capability = 'edit_others_posts'; /** * Get the task ID. diff --git a/classes/suggested-tasks/local-tasks/providers/class-content-create.php b/classes/suggested-tasks/local-tasks/providers/class-content-create.php index 19df97ae6..f7b58198b 100644 --- a/classes/suggested-tasks/local-tasks/providers/class-content-create.php +++ b/classes/suggested-tasks/local-tasks/providers/class-content-create.php @@ -7,13 +7,12 @@ namespace Progress_Planner\Suggested_Tasks\Local_Tasks\Providers; -use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Local_Tasks_Interface; use Progress_Planner\Activities\Content_Helpers; /** * Add tasks for content creation. */ -class Content_Create extends Content_Abstract implements Local_Tasks_Interface { +class Content_Create extends Content_Abstract { /** * The provider ID. @@ -186,13 +185,4 @@ public function get_task_details( $task_id ) { return $task_details; } - - /** - * Check if the user has the capability to create a post. - * - * @return bool - */ - public function capability_required() { - return \current_user_can( 'edit_others_posts' ); - } } diff --git a/classes/suggested-tasks/local-tasks/providers/class-content-update.php b/classes/suggested-tasks/local-tasks/providers/class-content-update.php index fa5e075a9..43a359781 100644 --- a/classes/suggested-tasks/local-tasks/providers/class-content-update.php +++ b/classes/suggested-tasks/local-tasks/providers/class-content-update.php @@ -8,12 +8,11 @@ namespace Progress_Planner\Suggested_Tasks\Local_Tasks\Providers; use Progress_Planner\Suggested_Tasks\Local_Tasks\Local_Task_Factory; -use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Local_Tasks_Interface; /** * Add tasks for content updates. */ -class Content_Update extends Content_Abstract implements Local_Tasks_Interface { +class Content_Update extends Content_Abstract { /** * The provider ID. @@ -190,13 +189,4 @@ public function transition_post_status( $new_status, $old_status, $post ) { } } } - - /** - * Check if the user has the capability to update a post. - * - * @return bool - */ - public function capability_required() { - return \current_user_can( 'edit_others_posts' ); - } } diff --git a/classes/suggested-tasks/local-tasks/providers/class-core-update.php b/classes/suggested-tasks/local-tasks/providers/class-core-update.php index a8ad9ccfd..3149b4ff4 100644 --- a/classes/suggested-tasks/local-tasks/providers/class-core-update.php +++ b/classes/suggested-tasks/local-tasks/providers/class-core-update.php @@ -7,12 +7,17 @@ namespace Progress_Planner\Suggested_Tasks\Local_Tasks\Providers; -use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Local_Tasks_Interface; - /** * Add tasks for Core updates. */ -class Core_Update implements Local_Tasks_Interface { +class Core_Update extends Local_Tasks_Abstract { + + /** + * The capability required to perform the task. + * + * @var string + */ + protected $capability = 'update_core'; /** * The provider ID. @@ -138,13 +143,4 @@ public function is_task_type_snoozed() { return false; } - - /** - * Check if the user has the capability to update the core. - * - * @return bool - */ - public function capability_required() { - return \current_user_can( 'update_core' ); - } } diff --git a/classes/suggested-tasks/local-tasks/providers/class-local-tasks-abstract.php b/classes/suggested-tasks/local-tasks/providers/class-local-tasks-abstract.php new file mode 100644 index 000000000..6f2f1a250 --- /dev/null +++ b/classes/suggested-tasks/local-tasks/providers/class-local-tasks-abstract.php @@ -0,0 +1,34 @@ +capability + ? \current_user_can( $this->capability ) + : true; + } +} diff --git a/classes/suggested-tasks/local-tasks/providers/class-settings-saved.php b/classes/suggested-tasks/local-tasks/providers/class-settings-saved.php index a4def57b1..193d1fd2c 100644 --- a/classes/suggested-tasks/local-tasks/providers/class-settings-saved.php +++ b/classes/suggested-tasks/local-tasks/providers/class-settings-saved.php @@ -7,12 +7,10 @@ namespace Progress_Planner\Suggested_Tasks\Local_Tasks\Providers; -use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Local_Tasks_Interface; - /** * Add tasks for settings saved. */ -class Settings_Saved implements Local_Tasks_Interface { +class Settings_Saved extends Local_Tasks_Abstract { /** * The provider ID. @@ -141,13 +139,4 @@ public function is_task_type_snoozed() { return false; } - - /** - * Check if the user has the capability to manage options. - * - * @return bool - */ - public function capability_required() { - return \current_user_can( 'manage_options' ); - } }