<?php /* * User Role Editor Pro WordPress plugin * Author: Vladimir Garagulya * Author email: support@role-editor.com * Author URI: https://www.role-editor.com * License: GPL v3 * */ /* * User Role Editor's internal tasks queue * Usage: on URE plugin activation URE adds 'on_activation' task to this queue, which fires 'ure_on_activation' action * on the next WordPress call. It's useful when some action is needed unavailable at standard plugin activation point, * like 'admin_menu', which is used for the admin menu access data conversion - class URE_Admin_Menu_Hashes. * Class User_Role_Editor_Pro adds execute_once method for the 'ure_on_activation' action, where * URE_Admin_Menu_Hashes::require_data_conversion(); method is called which registers tasks for data coversion, including * individual tasks for every site of the multisite network * */ class URE_Task_Queue { private static $instance = null; // object exemplar reference according to singleton patern const OPTION_NAME = 'ure_tasks_queue'; private $queue = null; public static function get_instance() { if (self::$instance===null) { self::$instance = new URE_Task_Queue(); } return self::$instance; } // end of get_instance() protected function __construct() { $this->init(); } // end of __construct() private function init() { $this->queue = get_option(self::OPTION_NAME, array()); } // end of init() public function reinit() { $this->init(); } // end of reinit() /** * * @param string $task_id * @param array $args=array('action'=>'action_name', 'routine'=>'routine_name', 'priority'=>99) */ public function add($task_id, $args=array()) { $this->queue[$task_id] = $args; update_option(self::OPTION_NAME, $this->queue); } // end of add_task() public function remove($task_id) { if (isset($this->queue[$task_id])) { unset($this->queue[$task_id]); update_option(self::OPTION_NAME, $this->queue); } } // end of remove_task() /** * Returns true in case a queue is empty * * @return boolean */ public function is_empty() { return count($this->queue)==0; } // end of is_empty() /** * Consumers should add there tasks with add_method and add 'ure_fulfil_task' action routine to work on it. * Do not forget remove task after it was fulfilled. * * @return void */ public function process() { if ($this->is_empty()) { return; } foreach($this->queue as $task_id=>$task) { if ($task_id=='on_activation') { do_action('ure_on_activation'); $this->remove('on_activation'); // remove this task after execution if it was defined } elseif (!empty($task['action'])) { $priority = empty($task['priority']) ? 10: $task['priority']; add_action($task['action'], $task['routine'], $priority); } else { add_action('init', $task['routine']); } } } // end of process(); /** * Prevent cloning of the instance of the *Singleton* instance. * * @return void */ public function __clone() { throw new \Exception('Do not clone a singleton instance.'); } // end of __clone() /** * Prevent unserializing of the *Singleton* instance. * * @return void */ public function __wakeup() { throw new \Exception('Do not unserialize a singleton instance.'); } // end of __wakeup() } // end of class URE_On_Activation
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
admin-notice.php | File | 833 B | 0644 |
|
advertisement.php | File | 2.58 KB | 0644 |
|
ajax-processor.php | File | 10.92 KB | 0644 |
|
assign-role.php | File | 5.68 KB | 0644 |
|
base-lib.php | File | 11.04 KB | 0644 |
|
bbpress.php | File | 2.81 KB | 0644 |
|
capabilities-groups-manager.php | File | 17.76 KB | 0644 |
|
capabilities.php | File | 15.09 KB | 0644 |
|
capability.php | File | 8.14 KB | 0644 |
|
editor.php | File | 56.29 KB | 0644 |
|
grant-roles.php | File | 19.88 KB | 0644 |
|
known-js-css-compatibility-issues.php | File | 2.59 KB | 0644 |
|
lib.php | File | 17.6 KB | 0644 |
|
own-capabilities.php | File | 5.22 KB | 0644 |
|
protect-admin.php | File | 8.01 KB | 0644 |
|
role-additional-options.php | File | 4.02 KB | 0644 |
|
role-view.php | File | 17.06 KB | 0644 |
|
screen-help.php | File | 5.77 KB | 0644 |
|
settings.php | File | 9.03 KB | 0644 |
|
task-queue.php | File | 3.94 KB | 0644 |
|
tools.php | File | 3.77 KB | 0644 |
|
uninstall.php | File | 2.62 KB | 0644 |
|
user-other-roles.php | File | 13.59 KB | 0644 |
|
user-role-editor.php | File | 37.1 KB | 0644 |
|
user-view.php | File | 8.09 KB | 0644 |
|
view.php | File | 13.86 KB | 0644 |
|
woocommerce-capabilities.php | File | 5.8 KB | 0644 |
|