| 1 |
<?php |
| 2 |
/** |
| 3 |
* Normalize a filesystem path. |
| 4 |
*/ |
| 5 |
if (!function_exists('wp_normalize_path')) { |
| 6 |
/** |
| 7 |
* WordPress function to normalize a filesystem path; was added to WP core in WP 3.9 |
| 8 |
* |
| 9 |
* @see wp_normalize_path() https://developer.wordpress.org/reference/functions/wp_normalize_path/#source for the original source code |
| 10 |
* |
| 11 |
* @param string $path Path to normalize. |
| 12 |
* @return string Normalized path. |
| 13 |
*/ |
| 14 |
function wp_normalize_path($path) { |
| 15 |
$wrapper = ''; |
| 16 |
if (wp_is_stream($path)) { |
| 17 |
list($wrapper, $path) = explode('://', $path, 2); |
| 18 |
$wrapper .= '://'; |
| 19 |
} |
| 20 |
// Standardise all paths to use / |
| 21 |
$path = str_replace('\\', '/', $path); |
| 22 |
// Replace multiple slashes down to a singular, allowing for network shares having two slashes. |
| 23 |
$path = preg_replace('|(?<=.)/+|', '/', $path); |
| 24 |
// Windows paths should uppercase the drive letter |
| 25 |
if (':' === substr($path, 1, 1)) { |
| 26 |
$path = ucfirst($path); |
| 27 |
} |
| 28 |
return $wrapper.$path; |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Unschedules all events attached to the hook. |
| 34 |
*/ |
| 35 |
if (!function_exists('wp_unschedule_hook')) { |
| 36 |
/** |
| 37 |
* Unschedules all events attached to the hook. |
| 38 |
* |
| 39 |
* Can be useful for plugins when deactivating to clean up the cron queue. |
| 40 |
* |
| 41 |
* Warning: This function may return Boolean FALSE, but may also return a non-Boolean |
| 42 |
* value which evaluates to FALSE. For information about casting to booleans see the |
| 43 |
* {@link https://www.php.net/manual/en/language.types.boolean.php PHP documentation}. Use |
| 44 |
* the `===` operator for testing the return value of this function. |
| 45 |
* |
| 46 |
* @since 4.9.0 |
| 47 |
* @since 5.1.0 Return value added to indicate success or failure. |
| 48 |
* |
| 49 |
* @param string $hook Action hook, the execution of which will be unscheduled. |
| 50 |
* @return int|false On success an integer indicating number of events unscheduled (0 indicates no |
| 51 |
* events were registered on the hook), false if unscheduling fails. |
| 52 |
*/ |
| 53 |
function wp_unschedule_hook($hook) { |
| 54 |
/** |
| 55 |
* Filter to preflight or hijack clearing all events attached to the hook. |
| 56 |
* |
| 57 |
* Returning a non-null value will short-circuit the normal unscheduling |
| 58 |
* process, causing the function to return the filtered value instead. |
| 59 |
* |
| 60 |
* For plugins replacing wp-cron, return the number of events successfully |
| 61 |
* unscheduled (zero if no events were registered with the hook) or false |
| 62 |
* if unscheduling one or more events fails. |
| 63 |
* |
| 64 |
* @since 5.1.0 |
| 65 |
* |
| 66 |
* @param null|int|false $pre Value to return instead. Default null to continue unscheduling the hook. |
| 67 |
* @param string $hook Action hook, the execution of which will be unscheduled. |
| 68 |
*/ |
| 69 |
$pre = apply_filters('pre_unschedule_hook', null, $hook); |
| 70 |
if (null !== $pre) { |
| 71 |
return $pre; |
| 72 |
} |
| 73 |
|
| 74 |
$crons = _get_cron_array(); |
| 75 |
if (empty($crons)) { |
| 76 |
return 0; |
| 77 |
} |
| 78 |
|
| 79 |
$results = array(); |
| 80 |
foreach ($crons as $timestamp => $args) { |
| 81 |
if (!empty($crons[$timestamp][$hook])) { |
| 82 |
$results[] = count($crons[$timestamp][$hook]); |
| 83 |
} |
| 84 |
unset($crons[$timestamp][$hook]); |
| 85 |
|
| 86 |
if (empty($crons[$timestamp])) { |
| 87 |
unset($crons[$timestamp]); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
/* |
| 92 |
* If the results are empty (zero events to unschedule), no attempt |
| 93 |
* to update the cron array is required. |
| 94 |
*/ |
| 95 |
if (empty($results)) { |
| 96 |
return 0; |
| 97 |
} |
| 98 |
if (_set_cron_array($crons)) { |
| 99 |
return array_sum($results); |
| 100 |
} |
| 101 |
return false; |
| 102 |
} |
| 103 |
} |
| 104 |
|