PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 4.7.0
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v4.7.0
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / includes / backward-compatibility-functions.php

backward-compatibility-functions.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 4.7.0, at includes/backward-compatibility-functions.php

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