8889841creadme.md 0000644 00000044034 15054503403 0006327 0 ustar 00 # WP Crontrol
Contributors: johnbillion, scompt
Tags: cron, wp-cron, crontrol, debug
Tested up to: 6.4
Stable tag: 1.16.1
Donate link: https://github.com/sponsors/johnbillion
WP Crontrol enables you to view and control what's happening in the WP-Cron system.
## Description
WP Crontrol enables you to view and control what's happening in the WP-Cron system. From the admin screens you can:
* View all cron events along with their arguments, recurrence, callback functions, and when they are next due.
* Edit, delete, pause, resume, and immediately run cron events.
* Add new cron events.
* Bulk delete cron events.
* Add and remove custom cron schedules.
* Export and download cron event lists as a CSV file.
WP Crontrol is aware of timezones, will alert you to events that have no actions or that have missed their schedule, and will show you a helpful warning message if it detects any problems with your cron system.
### Usage
1. Go to the `Tools → Cron Events` menu to manage cron events.
2. Go to the `Settings → Cron Schedules` menu to manage cron schedules.
### Other Plugins
I maintain several other plugins for developers. Check them out:
* [Query Monitor](https://wordpress.org/plugins/query-monitor/) is the developer tools panel for WordPress.
* [User Switching](https://wordpress.org/plugins/user-switching/) provides instant switching between user accounts in WordPress.
### Privacy Statement
WP Crontrol is private by default and always will be. It does not send data to any third party, nor does it include any third party resources.
[WP Crontrol's full privacy statement can be found here](https://github.com/johnbillion/wp-crontrol/wiki/Privacy-statement).
### Accessibility Statement
WP Crontrol aims to be fully accessible to all of its users. It implements best practices for web accessibility, outputs semantic and structured markup, adheres to the default styles and accessibility guidelines of WordPress, uses the accessibility APIs provided by WordPress and web browsers where appropriate, and is fully accessible via keyboard and via mobile devices.
WP Crontrol should adhere to Web Content Accessibility Guidelines (WCAG) 2.0 at level AA when used with a recent version of WordPress where its admin area itself adheres to these guidelines. If you've experienced or identified an accessibility issue in WP Crontrol, please open a thread in [the WP Crontrol plugin support forum](https://wordpress.org/support/plugin/wp-crontrol/) and I'll address it swiftly.
## Frequently Asked Questions
### Does this plugin work with PHP 8?
Yes, it's actively tested and working up to PHP 8.2.
### I get the error "There was a problem spawning a call to the WP-Cron system on your site". How do I fix this?
[You can read all about problems spawning WP-Cron on the WP Crontrol wiki](https://github.com/johnbillion/wp-crontrol/wiki/Problems-with-spawning-a-call-to-the-WP-Cron-system).
### Why do some cron events miss their schedule?
[You can read all about cron events that miss their schedule on the WP Crontrol wiki](https://github.com/johnbillion/wp-crontrol/wiki/Cron-events-that-have-missed-their-schedule).
### Why do some cron events reappear shortly after I delete them?
If the event is added by a plugin then the plugin most likely rescheduled the event as soon as it saw that the event was missing. To get around this you can instead use the "Pause this hook" action which means it'll remain in place but won't perform any action when it runs.
### Is it safe to delete cron events?
This depends entirely on the event. You can use your favourite search engine to search for the event name in order to find out which plugin it belongs to, and then decide whether or not to delete it.
If the event shows "None" as its action then it's usually safe to delete. Please see the other FAQs for more information about events with no action.
### Why can't I delete some cron events?
The WordPress core software uses cron events for some of its functionality and removing these events is not possible because WordPress would immediately reschedule them if you did delete them. For this reason, WP Crontrol doesn't let you delete these persistent events from WordPress core in the first place.
If you don't want these events to run, you can use the "Pause this hook" action instead.
### What happens when I pause an event?
Pausing an event will disable all actions attached to the event's hook. The event itself will remain in place and will run according to its schedule, but all actions attached to its hook will be disabled. This renders the event inoperative but keeps it scheduled so as to remain fully compatible with events which would otherwise get automatically rescheduled when they're missing.
As pausing an event actually pauses its hook, all events that use the same hook will be paused or resumed when pausing and resuming an event. This is much more useful and reliable than pausing individual events separately.
### What happens when I resume an event?
Resuming an event re-enables all actions attached to the event's hook. All events that use the same hook will be resumed.
### What does it mean when "None" is shown for the Action of a cron event?
This means the cron event is scheduled to run at the specified time but there is no corresponding functionality that will be triggered when the event runs, therefore the event is useless.
This is often caused by plugins that don't clean up their cron events when you deactivate them. You can use your favourite search engine to search for the event name in order to find out which plugin it belongs to, and then decide whether or not to delete it.
### How do I change the next run time or the recurrence of a cron event?
You can change the time and recurrence of a cron event by clicking the "Edit" link next to the event.
### How can I create a cron event that requests a URL?
From the Tools → Cron Events → Add New screen, create a PHP cron event that includes PHP that fetches the URL using the WordPress HTTP API. For example:
wp_remote_get( 'http://example.com' );
[You can read all about the features and security of PHP cron events on the WP Crontrol wiki](https://github.com/johnbillion/wp-crontrol/wiki/PHP-cron-events).
### Why do changes that I make to some cron events not get saved?
[You can read all about problems with editing cron events on the WP Crontrol wiki](https://github.com/johnbillion/wp-crontrol/wiki/Problems-adding-or-editing-WP-Cron-events).
### Can I export a list of cron events?
Yes, a CSV file of the event list can be exported and downloaded via the "Export" button on the cron event listing screen. This file can be opened in any spreadsheet application.
### Can I see a historical log of all the cron events that ran on my site?
Not yet, but I hope to add this functionality soon.
### Can I see a historical log of edits, additions, and deletions of cron events and schedules?
Yes. The excellent Simple History plugin has built-in support for logging actions performed via WP Crontrol.
### What's the use of adding new cron schedules?
Cron schedules are used by WordPress and plugins for scheduling events to be executed at regular intervals. Intervals must be provided by the WordPress core or a plugin in order to be used. As an example, many backup plugins provide support for periodic backups. In order to do a weekly backup, a weekly cron schedule must be entered into WP Crontrol first and then a backup plugin can take advantage of it as an interval.
### How do I create a new cron event?
There are two steps to getting a functioning cron event that executes regularly. The first step is telling WordPress about the hook. This is the part that WP Crontrol was created to provide. The second step is calling a function when your hook is executed.
*Step One: Adding the hook*
In the Tools → Cron Events admin panel, click on "Add New" and enter the details of the hook. You're best off using a hook name that conforms to normal PHP variable naming conventions. The event schedule is how often your hook will be executed. If you don't see a good interval, then add one in the Settings → Cron Schedules admin panel.
*Step Two: Writing the function*
This part takes place in PHP code (for example, in the `functions.php` file from your theme). To execute your hook, WordPress runs an action. For this reason, we need to tell WordPress which function to execute when this action is run. The following line accomplishes that:
add_action( 'my_hookname', 'my_function' );
The next step is to write your function. Here's a simple example:
function my_function() {
wp_mail( 'hello@example.com', 'WP Crontrol', 'WP Crontrol rocks!' );
}
### How do I create a new PHP cron event?
In the Tools → Cron Events admin panel, click on "Add New". In the form that appears, select "PHP Cron Event" and enter the schedule and next run time. The event schedule is how often your event will be executed. If you don't see a good interval, then add one in the Settings → Cron Schedules admin panel. In the "Hook code" area, enter the PHP code that should be run when your cron event is executed. You don't need to provide the PHP opening tag (`Michael Pardo and is in the public domain.
## Screenshots
1. Cron events can be modified, deleted, and executed 
2. New cron events can be added 
3. New cron schedules can be added, giving plugin developers more options when scheduling events 
## Changelog ##
### 1.16.1 ###
* Confirm support for WordPress 6.4
### 1.16.0 ###
* Allow persistent WordPress core hooks to be cleared if there's more than one event with that hook
* Add the number of matching events to the hook deletion link text
* Scrap the Ajax request that checks if the current page of cron events has changed since loading
* Make some improvements to sorting the cron event list table columns
* Increase the minimum supported PHP version to 7.4
### 1.15.3 ###
* Pass the `$doing_wp_cron` value to the `cron_request` filter so it matches WordPress core
* Miscellaneous code quality improvements
### 1.15.2 ###
* Improves the terminology around pausing and deleting hooks and events
* Improves accessibility of the event listing table for keyboard users
* Removes an unnecessary SQL query when fetching the list of paused events
* Adds an FAQ about deactivating the plugin
### 1.15.1 ###
* Confirms the plugin is compatible with PHP 8.2
* Increases compatibility with other plugins that include very old Composer autoloader implementations
### 1.15.0 ###
* Introduces the ability to pause and resume cron events from the event listing screen; see the FAQ for full details
* Adds the site time to the cron event editing screen
* Implements an autoloader to reduce memory usage
* Bumps the minimum supported version of PHP to 5.6
### 1.14.0 ###
* Reverts the changes introduced in version 1.13 while I look into the problem with the deployment process for wordpress.org
### 1.13.2 ###
* Fixes another issue with missing files in the release
### 1.13.1 ###
* Fixes an issue with missing files in the 1.13.0 release
### 1.13.0 ###
* Introduces the ability to pause and resume cron events from the event listing screen; see the FAQ for full details
* Implements an autoloader to reduce memory usage
* Bumps the minimum supported version of PHP to 5.6
### 1.12.1 ###
* Corrects an issue where an invalid hook callback isn't always identified
* Various code quality improvements
### 1.12.0 ###
* Fix the PHP cron event management.
* More "namespacing" of query variables to avoid conflicts with other cron management plugins.
### 1.11.0 ###
* Introduced an `Export` feature to the event listing screen for exporting the list of events as a CSV file.
* Added the timezone offset to the date displayed for events that are due to run after the next DST change, for extra clarity.
* Introduced the `crontrol/filter-types` and `crontrol/filtered-events` filters for adjusting the available event filters on the event listing screen.
* Lots of code quality improvements (thanks, PHPStan!).
### 1.10.0 ###
* Support for more granular cron-related error messages in WordPress 5.7
* Several accessibility improvements
* Warning for events that are attached to [a schedule that is too frequent](https://github.com/johnbillion/wp-crontrol/wiki/This-interval-is-less-than-the-WP_CRON_LOCK_TIMEOUT-constant)
* More clarity around events and schedules that are built in to WordPress core
* Add a Help tab with links to the wiki and FAQs
### 1.9.1 ###
* Fix the adding of new cron events when `DISALLOW_FILE_EDIT` is true.
### 1.9.0 ###
* Add filters and sorting to the event listing screen. Props @yuriipavlov.
* Replace the "Add New" tabs with a more standard "Add New" button on the cron event listing page.
* Switch back to using browser-native controls for the date and time inputs.
* Add an error message when trying to edit a non-existent event.
* Introduce an informational message which appears when there are events that have missed their schedule.
* Fire actions when cron events and schedules are added, updated, and deleted.
### 1.8.5 ###
* Fix an issue with the tabs in 1.8.4.
### 1.8.4 ###
* Add a warning message if the default timezone has been changed. More information.
* Fixed string being passed to `strtotime()` function when the `Now` option is chosen when adding or editing an event.
### 1.8.3 ###
* Fix the editing of events that aren't currently listed on the first page of results.
### 1.8.2 ###
* Bypass the duplicate event check when manually running an event. This allows an event to manually run even if it's due within ten minutes or if it's overdue.
* Force only one event to fire when manually running a cron event.
* Introduce polling of the events list in order to show a warning when the event listing screen is out of date.
* Add a warning for cron schedules which are shorter than `WP_CRON_LOCK_TIMEOUT`.
* Add the Site Health check event to the list of persistent core hooks.
### 1.8.1 ###
* Fix the bottom bulk action menu on the event listing screen.
* Make the timezone more prominent when adding or editing a cron event.
### 1.8.0 ###
* Searching and pagination for cron events
* Ability to delete all cron events with a given hook
* More accurate response messages when managing events (in WordPress 5.1+)
* Visual warnings for events without actions, and PHP events with syntax errors
* Timezone-related clarifications and fixes
* A more unified UI
* Modernised codebase
### 1.7.1 ###
* Correct the PHP.net URL for the `strtotime()` reference.
### 1.7.0 ###
* Remove the `date` and `time` inputs and replace with a couple of preset options and a plain text field. Fixes #24 .
* Ensure the schedule name is always correct when multiple schedules exist with the same interval. Add error handling. Fixes #25.
* Re-introduce the display of the current site time.
* Use a more appropriate HTTP response code for unauthorised request errors.
### 1.6.2 ###
* Remove the ability to delete a PHP cron event if the user cannot edit files.
* Remove the `Edit` link for PHP cron events when the user cannot edit the event.
* Avoid a PHP notice due to an undefined variable when adding a new cron event.
### 1.6.1 ###
* Fix a potential fatal error on the cron events listing screen.
### 1.6 ###
* Introduce bulk deletion of cron events. Yay!
* Show the schedule name instead of the schedule interval next to each event.
* Add core's new `delete_expired_transients` event to the list of core events.
* Don't allow custom cron schedules to be deleted if they're in use.
* Add links between the Events and Schedules admin screens.
* Add syntax highlighting to the PHP code editor for a PHP cron event.
* Styling fixes for events with many arguments or long arguments.
* Improvements to help text.
* Remove usage of `create_function()`.
* Fix some translator comments, improve i18n, improve coding standards.
### 1.5.0 ###
* Show the hooked actions for each cron event.
* Don't show the `Delete` link for core's built-in cron events, as they get re-populated immediately.
* Correct the success message after adding or editing PHP cron events.
* Correct the translations directory name.
vendor/autoload.php 0000644 00000001403 15054503403 0010357 0 ustar 00
* Jordi Boggiano
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier
* @author Jordi Boggiano
* @see https://www.php-fig.org/psr/psr-0/
* @see https://www.php-fig.org/psr/psr-4/
*/
class ClassLoader
{
/** @var \Closure(string):void */
private static $includeFile;
/** @var string|null */
private $vendorDir;
// PSR-4
/**
* @var array>
*/
private $prefixLengthsPsr4 = array();
/**
* @var array>
*/
private $prefixDirsPsr4 = array();
/**
* @var list
*/
private $fallbackDirsPsr4 = array();
// PSR-0
/**
* List of PSR-0 prefixes
*
* Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
*
* @var array>>
*/
private $prefixesPsr0 = array();
/**
* @var list
*/
private $fallbackDirsPsr0 = array();
/** @var bool */
private $useIncludePath = false;
/**
* @var array
*/
private $classMap = array();
/** @var bool */
private $classMapAuthoritative = false;
/**
* @var array
*/
private $missingClasses = array();
/** @var string|null */
private $apcuPrefix;
/**
* @var array
*/
private static $registeredLoaders = array();
/**
* @param string|null $vendorDir
*/
public function __construct($vendorDir = null)
{
$this->vendorDir = $vendorDir;
self::initializeIncludeClosure();
}
/**
* @return array>
*/
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
}
return array();
}
/**
* @return array>
*/
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
/**
* @return list
*/
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
/**
* @return list
*/
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
/**
* @return array Array of classname => path
*/
public function getClassMap()
{
return $this->classMap;
}
/**
* @param array $classMap Class to filename map
*
* @return void
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param list|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*
* @return void
*/
public function add($prefix, $paths, $prepend = false)
{
$paths = (array) $paths;
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
$paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
$paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
$paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param list|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
$paths = (array) $paths;
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
$paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
$paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
$paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param list|string $paths The PSR-0 base directories
*
* @return void
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param list|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*
* @return void
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*
* @return void
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*
* @return void
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
}
/**
* The APCu prefix in use, or null if APCu caching is not enabled.
*
* @return string|null
*/
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*
* @return void
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
if (null === $this->vendorDir) {
return;
}
if ($prepend) {
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
} else {
unset(self::$registeredLoaders[$this->vendorDir]);
self::$registeredLoaders[$this->vendorDir] = $this;
}
}
/**
* Unregisters this instance as an autoloader.
*
* @return void
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
if (null !== $this->vendorDir) {
unset(self::$registeredLoaders[$this->vendorDir]);
}
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return true|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
$includeFile = self::$includeFile;
$includeFile($file);
return true;
}
return null;
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
}
return $file;
}
/**
* Returns the currently registered loaders keyed by their corresponding vendor directories.
*
* @return array
*/
public static function getRegisteredLoaders()
{
return self::$registeredLoaders;
}
/**
* @param string $class
* @param string $ext
* @return string|false
*/
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
if (file_exists($file = $dir . $pathEnd)) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
/**
* @return void
*/
private static function initializeIncludeClosure()
{
if (self::$includeFile !== null) {
return;
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*
* @param string $file
* @return void
*/
self::$includeFile = \Closure::bind(static function($file) {
include $file;
}, null, null);
}
}
vendor/composer/installed.php 0000644 00000001431 15054503403 0012356 0 ustar 00 array(
'name' => 'johnbillion/wp-crontrol',
'pretty_version' => 'dev-release',
'version' => 'dev-release',
'reference' => 'dd6e69045b04417660f3d207bedfc605c1877e40',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'dev' => false,
),
'versions' => array(
'johnbillion/wp-crontrol' => array(
'pretty_version' => 'dev-release',
'version' => 'dev-release',
'reference' => 'dd6e69045b04417660f3d207bedfc605c1877e40',
'type' => 'wordpress-plugin',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'dev_requirement' => false,
),
),
);
vendor/composer/autoload_namespaces.php 0000644 00000000213 15054503403 0014403 0 ustar 00 setClassMapAuthoritative(true);
}
$loader->register(false);
return $loader;
}
}
vendor/composer/autoload_classmap.php 0000644 00000000535 15054503403 0014076 0 ustar 00 $baseDir . '/src/event-list-table.php',
'Crontrol\\Request' => $baseDir . '/src/request.php',
'Crontrol\\Schedule_List_Table' => $baseDir . '/src/schedule-list-table.php',
);
vendor/composer/platform_check.php 0000644 00000001635 15054503403 0013366 0 ustar 00 = 70400)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.4.0". You are running ' . PHP_VERSION . '.';
}
if ($issues) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
} elseif (!headers_sent()) {
echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
}
}
trigger_error(
'Composer detected issues in your platform: ' . implode(' ', $issues),
E_USER_ERROR
);
}
vendor/composer/LICENSE 0000644 00000002056 15054503403 0010677 0 ustar 00
Copyright (c) Nils Adermann, Jordi Boggiano
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
vendor/composer/installed.json 0000644 00000000106 15054503403 0012536 0 ustar 00 {
"packages": [],
"dev": false,
"dev-package-names": []
}
vendor/composer/autoload_psr4.php 0000644 00000000205 15054503403 0013155 0 ustar 00 __DIR__ . '/../..' . '/src/event-list-table.php',
'Crontrol\\Request' => __DIR__ . '/../..' . '/src/request.php',
'Crontrol\\Schedule_List_Table' => __DIR__ . '/../..' . '/src/schedule-list-table.php',
);
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->classMap = ComposerStaticInit62e0e156461f136eb1f6faca04e5a55f::$classMap;
}, null, ClassLoader::class);
}
}
src/event.php 0000644 00000033435 15054503403 0007174 0 ustar 00 $cron ) {
if ( isset( $cron[ $hookname ][ $sig ] ) ) {
$event = $cron[ $hookname ][ $sig ];
$event['hook'] = $hookname;
$event['timestamp'] = $time;
$event = (object) $event;
delete_transient( 'doing_cron' );
$scheduled = force_schedule_single_event( $hookname, $event->args ); // UTC
if ( is_wp_error( $scheduled ) ) {
return $scheduled;
}
add_filter( 'cron_request', function( array $cron_request_array ) {
$cron_request_array['url'] = add_query_arg( 'crontrol-single-event', 1, $cron_request_array['url'] );
return $cron_request_array;
} );
spawn_cron();
sleep( 1 );
/**
* Fires after a cron event is scheduled to run manually.
*
* @param stdClass $event {
* An object containing the event's data.
*
* @type string $hook Action hook to execute when the event is run.
* @type int $timestamp Unix timestamp (UTC) for when to next run the event.
* @type string|false $schedule How often the event should subsequently recur.
* @type array $args Array containing each separate argument to pass to the hook's callback function.
* @type int $interval The interval time in seconds for the schedule. Only present for recurring events.
* }
*/
do_action( 'crontrol/ran_event', $event );
return true;
}
}
return new WP_Error(
'not_found',
sprintf(
/* translators: 1: The name of the cron event. */
__( 'The cron event %s could not be found.', 'wp-crontrol' ),
$hookname
)
);
}
/**
* Forcibly schedules a single event for the purpose of manually running it.
*
* This is used instead of `wp_schedule_single_event()` to avoid the duplicate check that's otherwise performed.
*
* @param string $hook Action hook to execute when the event is run.
* @param mixed[] $args Optional. Array containing each separate argument to pass to the hook's callback function.
* @return true|WP_Error True if event successfully scheduled. WP_Error on failure.
*/
function force_schedule_single_event( $hook, $args = array() ) {
$event = (object) array(
'hook' => $hook,
'timestamp' => 1,
'schedule' => false,
'args' => $args,
);
$crons = get_core_cron_array();
$key = md5( serialize( $event->args ) );
$crons[ $event->timestamp ][ $event->hook ][ $key ] = array(
'schedule' => $event->schedule,
'args' => $event->args,
);
ksort( $crons );
$result = _set_cron_array( $crons );
// Not using the WP_Error from `_set_cron_array()` here so we can provide a more specific error message.
if ( false === $result ) {
return new WP_Error(
'could_not_add',
sprintf(
/* translators: 1: The name of the cron event. */
__( 'Failed to schedule the cron event %s.', 'wp-crontrol' ),
$hook
)
);
}
return true;
}
/**
* Adds a new cron event.
*
* @param string $next_run_local The time that the event should be run at, in the site's timezone.
* @param string $schedule The recurrence of the cron event.
* @param string $hook The name of the hook to execute.
* @param mixed[] $args Arguments to add to the cron event.
* @return true|WP_error True if the addition was successful, WP_Error otherwise.
*/
function add( $next_run_local, $schedule, $hook, array $args ) {
/**
* @var int
*/
$current_time = current_time( 'timestamp' );
$next_run_local = strtotime( $next_run_local, $current_time );
if ( false === $next_run_local ) {
return new WP_Error(
'invalid_timestamp',
__( 'Invalid timestamp provided.', 'wp-crontrol' )
);
}
$next_run_utc = (int) get_gmt_from_date( gmdate( 'Y-m-d H:i:s', $next_run_local ), 'U' );
if ( ! is_array( $args ) ) {
$args = array();
}
if ( 'crontrol_cron_job' === $hook && ! empty( $args['code'] ) && class_exists( '\ParseError' ) ) {
try {
// phpcs:ignore Squiz.PHP.Eval.Discouraged
eval( sprintf(
'return true; %s',
$args['code']
) );
// phpcs:ignore PHPCompatibility.Classes.NewClasses.parseerrorFound
} catch ( \ParseError $e ) {
$args['syntax_error_message'] = $e->getMessage();
$args['syntax_error_line'] = $e->getLine();
}
}
if ( '_oneoff' === $schedule || '' === $schedule ) {
/**
* @var bool|null|\WP_Error $result
*/
$result = wp_schedule_single_event( $next_run_utc, $hook, $args, true );
} else {
/**
* @var bool|null|\WP_Error $result
*/
$result = wp_schedule_event( $next_run_utc, $schedule, $hook, $args, true );
}
/**
* Possible return values of `wp_schedule_*()` as called above:
*
* - 5.7+ Success: true, Failure: WP_Error
* - 5.1+ Success: true, Failure: false
* - <5.1 Success: null, Failure: false
*/
if ( is_wp_error( $result ) ) {
return $result;
}
if ( false === $result ) {
return new WP_Error(
'could_not_add',
sprintf(
/* translators: 1: The name of the cron event. */
__( 'Failed to schedule the cron event %s.', 'wp-crontrol' ),
$hook
)
);
}
return true;
}
/**
* Deletes a cron event.
*
* @param string $hook The hook name of the event to delete.
* @param string $sig The cron event signature.
* @param string $next_run_utc The UTC time that the event would be run at.
* @return true|WP_Error True if the deletion was successful, WP_Error otherwise.
*/
function delete( $hook, $sig, $next_run_utc ) {
$event = get_single( $hook, $sig, $next_run_utc );
if ( is_wp_error( $event ) ) {
return $event;
}
/**
* @var bool|null|\WP_Error $unscheduled
*/
$unscheduled = wp_unschedule_event( $event->timestamp, $event->hook, $event->args, true );
/**
* Possible return values of `wp_unschedule_*()` as called above:
*
* - 5.7+ Success: true, Failure: WP_Error
* - 5.1+ Success: true, Failure: false
* - <5.1 Success: null, Failure: false
*/
if ( is_wp_error( $unscheduled ) ) {
return $unscheduled;
}
if ( false === $unscheduled ) {
return new WP_Error(
'could_not_delete',
sprintf(
/* translators: 1: The name of the cron event. */
__( 'Failed to the delete the cron event %s.', 'wp-crontrol' ),
$hook
)
);
}
return true;
}
/**
* Pauses a cron event.
*
* @param string $hook The hook name of the event to pause.
* @return true|WP_Error True if the pause was successful, WP_Error otherwise.
*/
function pause( $hook ) {
$paused = get_option( PAUSED_OPTION, array() );
if ( ! is_array( $paused ) ) {
$paused = array();
}
$paused[ $hook ] = true;
$result = update_option( PAUSED_OPTION, $paused, true );
if ( false === $result ) {
return new WP_Error(
'could_not_pause',
sprintf(
/* translators: 1: The name of the cron event. */
__( 'Failed to pause the cron event %s.', 'wp-crontrol' ),
$hook
)
);
}
return true;
}
/**
* Resumes a paused cron event.
*
* @param string $hook The hook name of the event to resume.
* @return true|WP_Error True if the resumption was successful, WP_Error otherwise.
*/
function resume( $hook ) {
$paused = get_option( PAUSED_OPTION );
if ( ! is_array( $paused ) || ( count( $paused ) === 0 ) ) {
return true;
}
unset( $paused[ $hook ] );
$result = update_option( PAUSED_OPTION, $paused, true );
if ( false === $result ) {
return new WP_Error(
'could_not_resume',
sprintf(
/* translators: 1: The name of the cron event. */
__( 'Failed to resume the cron event %s.', 'wp-crontrol' ),
$hook
)
);
}
return true;
}
/**
* Returns a flattened array of cron events.
*
* @return array An array of cron event objects keyed by unique signature.
*/
function get() {
$crons = get_core_cron_array();
$events = array();
if ( empty( $crons ) ) {
return array();
}
foreach ( $crons as $time => $cron ) {
foreach ( $cron as $hook => $dings ) {
foreach ( $dings as $sig => $data ) {
// This is a prime candidate for a Crontrol_Event class but I'm not bothering currently.
$events[ "$hook-$sig-$time" ] = (object) array(
'hook' => $hook,
'timestamp' => $time, // UTC
'sig' => $sig,
'args' => $data['args'],
'schedule' => $data['schedule'],
'interval' => isset( $data['interval'] ) ? $data['interval'] : null,
);
}
}
}
// Ensure events are always returned in date descending order.
// External cron runners such as Cavalcade don't guarantee events are returned in order of time.
uasort( $events, 'Crontrol\Event\uasort_order_events' );
return $events;
}
/**
* Gets a single cron event.
*
* @param string $hook The hook name of the event.
* @param string $sig The event signature.
* @param string|int $next_run_utc The UTC time that the event would be run at.
* @return stdClass|WP_Error A cron event object, or a WP_Error if it's not found.
*/
function get_single( $hook, $sig, $next_run_utc ) {
$crons = get_core_cron_array();
$next_run_utc = (int) $next_run_utc;
if ( isset( $crons[ $next_run_utc ][ $hook ][ $sig ] ) ) {
$event = $crons[ $next_run_utc ][ $hook ][ $sig ];
$event['hook'] = $hook;
$event['timestamp'] = $next_run_utc;
$event = (object) $event;
return $event;
}
return new WP_Error(
'not_found',
sprintf(
/* translators: 1: The name of the cron event. */
__( 'The cron event %s could not be found.', 'wp-crontrol' ),
$hook
)
);
}
/**
* Returns an array of the number of events for each hook.
*
* @return array Array of number of events for each hook, keyed by the hook name.
*/
function count_by_hook() {
$crons = get_core_cron_array();
$events = array();
if ( empty( $crons ) ) {
return array();
}
foreach ( $crons as $time => $cron ) {
foreach ( $cron as $hook => $dings ) {
if ( ! isset( $events[ $hook ] ) ) {
$events[ $hook ] = 0;
}
$events[ $hook ] += count( $dings );
}
}
return $events;
}
/**
* Returns the schedule display name for a given event.
*
* @param stdClass $event A WP-Cron event.
* @return string|WP_Error The interval display name, or a WP_Error object if no such schedule exists.
*/
function get_schedule_name( stdClass $event ) {
$schedules = Schedule\get();
if ( isset( $schedules[ $event->schedule ] ) ) {
return isset( $schedules[ $event->schedule ]['display'] ) ? $schedules[ $event->schedule ]['display'] : $schedules[ $event->schedule ]['name'];
}
return new WP_Error( 'unknown_schedule', sprintf(
/* translators: %s: Schedule name */
__( 'Unknown (%s)', 'wp-crontrol' ),
$event->schedule
) );
}
/**
* Determines whether the schedule for an event means it runs too frequently to be reliable.
*
* @param stdClass $event A WP-Cron event.
* @return bool Whether the event scheduled is too frequent.
*/
function is_too_frequent( stdClass $event ) {
$schedules = Schedule\get();
if ( ! isset( $schedules[ $event->schedule ] ) ) {
return false;
}
return $schedules[ $event->schedule ]['is_too_frequent'];
}
/**
* Determines whether an event is late.
*
* An event which has missed its schedule by more than 10 minutes is considered late.
*
* @param stdClass $event The event.
* @return bool Whether the event is late.
*/
function is_late( stdClass $event ) {
$until = $event->timestamp - time();
return ( $until < ( 0 - ( 10 * MINUTE_IN_SECONDS ) ) );
}
/**
* Determines whether an event is paused.
*
* @param stdClass $event The event.
* @return bool Whether the event is paused.
*/
function is_paused( stdClass $event ) {
$paused = get_option( PAUSED_OPTION );
if ( ! is_array( $paused ) ) {
return false;
}
return array_key_exists( $event->hook, $paused );
}
/**
* Initialises and returns the list table for events.
*
* @return Table The list table.
*/
function get_list_table() {
static $table = null;
if ( ! $table ) {
$table = new Table();
$table->prepare_items();
}
return $table;
}
/**
* Order events function.
*
* The comparison function returns an integer less than, equal to, or greater than zero if the first argument is
* considered to be respectively less than, equal to, or greater than the second.
*
* @param stdClass $a The first event to compare.
* @param stdClass $b The second event to compare.
* @return int
*/
function uasort_order_events( $a, $b ) {
$orderby = ( ! empty( $_GET['orderby'] ) ) ? sanitize_text_field( $_GET['orderby'] ) : 'crontrol_next';
$order = ( ! empty( $_GET['order'] ) ) ? sanitize_text_field( $_GET['order'] ) : 'asc';
$compare = 0;
switch ( $orderby ) {
case 'crontrol_hook':
if ( 'asc' === $order ) {
$compare = strcmp( $a->hook, $b->hook );
} else {
$compare = strcmp( $b->hook, $a->hook );
}
break;
case 'crontrol_recurrence':
if ( 'asc' === $order ) {
$compare = ( $a->interval ?? 0 ) <=> ( $b->interval ?? 0 );
} else {
$compare = ( $b->interval ?? 0 ) <=> ( $a->interval ?? 0 );
}
break;
default:
if ( 'asc' === $order ) {
$compare = $a->timestamp <=> $b->timestamp;
} else {
$compare = $b->timestamp <=> $a->timestamp;
}
break;
}
return $compare;
}
/**
* Fetches the list of cron events from WordPress core.
*
* @return array>>>
* @phpstan-return array>>>
*/
function get_core_cron_array() {
$crons = _get_cron_array();
if ( empty( $crons ) ) {
$crons = array();
}
return $crons;
}
src/schedule.php 0000644 00000006273 15054503403 0007647 0 ustar 00 */
$old_scheds = get_option( 'crontrol_schedules', array() );
$old_scheds[ $name ] = array(
'interval' => $interval,
'display' => $display,
);
update_option( 'crontrol_schedules', $old_scheds );
/**
* Fires after a new cron schedule is added.
*
* @param string $name The internal name of the schedule.
* @param int $interval The interval between executions of the new schedule.
* @param string $display The display name of the schedule.
*/
do_action( 'crontrol/added_new_schedule', $name, $interval, $display );
}
/**
* Deletes a custom cron schedule.
*
* @param string $name The internal name of the schedule to delete.
* @return void
*/
function delete( $name ) {
/** @var array */
$scheds = get_option( 'crontrol_schedules', array() );
unset( $scheds[ $name ] );
update_option( 'crontrol_schedules', $scheds );
/**
* Fires after a cron schedule is deleted.
*
* @param string $name The internal name of the schedule.
*/
do_action( 'crontrol/deleted_schedule', $name );
}
/**
* Gets a sorted (according to interval) list of the cron schedules
*
* @return array> Array of cron schedule arrays.
* @phpstan-return array
*/
function get() {
/**
* @phpstan-var array $schedules
*/
$schedules = wp_get_schedules();
uasort( $schedules, function( array $a, array $b ) {
return ( $a['interval'] - $b['interval'] );
} );
array_walk( $schedules, function( array &$schedule, $name ) {
$schedule['name'] = $name;
$schedule['is_too_frequent'] = ( $schedule['interval'] < WP_CRON_LOCK_TIMEOUT );
} );
/**
* @phpstan-var array $schedules
*/
return $schedules;
}
/**
* Displays a dropdown filled with the possible schedules, including non-repeating.
*
* @param string|false $current The currently selected schedule, or false for none.
* @return void
*/
function dropdown( $current = false ) {
$schedules = get();
?>
Array of schedule names.
*/
protected static $core_schedules;
/**
* Array of cron event schedule names that are in use by events.
*
* @var array Array of schedule names.
*/
protected static $used_schedules;
/**
* Constructor.
*/
public function __construct() {
parent::__construct( array(
'singular' => 'crontrol-schedule',
'plural' => 'crontrol-schedules',
'ajax' => false,
'screen' => 'crontrol-schedules',
) );
}
/**
* Gets the name of the primary column.
*
* @return string The name of the primary column.
*/
protected function get_primary_column_name() {
return 'crontrol_name';
}
/**
* Prepares the list table items and arguments.
*
* @return void
*/
public function prepare_items() {
$schedules = Schedule\get();
$count = count( $schedules );
self::$core_schedules = get_core_schedules();
self::$used_schedules = array_unique( wp_list_pluck( Event\get(), 'schedule' ) );
$this->items = $schedules;
$this->set_pagination_args( array(
'total_items' => $count,
'per_page' => -1,
'total_pages' => 1,
) );
}
/**
* Returns an array of column names for the table.
*
* @return array Array of column names keyed by their ID.
*/
public function get_columns() {
return array(
'crontrol_icon' => '',
'crontrol_name' => __( 'Internal Name', 'wp-crontrol' ),
'crontrol_interval' => __( 'Interval', 'wp-crontrol' ),
'crontrol_display' => __( 'Display Name', 'wp-crontrol' ),
);
}
/**
* Returns an array of CSS class names for the table.
*
* @return array Array of class names.
*/
protected function get_table_classes() {
return array( 'widefat', 'fixed', 'striped', 'table-view-list', $this->_args['plural'] );
}
/**
* Generates and displays row action links for the table.
*
* @phpstan-param array{
* interval: int,
* display?: string,
* name: string,
* is_too_frequent: bool,
* } $schedule
* @param mixed[] $schedule The schedule for the current row.
* @param string $column_name Current column name.
* @param string $primary Primary column name.
* @return string The row actions HTML.
*/
protected function handle_row_actions( $schedule, $column_name, $primary ) {
if ( $primary !== $column_name ) {
return '';
}
$links = array();
/** @var array */
$new_scheds = get_option( 'crontrol_schedules', array() );
if ( in_array( $schedule['name'], self::$core_schedules, true ) ) {
$links[] = "" . esc_html__( 'This is a WordPress core schedule and cannot be deleted', 'wp-crontrol' ) . '';
} elseif ( ! isset( $new_scheds[ $schedule['name'] ] ) ) {
$links[] = "" . esc_html__( 'This schedule is added by another plugin and cannot be deleted', 'wp-crontrol' ) . '';
} elseif ( in_array( $schedule['name'], self::$used_schedules, true ) ) {
$links[] = "" . esc_html__( 'This custom schedule is in use and cannot be deleted', 'wp-crontrol' ) . '';
} else {
$link = add_query_arg( array(
'page' => 'crontrol_admin_options_page',
'crontrol_action' => 'delete-schedule',
'crontrol_id' => rawurlencode( $schedule['name'] ),
), admin_url( 'options-general.php' ) );
$link = wp_nonce_url( $link, 'crontrol-delete-schedule_' . $schedule['name'] );
$links[] = "" . esc_html__( 'Delete', 'wp-crontrol' ) . '';
}
return $this->row_actions( $links );
}
/**
* Returns the output for the icon cell of a table row.
*
* @phpstan-param array{
* interval: int,
* display?: string,
* name: string,
* is_too_frequent: bool,
* } $schedule
* @param mixed[] $schedule The schedule for the current row.
* @return string The cell output.
*/
protected function column_crontrol_icon( array $schedule ) {
if ( in_array( $schedule['name'], self::$core_schedules, true ) ) {
return sprintf(
'
%s',
esc_html__( 'This is a WordPress core schedule and cannot be deleted', 'wp-crontrol' )
);
}
return '';
}
/**
* Returns the output for the schdule name cell of a table row.
*
* @phpstan-param array{
* interval: int,
* display?: string,
* name: string,
* is_too_frequent: bool,
* } $schedule
* @param mixed[] $schedule The schedule for the current row.
* @return string The cell output.
*/
protected function column_crontrol_name( array $schedule ) {
return esc_html( $schedule['name'] );
}
/**
* Returns the output for the interval cell of a table row.
*
* @phpstan-param array{
* interval: int,
* display?: string,
* name: string,
* is_too_frequent: bool,
* } $schedule
* @param mixed[] $schedule The schedule for the current row.
* @return string The cell output.
*/
protected function column_crontrol_interval( array $schedule ) {
$interval = sprintf(
'%s (%s)',
esc_html( "{$schedule['interval']}" ),
esc_html( interval( $schedule['interval'] ) )
);
if ( $schedule['is_too_frequent'] ) {
$interval .= sprintf(
' %s',
sprintf(
/* translators: 1: The name of the configuration constant, 2: The value of the configuration constant */
esc_html__( 'This interval is less than the %1$s constant which is set to %2$s seconds. Events that use it may not run on time.', 'wp-crontrol' ),
'WP_CRON_LOCK_TIMEOUT',
intval( WP_CRON_LOCK_TIMEOUT )
)
);
}
return $interval;
}
/**
* Returns the output for the display name cell of a table row.
*
* @param mixed[] $schedule The schedule for the current row.
*
* @phpstan-param array{
* interval: int,
* display?: string,
* name: string,
* is_too_frequent: bool,
* } $schedule
* @return string The cell output.
*/
protected function column_crontrol_display( array $schedule ) {
return esc_html( isset( $schedule['display'] ) ? $schedule['display'] : $schedule['name'] );
}
/**
* Outputs a message when there are no items to show in the table.
*
* @return void
*/
public function no_items() {
esc_html_e( 'There are no schedules.', 'wp-crontrol' );
}
}
src/event-list-table.php 0000644 00000051602 15054503403 0011226 0 ustar 00 Array of hook names.
*/
protected static $persistent_core_hooks;
/**
* Whether the current user has the capability to create or edit PHP cron events.
*
* @var bool Whether the user can create or edit PHP cron events.
*/
protected static $can_manage_php_crons;
/**
* Array of the count of each hook.
*
* @var array Array of count of each hooked, keyed by hook name.
*/
protected static $count_by_hook;
/**
* Array of all cron events.
*
* @var array Array of event objects.
*/
protected $all_events = array();
/**
* Constructor.
*/
public function __construct() {
parent::__construct( array(
'singular' => 'crontrol-event',
'plural' => 'crontrol-events',
'ajax' => false,
'screen' => 'crontrol-events',
) );
}
/**
* Prepares the list table items and arguments.
*
* @return void
*/
public function prepare_items() {
self::$persistent_core_hooks = \Crontrol\get_persistent_core_hooks();
self::$can_manage_php_crons = current_user_can( 'edit_files' );
self::$count_by_hook = count_by_hook();
$events = get();
$this->all_events = $events;
if ( ! empty( $_GET['s'] ) ) {
$s = sanitize_text_field( wp_unslash( $_GET['s'] ) );
$events = array_filter( $events, function( $event ) use ( $s ) {
return ( false !== strpos( $event->hook, $s ) );
} );
}
if ( ! empty( $_GET['crontrol_hooks_type'] ) ) {
$hooks_type = sanitize_text_field( $_GET['crontrol_hooks_type'] );
$filtered = self::get_filtered_events( $events );
if ( isset( $filtered[ $hooks_type ] ) ) {
$events = $filtered[ $hooks_type ];
}
}
$count = count( $events );
$per_page = 50;
$offset = ( $this->get_pagenum() - 1 ) * $per_page;
$this->items = array_slice( $events, $offset, $per_page );
$has_late = (bool) array_filter( array_map( __NAMESPACE__ . '\\is_late', $this->items ) );
if ( $has_late ) {
add_action( 'admin_notices', function() {
printf(
'
',
esc_html( \Crontrol\json_output( $event->args ) )
);
}
}
}
/**
* Returns the output for the actions cell of a table row.
*
* @param stdClass $event The cron event for the current row.
* @return string The cell output.
*/
protected function column_crontrol_actions( $event ) {
$hook_callbacks = \Crontrol\get_hook_callbacks( $event->hook );
if ( 'crontrol_cron_job' === $event->hook ) {
return '' . esc_html__( 'WP Crontrol', 'wp-crontrol' ) . '';
} elseif ( ! empty( $hook_callbacks ) ) {
$callbacks = array();
foreach ( $hook_callbacks as $callback ) {
$callbacks[] = \Crontrol\output_callback( $callback );
}
return implode( ' ', $callbacks ); // WPCS:: XSS ok.
} else {
return sprintf(
' %s',
esc_html__( 'None', 'wp-crontrol' )
);
}
}
/**
* Returns the output for the next run cell of a table row.
*
* @param stdClass $event The cron event for the current row.
* @return string The cell output.
*/
protected function column_crontrol_next( $event ) {
$date_local_format = 'Y-m-d H:i:s';
$offset_site = get_date_from_gmt( 'now', 'P' );
$offset_event = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $event->timestamp ), 'P' );
if ( $offset_site !== $offset_event ) {
$date_local_format .= ' P';
}
$date_utc = gmdate( 'c', $event->timestamp );
$date_local = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $event->timestamp ), $date_local_format );
$time = sprintf(
'',
esc_attr( $date_utc ),
esc_html( $date_local )
);
$until = $event->timestamp - time();
$late = is_late( $event );
if ( $late ) {
// Show a warning for events that are late.
$ago = sprintf(
/* translators: %s: Time period, for example "8 minutes" */
__( '%s ago', 'wp-crontrol' ),
\Crontrol\interval( abs( $until ) )
);
return sprintf(
'%s %s',
$time,
esc_html( $ago )
);
}
return sprintf(
'%s %s',
$time,
esc_html( \Crontrol\interval( $until ) )
);
}
/**
* Returns the output for the recurrence cell of a table row.
*
* @param stdClass $event The cron event for the current row.
* @return string The cell output.
*/
protected function column_crontrol_recurrence( $event ) {
if ( $event->schedule ) {
$schedule_name = get_schedule_name( $event );
if ( is_wp_error( $schedule_name ) ) {
return sprintf(
' %s',
esc_html( $schedule_name->get_error_message() )
);
} elseif ( is_too_frequent( $event ) ) {
return sprintf(
'%1$s %2$s',
esc_html( $schedule_name ),
sprintf(
/* translators: 1: The name of the configuration constant, 2: The value of the configuration constant */
esc_html__( 'This interval is less than the %1$s constant which is set to %2$s seconds. Events that use it may not run on time.', 'wp-crontrol' ),
'WP_CRON_LOCK_TIMEOUT',
intval( WP_CRON_LOCK_TIMEOUT )
)
);
} else {
return esc_html( $schedule_name );
}
} else {
return esc_html__( 'Non-repeating', 'wp-crontrol' );
}
}
/**
* Outputs a message when there are no items to show in the table.
*
* @return void
*/
public function no_items() {
if ( empty( $_GET['s'] ) && empty( $_GET['crontrol_hooks_type'] ) ) {
esc_html_e( 'There are currently no scheduled cron events.', 'wp-crontrol' );
} else {
esc_html_e( 'No matching cron events.', 'wp-crontrol' );
}
}
}
src/request.php 0000644 00000002506 15054503403 0007536 0 ustar 00 $props Properties.
* @return Request This object.
*/
public function init( array $props ) {
foreach ( $props as $name => $value ) {
$prop = (string) preg_replace( '#^crontrol_#', '', $name );
if ( property_exists( $this, $prop ) ) {
$this->$prop = $value;
}
}
return $this;
}
}
src/bootstrap.php 0000644 00000211132 15054503403 0010060 0 ustar 00 $plugin_meta An array of the plugin row's meta data.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
* @return array An array of the plugin row's meta data.
*/
function filter_plugin_row_meta( array $plugin_meta, $plugin_file ) {
if ( 'wp-crontrol/wp-crontrol.php' !== $plugin_file ) {
return $plugin_meta;
}
$plugin_meta[] = sprintf(
'%2$s',
'https://github.com/sponsors/johnbillion',
esc_html_x( 'Sponsor', 'verb', 'wp-crontrol' )
);
return $plugin_meta;
}
/**
* Run using the 'init' action.
*
* @return void
*/
function action_init() {
load_plugin_textdomain( 'wp-crontrol', false, dirname( plugin_basename( PLUGIN_FILE ) ) . '/languages' );
/** @var array|false $paused */
$paused = get_option( PAUSED_OPTION );
if ( ! is_array( $paused ) ) {
$paused = array();
update_option( PAUSED_OPTION, $paused, true );
}
foreach ( $paused as $hook => $value ) {
if ( ! is_string( $hook ) ) {
continue;
}
add_action( $hook, __NAMESPACE__ . '\\pauser', -99999, 0 );
}
}
/**
* @return void
*/
function pauser() {
remove_all_actions( current_filter() );
}
/**
* Handles any POSTs and GETs made by the plugin. Run using the 'init' action.
*
* @return void
*/
function action_handle_posts() {
$request = new Request();
if ( isset( $_POST['crontrol_action'] ) && ( 'new_cron' === $_POST['crontrol_action'] ) ) {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to add new cron events.', 'wp-crontrol' ), 401 );
}
check_admin_referer( 'crontrol-new-cron' );
$cr = $request->init( wp_unslash( $_POST ) );
if ( 'crontrol_cron_job' === $cr->hookname && ! current_user_can( 'edit_files' ) ) {
wp_die( esc_html__( 'You are not allowed to add new PHP cron events.', 'wp-crontrol' ), 401 );
}
$args = json_decode( $cr->args, true );
if ( empty( $args ) || ! is_array( $args ) ) {
$args = array();
}
$next_run_local = ( 'custom' === $cr->next_run_date_local ) ? $cr->next_run_date_local_custom_date . ' ' . $cr->next_run_date_local_custom_time : $cr->next_run_date_local;
add_filter( 'schedule_event', function( $event ) {
if ( ! $event ) {
return $event;
}
/**
* Fires after a new cron event is added.
*
* @param stdClass $event {
* An object containing the event's data.
*
* @type string $hook Action hook to execute when the event is run.
* @type int $timestamp Unix timestamp (UTC) for when to next run the event.
* @type string|false $schedule How often the event should subsequently recur.
* @type mixed[] $args Array containing each separate argument to pass to the hook's callback function.
* @type int $interval The interval time in seconds for the schedule. Only present for recurring events.
* }
*/
do_action( 'crontrol/added_new_event', $event );
return $event;
}, 99 );
$added = Event\add( $next_run_local, $cr->schedule, $cr->hookname, $args );
$redirect = array(
'page' => 'crontrol_admin_manage_page',
'crontrol_message' => '5',
'crontrol_name' => rawurlencode( $cr->hookname ),
);
if ( is_wp_error( $added ) ) {
set_message( $added->get_error_message() );
$redirect['crontrol_message'] = 'error';
}
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'tools.php' ) ) );
exit;
} elseif ( isset( $_POST['crontrol_action'] ) && ( 'new_php_cron' === $_POST['crontrol_action'] ) ) {
if ( ! current_user_can( 'edit_files' ) ) {
wp_die( esc_html__( 'You are not allowed to add new PHP cron events.', 'wp-crontrol' ), 401 );
}
check_admin_referer( 'crontrol-new-cron' );
$cr = $request->init( wp_unslash( $_POST ) );
$next_run_local = ( 'custom' === $cr->next_run_date_local ) ? $cr->next_run_date_local_custom_date . ' ' . $cr->next_run_date_local_custom_time : $cr->next_run_date_local;
$args = array(
'code' => $cr->hookcode,
'name' => $cr->eventname,
);
add_filter( 'schedule_event', function( $event ) {
if ( ! $event ) {
return $event;
}
/**
* Fires after a new PHP cron event is added.
*
* @param stdClass $event {
* An object containing the event's data.
*
* @type string $hook Action hook to execute when the event is run.
* @type int $timestamp Unix timestamp (UTC) for when to next run the event.
* @type string|false $schedule How often the event should subsequently recur.
* @type mixed[] $args Array containing each separate argument to pass to the hook's callback function.
* @type int $interval The interval time in seconds for the schedule. Only present for recurring events.
* }
*/
do_action( 'crontrol/added_new_php_event', $event );
return $event;
}, 99 );
$added = Event\add( $next_run_local, $cr->schedule, 'crontrol_cron_job', $args );
$hookname = ( ! empty( $cr->eventname ) ) ? $cr->eventname : __( 'PHP Cron', 'wp-crontrol' );
$redirect = array(
'page' => 'crontrol_admin_manage_page',
'crontrol_message' => '5',
'crontrol_name' => rawurlencode( $hookname ),
);
if ( is_wp_error( $added ) ) {
set_message( $added->get_error_message() );
$redirect['crontrol_message'] = 'error';
}
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'tools.php' ) ) );
exit;
} elseif ( isset( $_POST['crontrol_action'] ) && ( 'edit_cron' === $_POST['crontrol_action'] ) ) {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to edit cron events.', 'wp-crontrol' ), 401 );
}
$cr = $request->init( wp_unslash( $_POST ) );
check_admin_referer( "crontrol-edit-cron_{$cr->original_hookname}_{$cr->original_sig}_{$cr->original_next_run_utc}" );
if ( 'crontrol_cron_job' === $cr->hookname && ! current_user_can( 'edit_files' ) ) {
wp_die( esc_html__( 'You are not allowed to edit PHP cron events.', 'wp-crontrol' ), 401 );
}
$args = json_decode( $cr->args, true );
if ( empty( $args ) || ! is_array( $args ) ) {
$args = array();
}
$redirect = array(
'page' => 'crontrol_admin_manage_page',
'crontrol_message' => '4',
'crontrol_name' => rawurlencode( $cr->hookname ),
);
$original = Event\get_single( $cr->original_hookname, $cr->original_sig, $cr->original_next_run_utc );
if ( is_wp_error( $original ) ) {
set_message( $original->get_error_message() );
$redirect['crontrol_message'] = 'error';
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'tools.php' ) ) );
exit;
}
$deleted = Event\delete( $cr->original_hookname, $cr->original_sig, $cr->original_next_run_utc );
if ( is_wp_error( $deleted ) ) {
set_message( $deleted->get_error_message() );
$redirect['crontrol_message'] = 'error';
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'tools.php' ) ) );
exit;
}
$next_run_local = ( 'custom' === $cr->next_run_date_local ) ? $cr->next_run_date_local_custom_date . ' ' . $cr->next_run_date_local_custom_time : $cr->next_run_date_local;
/**
* Modifies an event before it is scheduled.
*
* @param stdClass|false $event An object containing the new event's data, or boolean false.
*/
add_filter( 'schedule_event', function( $event ) use ( $original ) {
if ( ! $event ) {
return $event;
}
/**
* Fires after a cron event is edited.
*
* @param stdClass $event {
* An object containing the new event's data.
*
* @type string $hook Action hook to execute when the event is run.
* @type int $timestamp Unix timestamp (UTC) for when to next run the event.
* @type string|false $schedule How often the event should subsequently recur.
* @type mixed[] $args Array containing each separate argument to pass to the hook's callback function.
* @type int $interval The interval time in seconds for the schedule. Only present for recurring events.
* }
* @param stdClass $original {
* An object containing the original event's data.
*
* @type string $hook Action hook to execute when the event is run.
* @type int $timestamp Unix timestamp (UTC) for when to next run the event.
* @type string|false $schedule How often the event should subsequently recur.
* @type mixed[] $args Array containing each separate argument to pass to the hook's callback function.
* @type int $interval The interval time in seconds for the schedule. Only present for recurring events.
* }
*/
do_action( 'crontrol/edited_event', $event, $original );
return $event;
}, 99 );
$added = Event\add( $next_run_local, $cr->schedule, $cr->hookname, $args );
if ( is_wp_error( $added ) ) {
set_message( $added->get_error_message() );
$redirect['crontrol_message'] = 'error';
}
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'tools.php' ) ) );
exit;
} elseif ( isset( $_POST['crontrol_action'] ) && ( 'edit_php_cron' === $_POST['crontrol_action'] ) ) {
if ( ! current_user_can( 'edit_files' ) ) {
wp_die( esc_html__( 'You are not allowed to edit PHP cron events.', 'wp-crontrol' ), 401 );
}
$cr = $request->init( wp_unslash( $_POST ) );
check_admin_referer( "crontrol-edit-cron_{$cr->original_hookname}_{$cr->original_sig}_{$cr->original_next_run_utc}" );
$args = array(
'code' => $cr->hookcode,
'name' => $cr->eventname,
);
$hookname = ( ! empty( $cr->eventname ) ) ? $cr->eventname : __( 'PHP Cron', 'wp-crontrol' );
$redirect = array(
'page' => 'crontrol_admin_manage_page',
'crontrol_message' => '4',
'crontrol_name' => rawurlencode( $hookname ),
);
$original = Event\get_single( $cr->original_hookname, $cr->original_sig, $cr->original_next_run_utc );
if ( is_wp_error( $original ) ) {
set_message( $original->get_error_message() );
$redirect['crontrol_message'] = 'error';
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'tools.php' ) ) );
exit;
}
$deleted = Event\delete( $cr->original_hookname, $cr->original_sig, $cr->original_next_run_utc );
if ( is_wp_error( $deleted ) ) {
set_message( $deleted->get_error_message() );
$redirect['crontrol_message'] = 'error';
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'tools.php' ) ) );
exit;
}
$next_run_local = ( 'custom' === $cr->next_run_date_local ) ? $cr->next_run_date_local_custom_date . ' ' . $cr->next_run_date_local_custom_time : $cr->next_run_date_local;
/**
* Modifies an event before it is scheduled.
*
* @param stdClass|false $event An object containing the new event's data, or boolean false.
*/
add_filter( 'schedule_event', function( $event ) use ( $original ) {
if ( ! $event ) {
return $event;
}
/**
* Fires after a PHP cron event is edited.
*
* @param stdClass $event {
* An object containing the new event's data.
*
* @type string $hook Action hook to execute when the event is run.
* @type int $timestamp Unix timestamp (UTC) for when to next run the event.
* @type string|false $schedule How often the event should subsequently recur.
* @type mixed[] $args Array containing each separate argument to pass to the hook's callback function.
* @type int $interval The interval time in seconds for the schedule. Only present for recurring events.
* }
* @param stdClass $original {
* An object containing the original event's data.
*
* @type string $hook Action hook to execute when the event is run.
* @type int $timestamp Unix timestamp (UTC) for when to next run the event.
* @type string|false $schedule How often the event should subsequently recur.
* @type mixed[] $args Array containing each separate argument to pass to the hook's callback function.
* @type int $interval The interval time in seconds for the schedule. Only present for recurring events.
* }
*/
do_action( 'crontrol/edited_php_event', $event, $original );
return $event;
}, 99 );
$added = Event\add( $next_run_local, $cr->schedule, 'crontrol_cron_job', $args );
if ( is_wp_error( $added ) ) {
set_message( $added->get_error_message() );
$redirect['crontrol_message'] = 'error';
}
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'tools.php' ) ) );
exit;
} elseif ( isset( $_POST['crontrol_new_schedule'] ) ) {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to add new cron schedules.', 'wp-crontrol' ), 401 );
}
check_admin_referer( 'crontrol-new-schedule' );
$name = wp_unslash( $_POST['crontrol_schedule_internal_name'] );
$interval = absint( $_POST['crontrol_schedule_interval'] );
$display = wp_unslash( $_POST['crontrol_schedule_display_name'] );
Schedule\add( $name, $interval, $display );
$redirect = array(
'page' => 'crontrol_admin_options_page',
'crontrol_message' => '3',
'crontrol_name' => rawurlencode( $name ),
);
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'options-general.php' ) ) );
exit;
} elseif ( isset( $_GET['crontrol_action'] ) && 'delete-schedule' === $_GET['crontrol_action'] ) {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to delete cron schedules.', 'wp-crontrol' ), 401 );
}
$schedule = wp_unslash( $_GET['crontrol_id'] );
check_admin_referer( "crontrol-delete-schedule_{$schedule}" );
Schedule\delete( $schedule );
$redirect = array(
'page' => 'crontrol_admin_options_page',
'crontrol_message' => '2',
'crontrol_name' => rawurlencode( $schedule ),
);
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'options-general.php' ) ) );
exit;
} elseif ( ( isset( $_POST['action'] ) && 'crontrol_delete_crons' === $_POST['action'] ) || ( isset( $_POST['action2'] ) && 'crontrol_delete_crons' === $_POST['action2'] ) ) {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to delete cron events.', 'wp-crontrol' ), 401 );
}
check_admin_referer( 'bulk-crontrol-events' );
if ( empty( $_POST['crontrol_delete'] ) ) {
return;
}
/**
* @var array>
*/
$delete = (array) wp_unslash( $_POST['crontrol_delete'] );
$deleted = 0;
foreach ( $delete as $next_run_utc => $events ) {
foreach ( (array) $events as $hook => $sig ) {
if ( 'crontrol_cron_job' === $hook && ! current_user_can( 'edit_files' ) ) {
continue;
}
$event = Event\get_single( urldecode( $hook ), $sig, $next_run_utc );
$deleted = Event\delete( urldecode( $hook ), $sig, $next_run_utc );
if ( ! is_wp_error( $deleted ) ) {
$deleted++;
/** This action is documented in wp-crontrol.php */
do_action( 'crontrol/deleted_event', $event );
}
}
}
$redirect = array(
'page' => 'crontrol_admin_manage_page',
'crontrol_name' => $deleted,
'crontrol_message' => '9',
);
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'tools.php' ) ) );
exit;
} elseif ( isset( $_GET['crontrol_action'] ) && 'delete-cron' === $_GET['crontrol_action'] ) {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to delete cron events.', 'wp-crontrol' ), 401 );
}
$hook = wp_unslash( $_GET['crontrol_id'] );
$sig = wp_unslash( $_GET['crontrol_sig'] );
$next_run_utc = wp_unslash( $_GET['crontrol_next_run_utc'] );
check_admin_referer( "crontrol-delete-cron_{$hook}_{$sig}_{$next_run_utc}" );
if ( 'crontrol_cron_job' === $hook && ! current_user_can( 'edit_files' ) ) {
wp_die( esc_html__( 'You are not allowed to delete PHP cron events.', 'wp-crontrol' ), 401 );
}
$redirect = array(
'page' => 'crontrol_admin_manage_page',
'crontrol_message' => '6',
'crontrol_name' => rawurlencode( $hook ),
);
$event = Event\get_single( $hook, $sig, $next_run_utc );
if ( is_wp_error( $event ) ) {
set_message( $event->get_error_message() );
$redirect['crontrol_message'] = 'error';
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'tools.php' ) ) );
exit;
}
$deleted = Event\delete( $hook, $sig, $next_run_utc );
if ( is_wp_error( $deleted ) ) {
set_message( $deleted->get_error_message() );
$redirect['crontrol_message'] = 'error';
} else {
/**
* Fires after a cron event is deleted.
*
* @param stdClass $event {
* An object containing the event's data.
*
* @type string $hook Action hook to execute when the event is run.
* @type int $timestamp Unix timestamp (UTC) for when to next run the event.
* @type string|false $schedule How often the event should subsequently recur.
* @type mixed[] $args Array containing each separate argument to pass to the hook's callback function.
* @type int $interval The interval time in seconds for the schedule. Only present for recurring events.
* }
*/
do_action( 'crontrol/deleted_event', $event );
}
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'tools.php' ) ) );
exit;
} elseif ( isset( $_GET['crontrol_action'] ) && 'delete-hook' === $_GET['crontrol_action'] ) {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to delete cron events.', 'wp-crontrol' ), 401 );
}
$hook = wp_unslash( $_GET['crontrol_id'] );
$deleted = false;
check_admin_referer( "crontrol-delete-hook_{$hook}" );
if ( 'crontrol_cron_job' === $hook ) {
wp_die( esc_html__( 'You are not allowed to delete PHP cron events.', 'wp-crontrol' ), 401 );
}
if ( function_exists( 'wp_unschedule_hook' ) ) {
/** @var int|false */
$deleted = wp_unschedule_hook( $hook );
}
if ( 0 === $deleted ) {
$redirect = array(
'page' => 'crontrol_admin_manage_page',
'crontrol_message' => '3',
'crontrol_name' => rawurlencode( $hook ),
);
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'tools.php' ) ) );
exit;
} elseif ( $deleted ) {
/**
* Fires after all cron events with the given hook are deleted.
*
* @param string $hook The hook name.
* @param int $deleted The number of events that were deleted.
*/
do_action( 'crontrol/deleted_all_with_hook', $hook, $deleted );
$redirect = array(
'page' => 'crontrol_admin_manage_page',
'crontrol_message' => '2',
'crontrol_name' => rawurlencode( $hook ),
);
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'tools.php' ) ) );
exit;
} else {
$redirect = array(
'page' => 'crontrol_admin_manage_page',
'crontrol_message' => '7',
'crontrol_name' => rawurlencode( $hook ),
);
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'tools.php' ) ) );
exit;
}
} elseif ( isset( $_GET['crontrol_action'] ) && 'run-cron' === $_GET['crontrol_action'] ) {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to run cron events.', 'wp-crontrol' ), 401 );
}
$hook = wp_unslash( $_GET['crontrol_id'] );
$sig = wp_unslash( $_GET['crontrol_sig'] );
check_admin_referer( "crontrol-run-cron_{$hook}_{$sig}" );
$ran = Event\run( $hook, $sig );
$redirect = array(
'page' => 'crontrol_admin_manage_page',
'crontrol_message' => '1',
'crontrol_name' => rawurlencode( $hook ),
);
if ( is_wp_error( $ran ) ) {
$set = set_message( $ran->get_error_message() );
// If we can't store the error message in a transient, just display it.
if ( ! $set ) {
wp_die(
esc_html( $ran->get_error_message() ),
'',
array(
'response' => 500,
'back_link' => true,
)
);
}
$redirect['crontrol_message'] = 'error';
}
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'tools.php' ) ) );
exit;
} elseif ( isset( $_GET['crontrol_action'] ) && 'pause-hook' === $_GET['crontrol_action'] ) {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to pause or resume cron events.', 'wp-crontrol' ), 401 );
}
$hook = wp_unslash( $_GET['crontrol_id'] );
check_admin_referer( "crontrol-pause-hook_{$hook}" );
$paused = Event\pause( $hook );
$redirect = array(
'page' => 'crontrol_admin_manage_page',
'crontrol_message' => '11',
'crontrol_name' => rawurlencode( $hook ),
);
if ( is_wp_error( $paused ) ) {
$set = set_message( $paused->get_error_message() );
// If we can't store the error message in a transient, just display it.
if ( ! $set ) {
wp_die(
esc_html( $paused->get_error_message() ),
'',
array(
'response' => 500,
'back_link' => true,
)
);
}
$redirect['crontrol_message'] = 'error';
} else {
/**
* Fires after a cron event hook is paused.
*
* @param string $hook The event hook name.
*/
do_action( 'crontrol/paused_hook', $hook );
}
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'tools.php' ) ) );
exit;
} elseif ( isset( $_GET['crontrol_action'] ) && 'resume-hook' === $_GET['crontrol_action'] ) {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You are not allowed to pause or resume cron events.', 'wp-crontrol' ), 401 );
}
$hook = wp_unslash( $_GET['crontrol_id'] );
check_admin_referer( "crontrol-resume-hook_{$hook}" );
$resumed = Event\resume( $hook );
$redirect = array(
'page' => 'crontrol_admin_manage_page',
'crontrol_message' => '12',
'crontrol_name' => rawurlencode( $hook ),
);
if ( is_wp_error( $resumed ) ) {
$set = set_message( $resumed->get_error_message() );
// If we can't store the error message in a transient, just display it.
if ( ! $set ) {
wp_die(
esc_html( $resumed->get_error_message() ),
'',
array(
'response' => 500,
'back_link' => true,
)
);
}
$redirect['crontrol_message'] = 'error';
} else {
/**
* Fires after a paused cron event hook is resumed.
*
* @param string $hook The event hook name.
*/
do_action( 'crontrol/resumed_hook', $hook );
}
wp_safe_redirect( add_query_arg( $redirect, admin_url( 'tools.php' ) ) );
exit;
} elseif ( isset( $_POST['crontrol_action'] ) && 'export-event-csv' === $_POST['crontrol_action'] ) {
check_admin_referer( 'crontrol-export-event-csv', 'crontrol_nonce' );
$type = isset( $_POST['crontrol_hooks_type'] ) ? $_POST['crontrol_hooks_type'] : 'all';
$headers = array(
'hook',
'arguments',
'next_run',
'next_run_gmt',
'action',
'recurrence',
'interval',
);
$filename = sprintf(
'cron-events-%s-%s.csv',
$type,
gmdate( 'Y-m-d-H.i.s' )
);
$csv = fopen( 'php://output', 'w' );
if ( false === $csv ) {
wp_die( esc_html__( 'Could not save CSV file.', 'wp-crontrol' ) );
}
$events = Table::get_filtered_events( Event\get() );
header( 'Content-Type: text/csv; charset=utf-8' );
header(
sprintf(
'Content-Disposition: attachment; filename="%s"',
esc_attr( $filename )
)
);
fputcsv( $csv, $headers );
if ( isset( $events[ $type ] ) ) {
foreach ( $events[ $type ] as $event ) {
$next_run_local = get_date_from_gmt( gmdate( 'Y-m-d H:i:s', $event->timestamp ), 'c' );
$next_run_utc = gmdate( 'c', $event->timestamp );
$hook_callbacks = \Crontrol\get_hook_callbacks( $event->hook );
if ( 'crontrol_cron_job' === $event->hook ) {
$args = __( 'PHP Code', 'wp-crontrol' );
} elseif ( empty( $event->args ) ) {
$args = '';
} else {
$args = \Crontrol\json_output( $event->args, false );
}
if ( 'crontrol_cron_job' === $event->hook ) {
$action = __( 'WP Crontrol', 'wp-crontrol' );
} else {
$callbacks = array();
foreach ( $hook_callbacks as $callback ) {
$callbacks[] = $callback['callback']['name'];
}
$action = implode( ',', $callbacks );
}
if ( $event->schedule ) {
$recurrence = Event\get_schedule_name( $event );
if ( is_wp_error( $recurrence ) ) {
$recurrence = $recurrence->get_error_message();
}
} else {
$recurrence = __( 'Non-repeating', 'wp-crontrol' );
}
$row = array(
$event->hook,
$args,
$next_run_local,
$next_run_utc,
$action,
$recurrence,
(int) $event->interval,
);
fputcsv( $csv, $row );
}
}
fclose( $csv );
exit;
}
}
/**
* Adds options & management pages to the admin menu.
*
* Run using the 'admin_menu' action.
*
* @return void
*/
function action_admin_menu() {
$schedules = add_options_page(
esc_html__( 'Cron Schedules', 'wp-crontrol' ),
esc_html__( 'Cron Schedules', 'wp-crontrol' ),
'manage_options',
'crontrol_admin_options_page',
__NAMESPACE__ . '\admin_options_page'
);
$events = add_management_page(
esc_html__( 'Cron Events', 'wp-crontrol' ),
esc_html__( 'Cron Events', 'wp-crontrol' ),
'manage_options',
'crontrol_admin_manage_page',
__NAMESPACE__ . '\admin_manage_page'
);
add_action( "load-{$schedules}", __NAMESPACE__ . '\admin_help_tab' );
add_action( "load-{$events}", __NAMESPACE__ . '\admin_help_tab' );
}
/**
* Adds a Help tab with links to help resources.
*
* @return void
*/
function admin_help_tab() {
$screen = get_current_screen();
if ( ! $screen ) {
return;
}
$content = '
' . __( 'There are several places to get help with issues relating to WP-Cron:', 'wp-crontrol' ) . '
';
$content .= '
';
$content .= '
';
$content .= sprintf(
/* translators: %s: URL to the documentation */
__( 'Read the WP Crontrol wiki which contains information about events that have missed their schedule, problems with spawning a call to the WP-Cron system, and much more.', 'wp-crontrol' ),
'https://github.com/johnbillion/wp-crontrol/wiki'
);
$content .= '
';
$content .= '
';
$content .= sprintf(
/* translators: %s: URL to the documentation */
__( 'Read the Frequently Asked Questions (FAQ) which cover many common questions and answers.', 'wp-crontrol' ),
'https://wordpress.org/plugins/wp-crontrol/faq/'
);
$content .= '
';
$content .= '
';
$content .= sprintf(
/* translators: %s: URL to the documentation */
__( 'Read the WordPress.org documentation on WP-Cron for more technical details about the WP-Cron system for developers.', 'wp-crontrol' ),
'https://developer.wordpress.org/plugins/cron/'
);
$content .= '
';
$screen->add_help_tab(
array(
'id' => 'crontrol-help',
'title' => __( 'Help', 'wp-crontrol' ),
'content' => $content,
)
);
}
/**
* Adds items to the plugin's action links on the Plugins listing screen.
*
* @param array $actions Array of action links.
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
* @param mixed[] $plugin_data An array of plugin data.
* @param string $context The plugin context.
* @return array Array of action links.
*/
function plugin_action_links( $actions, $plugin_file, $plugin_data, $context ) {
$new = array(
'crontrol-events' => sprintf(
'%s',
esc_url( admin_url( 'tools.php?page=crontrol_admin_manage_page' ) ),
esc_html__( 'Events', 'wp-crontrol' )
),
'crontrol-schedules' => sprintf(
'%s',
esc_url( admin_url( 'options-general.php?page=crontrol_admin_options_page' ) ),
esc_html__( 'Schedules', 'wp-crontrol' )
),
'crontrol-help' => sprintf(
'%s',
'https://github.com/johnbillion/wp-crontrol/wiki',
esc_html__( 'Help', 'wp-crontrol' )
),
);
return array_merge( $new, $actions );
}
/**
* Adds items to the plugin's action links on the Network Admin -> Plugins listing screen.
*
* @param array $actions Array of action links.
* @return array Array of action links.
*/
function network_plugin_action_links( $actions ) {
$new = array(
'crontrol-help' => sprintf(
'%s',
'https://github.com/johnbillion/wp-crontrol/wiki',
esc_html__( 'Help', 'wp-crontrol' )
),
);
return array_merge( $new, $actions );
}
/**
* Gives WordPress the plugin's set of cron schedules.
*
* Called by the `cron_schedules` filter.
*
* @param array> $scheds Array of cron schedule arrays. Usually empty.
* @return array> Array of modified cron schedule arrays.
*/
function filter_cron_schedules( array $scheds ) {
$new_scheds = get_option( 'crontrol_schedules', array() );
if ( ! is_array( $new_scheds ) ) {
return $scheds;
}
return array_merge( $new_scheds, $scheds );
}
/**
* Displays the options page for the plugin.
*
* @return void
*/
function admin_options_page() {
$messages = array(
'2' => array(
/* translators: 1: The name of the cron schedule. */
__( 'Deleted the cron schedule %s.', 'wp-crontrol' ),
'success',
),
'3' => array(
/* translators: 1: The name of the cron schedule. */
__( 'Added the cron schedule %s.', 'wp-crontrol' ),
'success',
),
);
if ( isset( $_GET['crontrol_message'] ) && isset( $_GET['crontrol_name'] ) && isset( $messages[ $_GET['crontrol_message'] ] ) ) {
$hook = wp_unslash( $_GET['crontrol_name'] );
$message = wp_unslash( $_GET['crontrol_message'] );
printf(
'
',
/* translators: %s: Help page URL. */
esc_html__( 'PHP default timezone is not set to UTC. This may cause issues with cron event timings.', 'wp-crontrol' ),
'https://github.com/johnbillion/wp-crontrol/wiki/PHP-default-timezone-is-not-set-to-UTC',
esc_html__( 'More information', 'wp-crontrol' )
);
?>
',
sprintf(
/* translators: 1: Error message text. */
esc_html__( 'There was a problem spawning a call to the WP-Cron system on your site. This means WP-Cron events on your site may not work. The problem was: %s', 'wp-crontrol' ),
'
array(
/* translators: 1: The name of the cron event. */
__( 'Scheduled the cron event %s to run now. The original event will not be affected.', 'wp-crontrol' ),
'success',
),
'2' => array(
/* translators: 1: The name of the cron event. */
__( 'Deleted all %s cron events.', 'wp-crontrol' ),
'success',
),
'3' => array(
/* translators: 1: The name of the cron event. */
__( 'There are no %s cron events to delete.', 'wp-crontrol' ),
'info',
),
'4' => array(
/* translators: 1: The name of the cron event. */
__( 'Saved the cron event %s.', 'wp-crontrol' ),
'success',
),
'5' => array(
/* translators: 1: The name of the cron event. */
__( 'Created the cron event %s.', 'wp-crontrol' ),
'success',
),
'6' => array(
/* translators: 1: The name of the cron event. */
__( 'Deleted the cron event %s.', 'wp-crontrol' ),
'success',
),
'7' => array(
/* translators: 1: The name of the cron event. */
__( 'Failed to the delete the cron event %s.', 'wp-crontrol' ),
'error',
),
'8' => array(
/* translators: 1: The name of the cron event. */
__( 'Failed to the execute the cron event %s.', 'wp-crontrol' ),
'error',
),
'9' => array(
__( 'Deleted the selected cron events.', 'wp-crontrol' ),
'success',
),
'10' => array(
/* translators: 1: The name of the cron event. */
__( 'Failed to save the cron event %s.', 'wp-crontrol' ),
'error',
),
'11' => array(
/* translators: 1: The name of the cron event. */
__( 'Paused the %s hook.', 'wp-crontrol' ),
'success',
),
'12' => array(
/* translators: 1: The name of the cron event. */
__( 'Resumed the %s hook.', 'wp-crontrol' ),
'success',
),
'error' => array(
__( 'An unknown error occurred.', 'wp-crontrol' ),
'error',
),
);
if ( isset( $_GET['crontrol_name'] ) && isset( $_GET['crontrol_message'] ) && isset( $messages[ $_GET['crontrol_message'] ] ) ) {
$hook = wp_unslash( $_GET['crontrol_name'] );
$message = wp_unslash( $_GET['crontrol_message'] );
$link = '';
if ( 'error' === $message ) {
$error = get_message();
if ( $error ) {
$messages['error'][0] = $error;
}
}
printf(
'
> Array of callbacks attached to the hook.
* @phpstan-return array,
* }>
*/
function get_hook_callbacks( $name ) {
global $wp_filter;
$actions = array();
if ( isset( $wp_filter[ $name ] ) ) {
// See http://core.trac.wordpress.org/ticket/17817.
$action = $wp_filter[ $name ];
/**
* @var int $priority
*/
foreach ( $action as $priority => $callbacks ) {
foreach ( $callbacks as $callback ) {
$callback = populate_callback( $callback );
if ( __NAMESPACE__ . '\\pauser()' === $callback['name'] ) {
continue;
}
$actions[] = array(
'priority' => $priority,
'callback' => $callback,
);
}
}
}
return $actions;
}
/**
* Populates the details of the given callback function.
*
* @param array $callback A callback entry.
* @phpstan-param array{
* function: string|array|object,
* accepted_args: int,
* } $callback
* @return array The updated callback entry.
*/
function populate_callback( array $callback ) {
// If Query Monitor is installed, use its rich callback analysis.
if ( method_exists( '\QM_Util', 'populate_callback' ) ) {
return \QM_Util::populate_callback( $callback );
}
if ( is_string( $callback['function'] ) && ( false !== strpos( $callback['function'], '::' ) ) ) {
$callback['function'] = explode( '::', $callback['function'] );
}
if ( is_array( $callback['function'] ) ) {
if ( is_object( $callback['function'][0] ) ) {
$class = get_class( $callback['function'][0] );
$access = '->';
} else {
$class = $callback['function'][0];
$access = '::';
}
$callback['name'] = $class . $access . $callback['function'][1] . '()';
} elseif ( is_object( $callback['function'] ) ) {
if ( is_a( $callback['function'], 'Closure' ) ) {
$callback['name'] = 'Closure';
} else {
$class = get_class( $callback['function'] );
$callback['name'] = $class . '->__invoke()';
}
} else {
$callback['name'] = $callback['function'] . '()';
}
if ( ! method_exists( '\QM_Util', 'populate_callback' ) && ! is_callable( $callback['function'] ) ) {
$callback['error'] = new WP_Error(
'not_callable',
sprintf(
/* translators: %s: Function name */
__( 'Function %s does not exist', 'wp-crontrol' ),
$callback['name']
)
);
}
return $callback;
}
/**
* Returns a user-friendly representation of the callback function.
*
* @param mixed[] $callback The callback entry.
* @return string The displayable version of the callback name.
*/
function output_callback( array $callback ) {
$qm = WP_PLUGIN_DIR . '/query-monitor/query-monitor.php';
$html = plugin_dir_path( $qm ) . 'output/Html.php';
if ( ! empty( $callback['callback']['error'] ) ) {
$return = '' . $callback['callback']['name'] . '';
$return .= ' ';
$return .= esc_html( $callback['callback']['error']->get_error_message() );
$return .= '';
return $return;
}
// If Query Monitor is installed, use its rich callback output.
if ( class_exists( '\QueryMonitor' ) && file_exists( $html ) ) {
require_once $html;
if ( class_exists( '\QM_Output_Html' ) ) {
return \QM_Output_Html::output_filename(
$callback['callback']['name'],
$callback['callback']['file'],
$callback['callback']['line']
);
}
}
return '' . $callback['callback']['name'] . '';
}
/**
* Pretty-prints the difference in two times.
*
* @param int $older_date Unix timestamp.
* @param int $newer_date Unix timestamp.
* @return string The pretty time_since value
* @link http://binarybonsai.com/code/timesince.txt
*/
function time_since( $older_date, $newer_date ) {
return interval( $newer_date - $older_date );
}
/**
* Converts a period of time in seconds into a human-readable format representing the interval.
*
* Example:
*
* echo \Crontrol\interval( 90 );
* // 1 minute 30 seconds
*
* @param int|float $since A period of time in seconds.
* @return string An interval represented as a string.
*/
function interval( $since ) {
// Array of time period chunks.
$chunks = array(
/* translators: 1: The number of years in an interval of time. */
array( YEAR_IN_SECONDS, _n_noop( '%s year', '%s years', 'wp-crontrol' ) ),
/* translators: 1: The number of months in an interval of time. */
array( MONTH_IN_SECONDS, _n_noop( '%s month', '%s months', 'wp-crontrol' ) ),
/* translators: 1: The number of weeks in an interval of time. */
array( WEEK_IN_SECONDS, _n_noop( '%s week', '%s weeks', 'wp-crontrol' ) ),
/* translators: 1: The number of days in an interval of time. */
array( DAY_IN_SECONDS, _n_noop( '%s day', '%s days', 'wp-crontrol' ) ),
/* translators: 1: The number of hours in an interval of time. */
array( HOUR_IN_SECONDS, _n_noop( '%s hour', '%s hours', 'wp-crontrol' ) ),
/* translators: 1: The number of minutes in an interval of time. */
array( MINUTE_IN_SECONDS, _n_noop( '%s minute', '%s minutes', 'wp-crontrol' ) ),
/* translators: 1: The number of seconds in an interval of time. */
array( 1, _n_noop( '%s second', '%s seconds', 'wp-crontrol' ) ),
);
if ( $since <= 0 ) {
return __( 'now', 'wp-crontrol' );
}
/**
* We only want to output two chunks of time here, eg:
* x years, xx months
* x days, xx hours
* so there's only two bits of calculation below:
*/
// Step one: the first chunk.
foreach ( array_keys( $chunks ) as $i ) {
$seconds = $chunks[ $i ][0];
$name = $chunks[ $i ][1];
// Finding the biggest chunk (if the chunk fits, break).
$count = (int) floor( $since / $seconds );
if ( $count ) {
break;
}
}
// Set output var.
$output = sprintf( translate_nooped_plural( $name, $count, 'wp-crontrol' ), $count );
// Step two: the second chunk.
if ( $i + 1 < count( $chunks ) ) {
$seconds2 = $chunks[ $i + 1 ][0];
$name2 = $chunks[ $i + 1 ][1];
$count2 = (int) floor( ( $since - ( $seconds * $count ) ) / $seconds2 );
if ( $count2 ) {
// Add to output var.
$output .= ' ' . sprintf( translate_nooped_plural( $name2, $count2, 'wp-crontrol' ), $count2 );
}
}
return $output;
}
/**
* Sets up the Events listing screen.
*
* @return void
*/
function setup_manage_page() {
// Initialise the list table
Event\get_list_table();
}
/**
* Registers the stylesheet and JavaScript for the admin areas.
*
* @param string $hook_suffix The admin screen ID.
* @return void
*/
function enqueue_assets( $hook_suffix ) {
$tab = get_tab_states();
if ( ! array_filter( $tab ) ) {
return;
}
wp_enqueue_style(
'wp-crontrol',
plugin_dir_url( PLUGIN_FILE ) . 'css/wp-crontrol.css',
array(
'dashicons',
),
WP_CRONTROL_VERSION
);
wp_enqueue_script(
'wp-crontrol',
plugin_dir_url( PLUGIN_FILE ) . 'js/wp-crontrol.js',
array(
'jquery',
'wp-a11y',
),
WP_CRONTROL_VERSION,
true
);
$vars = array();
if ( ! empty( $tab['add-event'] ) || ! empty( $tab['edit-event'] ) ) {
if ( function_exists( 'wp_enqueue_code_editor' ) && current_user_can( 'edit_files' ) ) {
$settings = wp_enqueue_code_editor( array(
'type' => 'text/x-php',
) );
if ( false !== $settings ) {
$vars['codeEditor'] = $settings;
}
}
}
wp_localize_script( 'wp-crontrol', 'wpCrontrol', $vars );
}
/**
* Filters the list of query arguments which get removed from admin area URLs in WordPress.
*
* @param array $args List of removable query arguments.
* @return array Updated list of removable query arguments.
*/
function filter_removable_query_args( array $args ) {
return array_merge( $args, array(
'crontrol_message',
'crontrol_name',
) );
}
/**
* Returns an array of cron event hooks that are persistently added by WordPress core.
*
* @return array Array of hook names.
*/
function get_persistent_core_hooks() {
return array(
'wp_update_plugins', // 2.7.0
'wp_update_themes', // 2.7.0
'wp_version_check', // 2.7.0
'wp_scheduled_delete', // 2.9.0
'update_network_counts', // 3.1.0
'wp_scheduled_auto_draft_delete', // 3.4.0
'delete_expired_transients', // 4.9.0
'wp_privacy_delete_old_export_files', // 4.9.6
'recovery_mode_clean_expired_keys', // 5.2.0
'wp_site_health_scheduled_check', // 5.4.0
'wp_https_detection', // 5.7.0
'wp_update_user_counts', // 6.0.0
);
}
/**
* Returns an array of all cron event hooks that are added by WordPress core.
*
* @return array Array of hook names.
*/
function get_all_core_hooks() {
return array_merge(
get_persistent_core_hooks(),
array(
'do_pings', // 2.1.0
'publish_future_post', // 2.1.0
'importer_scheduled_cleanup', // 2.5.0
'upgrader_scheduled_cleanup', // 3.2.2
'wp_maybe_auto_update', // 3.7.0
'wp_split_shared_term_batch', // 4.3.0
'wp_update_comment_type_batch', // 5.5.0
'wp_delete_temp_updater_backups', // 5.9.0
)
);
}
/**
* Returns an array of cron schedules that are added by WordPress core.
*
* @return array Array of schedule names.
*/
function get_core_schedules() {
return array(
'hourly',
'twicedaily',
'daily',
'weekly',
);
}
/**
* Encodes some input as JSON for output.
*
* @param mixed $input The input.
* @param bool $pretty Whether to pretty print the output. Default true.
* @return string The JSON-encoded output.
*/
function json_output( $input, $pretty = true ) {
$json_options = 0;
if ( defined( 'JSON_UNESCAPED_SLASHES' ) ) {
// phpcs:ignore PHPCompatibility.Constants.NewConstants.json_unescaped_slashesFound
$json_options |= JSON_UNESCAPED_SLASHES;
}
if ( $pretty && defined( 'JSON_PRETTY_PRINT' ) ) {
$json_options |= JSON_PRETTY_PRINT;
}
$output = wp_json_encode( $input, $json_options );
if ( false === $output ) {
$output = '';
}
return $output;
}
/**
* Evaluates the code in a PHP cron event using eval.
*
* Security: Only users with the `edit_files` capability can manage PHP cron events. This means if a user cannot edit
* files on the site (eg. through the Plugin Editor or Theme Editor) then they cannot edit or add a PHP cron event. By
* default, only Administrators have this capability, and with Multisite enabled only Super Admins have this capability.
*
* If file editing has been disabled via the `DISALLOW_FILE_MODS` or `DISALLOW_FILE_EDIT` configuration constants then
* no user will have the `edit_files` capability, which means editing or adding a PHP cron event will not be permitted.
*
* Therefore, the user access level required to execute arbitrary PHP code does not change with WP Crontrol activated.
*
* @param string $code The PHP code to evaluate.
* @return void
*/
function action_php_cron_event( $code ) {
// phpcs:ignore Squiz.PHP.Eval.Discouraged
eval( $code );
}
composer.json 0000644 00000004663 15054503403 0007276 0 ustar 00 {
"name": "johnbillion/wp-crontrol",
"description": "WP Crontrol lets you view and control what's happening in the WP-Cron system.",
"homepage": "https://github.com/johnbillion/wp-crontrol/",
"license": "GPL-2.0-or-later",
"type": "wordpress-plugin",
"authors": [
{
"name": "John Blackbourn",
"homepage": "https://johnblackbourn.com/"
},
{
"name": "Edward Dale",
"homepage": "http://scompt.com/"
}
],
"config": {
"sort-packages": true,
"preferred-install": "dist",
"prepend-autoloader": false,
"classmap-authoritative": true,
"allow-plugins": {
"composer/installers": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"roots/wordpress-core-installer": true
}
},
"require-dev": {
"codeception/module-asserts": "^1.0",
"codeception/module-filesystem": "^1.0",
"codeception/module-webdriver": "^1.0",
"codeception/util-universalframework": "^1.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"lucatume/wp-browser": "^3.0",
"phpcompatibility/phpcompatibility-wp": "2.1.2",
"phpstan/phpstan": "^1.7",
"phpunit/phpunit": "^9.0",
"roots/wordpress-core-installer": "^1.0.0",
"roots/wordpress-full": "*",
"szepeviktor/phpstan-wordpress": "^1.0",
"wp-coding-standards/wpcs": "2.3.0"
},
"require": {
"php": ">=7.4",
"composer/installers": "^1.0 || ^2.0"
},
"autoload": {
"classmap": [
"src"
]
},
"extra": {
"wordpress-install-dir": "tests/wordpress"
},
"scripts": {
"test:cs": [
"phpcs -nps --colors --report-code --report-summary --report-width=80 --cache=tests/cache/phpcs56.json --basepath=./ --standard=phpcs56.xml",
"phpcs -nps --colors --report-code --report-summary --report-width=80 --cache=tests/cache/phpcs.json --basepath=./ ."
],
"test:cs2pr": [
"phpcs -nsq --report=checkstyle --cache=tests/cache/phpcs . | cs2pr"
],
"test:analyze": [
"phpstan analyze --memory-limit=1024M"
],
"test:start": [
"docker compose up -d"
],
"test:acceptance": [
"bin/test.sh"
],
"test:stop": [
"docker compose down"
],
"test": [
"composer validate --strict",
"@test:cs",
"@test:analyze",
"@test:acceptance"
]
},
"support": {
"issues": "https://github.com/johnbillion/wp-crontrol/issues",
"forum": "https://wordpress.org/support/plugin/wp-crontrol",
"source": "https://github.com/johnbillion/wp-crontrol"
},
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/johnbillion"
}
]
}
wp-crontrol.php 0000644 00000003546 15054503403 0007552 0 ustar 00 =' ) ) {
return;
}
if ( ! file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
return;
}
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/src/bootstrap.php';
require_once __DIR__ . '/src/event.php';
require_once __DIR__ . '/src/schedule.php';
// Get this show on the road.
init_hooks();
css/wp-crontrol.css 0000644 00000003544 15054503403 0010341 0 ustar 00 table.wp-list-table {
width: 100%;
max-width: 100%;
table-layout: auto;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
-ms-overflow-style: -ms-autohiding-scrollbar;
}
.wp-list-table pre {
white-space: pre-wrap;
margin: 0;
}
.wp-list-table code {
background: transparent;
padding: 0;
font-size: 12px;
}
.wp-list-table td.column-crontrol_status {
white-space: nowrap;
}
.wp-list-table td.column-cb,
.wp-list-table tbody th {
border-left: 4px solid transparent;
}
.wp-list-table tr.crontrol-no-action th,
.wp-list-table tr.crontrol-warning th {
border-color: #dba617;
}
.wp-list-table tr.crontrol-error th {
border-color: #d63638;
}
.wp-list-table tr.crontrol-paused th {
border-color: #8c8f94;
}
.wp-list-table tr.crontrol-paused:not(.crontrol-no-action) .column-crontrol_actions {
text-decoration: line-through;
}
.wp-list-table .column-crontrol_icon .dashicons,
.wp-list-table .check-column .dashicons {
margin-left: 6px;
font-size: 15px;
}
.wp-list-table .column-crontrol_icon .dashicons {
margin-top: 2px;
}
.wp-list-table .qm-icon-edit {
display: none;
}
.status-crontrol-warning,
.wp-list-table tr.crontrol-no-action td.column-crontrol_status,
.wp-list-table tr.crontrol-warning td.column-crontrol_status {
color: #bd8600;
}
.status-crontrol-error,
.wp-list-table tr.crontrol-error td.column-crontrol_status {
color: #d63638;
}
.status-crontrol-paused .dashicons {
background: #646970;
border-radius: 50%;
color: #fff;
font-size: 14px;
height: 14px;
line-height: 14px;
margin-top: 2px;
padding: 1px;
width: 14px;
}
.column-crontrol_time,
.column-crontrol_ran,
.column-crontrol_next {
white-space: nowrap;
}
.row-actions .crontrol-in-use {
color: #646970;
}
.form-field input[type="number"] {
width: 100px;
}
.crontrol-edit-event-standard .crontrol-event-php,
.crontrol-edit-event-php .crontrol-event-standard {
display: none;
}
LICENSE 0000644 00000043136 15054503403 0005557 0 ustar 00 GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{{description}}
Copyright (C) {{year}} {{fullname}}
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
{signature of Ty Coon}, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
js/wp-crontrol.js 0000644 00000002140 15054503403 0010000 0 ustar 00 /**
* Functionality related to Crontrol.
*/
jQuery(function($){
$('#crontrol_next_run_date_local_custom_date,#crontrol_next_run_date_local_custom_time').on('change', function() {
$('#crontrol_next_run_date_local_custom').prop('checked',true);
});
if ( $('input[value="new_php_cron"]').length ) {
$('input[value="new_cron"]').on('click',function(){
$('.crontrol-edit-event').removeClass('crontrol-edit-event-php').addClass('crontrol-edit-event-standard');
$('#crontrol_hookname').attr('required',true);
});
$('input[value="new_php_cron"]').on('click',function(){
$('.crontrol-edit-event').removeClass('crontrol-edit-event-standard').addClass('crontrol-edit-event-php');
$('#crontrol_hookname').attr('required',false);
if ( ! $('#crontrol_hookcode').hasClass('crontrol-editor-initialized') ) {
wp.codeEditor.initialize( 'crontrol_hookcode', window.wpCrontrol.codeEditor );
}
$('#crontrol_hookcode').addClass('crontrol-editor-initialized');
});
} else if ( $('#crontrol_hookcode').length ) {
wp.codeEditor.initialize( 'crontrol_hookcode', window.wpCrontrol.codeEditor );
}
});