Skip to content

Commit

Permalink
base abstract class for local tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
ilicfilip committed Dec 20, 2024
1 parent 11b9497 commit ef54495
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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' );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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' );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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' );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Abstract class for a local task provider.
*
* @package Progress_Planner
*/

namespace Progress_Planner\Suggested_Tasks\Local_Tasks\Providers;

use Progress_Planner\Suggested_Tasks\Local_Tasks\Providers\Local_Tasks_Interface;

/**
* Add tasks for content updates.
*/
abstract class Local_Tasks_Abstract implements Local_Tasks_Interface {

/**
* The capability required to perform the task.
*
* @var string
*/
protected $capability = 'manage_options';

/**
* Check if the user has the capability to perform the task.
*
* @return bool
*/
public function capability_required() {
return $this->capability
? \current_user_can( $this->capability )
: true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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' );
}
}

0 comments on commit ef54495

Please sign in to comment.