-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced
AbstractTaskManager
to centralize common behaviors of al…
…l Task Manager classes, reducing redundancy and improving code clarity and maintainability. Modified Task Managers to instantiate only when their associated WP Cron hooks are scheduled, optimizing resource usage and avoiding errors about unhandled hooks. Ensured recurring WP Cron hooks are cleared after completion using `wp_clear_scheduled_hook`, preventing unnecessary executions. Added `TaskManagerSchedules` class to register new custom schedules for WP Cron jobs via filters, enabling more flexible scheduling for various Task Managers.
- Loading branch information
1 parent
86aa546
commit 53ac0db
Showing
8 changed files
with
253 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
namespace NewfoldLabs\WP\Module\Installer\TaskManagers; | ||
|
||
use NewfoldLabs\WP\Module\Installer\Data\Options; | ||
|
||
/** | ||
* Manages the execution of Tasks. | ||
*/ | ||
abstract class AbstractTaskManager { | ||
|
||
/** | ||
* The number of times a PluginUninstallTask can be retried. | ||
* | ||
* @var int | ||
*/ | ||
protected static $retry_limit = 1; | ||
|
||
/** | ||
* Name of the Queue. | ||
* | ||
* @var string | ||
*/ | ||
protected static $queue_name = ''; | ||
|
||
/** | ||
* Name of the Hook. | ||
* | ||
* @var string | ||
*/ | ||
protected static $hook_name = ''; | ||
|
||
/** | ||
* PluginUninstallTaskManager constructor. | ||
*/ | ||
public function __construct() { | ||
TaskManagerSchedules::init(); | ||
} | ||
|
||
/** | ||
* Retrieve the Queue Name for the TaskManager. | ||
* | ||
* @return string | ||
*/ | ||
public static function get_queue_name() { | ||
return static::$queue_name; | ||
} | ||
|
||
|
||
/** | ||
* Retrieve the Hook Name for the TaskManager. | ||
* | ||
* @return string | ||
*/ | ||
public static function get_hook_name() { | ||
return static::$hook_name; | ||
} | ||
|
||
|
||
/** | ||
* Returns the status of given plugin slug - uninstalling/completed. | ||
* | ||
* @param string $plugin Plugin Slug | ||
* @return string|false | ||
*/ | ||
public static function status( $plugin ) { | ||
$plugins = \get_option( Options::get_option_name( static::$queue_name ), array() ); | ||
return array_search( $plugin, array_column( $plugins, 'slug' ), true ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.