PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.17.9
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.17.9
1.19.8 1.19.7 1.19.6 1.19.5 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.12.0 1.13.0 1.14.0 1.15.0 1.15.1 1.15.2 1.15.3 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.16.7 1.16.8 1.17.0 1.17.6 1.17.7 1.17.8 1.17.9 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.18.5 1.18.6 1.18.7 1.18.8 1.18.9 1.19.0 1.19.1 1.19.2 1.19.3 1.19.4 1.3.19 1.3.20 1.4.0 1.4.1 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.8.1 1.8.3 1.9.0 1.9.1 1.9.2
nitropack / helpers.php
nitropack Last commit date
classes 1 year ago languages 1 year ago nitropack-sdk 1 year ago view 1 year ago advanced-cache.php 2 years ago batcache-compat.php 4 years ago constants.php 1 year ago diagnostics.php 2 years ago functions.php 1 year ago helpers.php 3 years ago main.php 1 year ago readme.txt 1 year ago uninstall.php 1 year ago
helpers.php
111 lines
1 <?php
2 defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
3
4 if( ! function_exists( 'remove_class_filter' ) ){
5 /**
6 * Remove Class Filter Without Access to Class Object
7 *
8 * In order to use the core WordPress remove_filter() on a filter added with the callback
9 * to a class, you either have to have access to that class object, or it has to be a call
10 * to a static method. This method allows you to remove filters with a callback to a class
11 * you don't have access to.
12 *
13 * Works with WordPress 1.2+ (4.7+ support added 9-19-2016)
14 * Updated 2-27-2017 to use internal WordPress removal for 4.7+ (to prevent PHP warnings output)
15 *
16 * @param string $tag Filter to remove
17 * @param string $class_name Class name for the filter's callback
18 * @param string $method_name Method name for the filter's callback
19 * @param int $priority Priority of the filter (default 10)
20 *
21 * @return bool Whether the function is removed.
22 */
23 function remove_class_filter( $tag, $class_name = '', $method_name = '', $priority = 10 ) {
24 global $wp_filter;
25 // Check that filter actually exists first
26 if ( ! isset( $wp_filter[ $tag ] ) ) {
27 return FALSE;
28 }
29
30 /**
31 * If filter config is an object, means we're using WordPress 4.7+ and the config is no longer
32 * a simple array, rather it is an object that implements the ArrayAccess interface.
33 *
34 * To be backwards compatible, we set $callbacks equal to the correct array as a reference (so $wp_filter is updated)
35 *
36 * @see https://make.wordpress.org/core/2016/09/08/wp_hook-next-generation-actions-and-filters/
37 */
38 if ( is_object( $wp_filter[ $tag ] ) && isset( $wp_filter[ $tag ]->callbacks ) ) {
39 // Create $fob object from filter tag, to use below
40 $fob = $wp_filter[ $tag ];
41 $callbacks = &$wp_filter[ $tag ]->callbacks;
42 } else {
43 $callbacks = &$wp_filter[ $tag ];
44 }
45 // Exit if there aren't any callbacks for specified priority
46 if ( ! isset( $callbacks[ $priority ] ) || empty( $callbacks[ $priority ] ) ) {
47 return FALSE;
48 }
49 // Loop through each filter for the specified priority, looking for our class & method
50 foreach ( (array) $callbacks[ $priority ] as $filter_id => $filter ) {
51 // Filter should always be an array - array( $this, 'method' ), if not goto next
52 if ( ! isset( $filter['function'] ) || ! is_array( $filter['function'] ) ) {
53 continue;
54 }
55 // If first value in array is not an object, it can't be a class
56 if ( ! is_object( $filter['function'][0] ) ) {
57 continue;
58 }
59 // Method doesn't match the one we're looking for, goto next
60 if ( $filter['function'][1] !== $method_name ) {
61 continue;
62 }
63 // Method matched, now let's check the Class
64 if ( get_class( $filter['function'][0] ) === $class_name ) {
65 // WordPress 4.7+ use core remove_filter() since we found the class object
66 if ( isset( $fob ) ) {
67 // Handles removing filter, reseting callback priority keys mid-iteration, etc.
68 $fob->remove_filter( $tag, $filter['function'], $priority );
69 } else {
70 // Use legacy removal process (pre 4.7)
71 unset( $callbacks[ $priority ][ $filter_id ] );
72 // and if it was the only filter in that priority, unset that priority
73 if ( empty( $callbacks[ $priority ] ) ) {
74 unset( $callbacks[ $priority ] );
75 }
76 // and if the only filter for that tag, set the tag to an empty array
77 if ( empty( $callbacks ) ) {
78 $callbacks = array();
79 }
80 // Remove this filter from merged_filters, which specifies if filters have been sorted
81 unset( $GLOBALS['merged_filters'][ $tag ] );
82 }
83 return TRUE;
84 }
85 }
86 return FALSE;
87 }
88 }
89
90 if( ! function_exists( 'remove_class_action') ){
91 /**
92 * Remove Class Action Without Access to Class Object
93 *
94 * In order to use the core WordPress remove_action() on an action added with the callback
95 * to a class, you either have to have access to that class object, or it has to be a call
96 * to a static method. This method allows you to remove actions with a callback to a class
97 * you don't have access to.
98 *
99 * Works with WordPress 1.2+ (4.7+ support added 9-19-2016)
100 *
101 * @param string $tag Action to remove
102 * @param string $class_name Class name for the action's callback
103 * @param string $method_name Method name for the action's callback
104 * @param int $priority Priority of the action (default 10)
105 *
106 * @return bool Whether the function is removed.
107 */
108 function remove_class_action( $tag, $class_name = '', $method_name = '', $priority = 10 ) {
109 remove_class_filter( $tag, $class_name, $method_name, $priority );
110 }
111 }