PluginProbe ʕ •ᴥ•ʔ
Smush – Image Optimization, Compression, Lazy Load, WebP & CDN / 3.15.3
Smush – Image Optimization, Compression, Lazy Load, WebP & CDN v3.15.3
4.1.0 4.0.3 4.0.2 2.8.1 2.9.1 3.0.0 3.0.1 3.0.2 3.1.1 3.10.1 3.10.2 3.10.3 3.11.1 3.12.3 3.12.4 3.12.5 3.12.6 3.13.0 3.13.1 3.13.2 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.2 3.16.4 3.16.5 3.16.6 3.17.0 3.17.1 3.18.0 3.18.1 3.2.0.1 3.2.1 3.2.2.1 3.2.4 3.20.0 3.21.1 3.22.1 3.22.3 3.23.0 3.23.1 3.23.2 3.23.3 3.23.4 3.24.0 3.24.0-beta.2 3.3.0 3.3.1 3.3.2 3.4.1 3.4.2 3.6.1 3.6.3 3.7.0 3.7.1 3.7.2 3.7.3 3.8.2 3.8.3 3.8.4 3.8.5 3.8.7 3.8.8 3.9.0 3.9.1 3.9.11 3.9.2 3.9.4 3.9.5 3.9.8 3.9.9 trunk 1.0.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.2 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.5.1 1.6.5.2 1.6.5.3 1.6.5.4 1.7 1.7.1 1.7.1.1 2.0 2.0.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.6.2 2.0.6.3 2.0.6.5 2.0.7 2.0.7.1 2.1 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.2 2.3 2.3.1 2.4 2.4.2 2.4.3 2.4.4 2.4.5 2.5.2 2.5.3 2.6.1 2.6.2 2.6.3 2.7 2.7.1 2.7.4 2.7.4.1 2.7.5 2.7.6 2.7.8 2.7.8.1 2.7.9.1 2.8.0 2.8.0.1
wp-smushit / core / class-deprecated-hooks.php
wp-smushit / core Last commit date
api 2 years ago backups 2 years ago external 2 years ago integrations 2 years ago media 2 years ago media-library 2 years ago modules 2 years ago photon 2 years ago png2jpg 2 years ago resize 2 years ago s3 2 years ago smush 2 years ago stats 2 years ago webp 2 years ago class-animated-status-controller.php 2 years ago class-array-utils.php 2 years ago class-attachment-id-list.php 2 years ago class-backup-size.php 2 years ago class-cli.php 2 years ago class-configs.php 2 years ago class-controller.php 2 years ago class-core.php 2 years ago class-deprecated-hooks.php 2 years ago class-error-handler.php 2 years ago class-file-system.php 2 years ago class-helper.php 2 years ago class-installer.php 2 years ago class-modules.php 2 years ago class-optimization-controller.php 2 years ago class-plugin-settings-watcher.php 2 years ago class-rest.php 2 years ago class-server-utils.php 2 years ago class-settings.php 2 years ago class-smush-file.php 2 years ago class-stats.php 2 years ago class-upload-dir.php 2 years ago
class-deprecated-hooks.php
148 lines
1 <?php
2 /**
3 * Deprecated hooks.
4 * It's created based on WC_Deprecated_Hooks.
5 *
6 * @since 3.9.6
7 * @package Deprecated_Hooks
8 */
9
10 namespace Smush\Core;
11
12 defined( 'ABSPATH' ) || exit;
13
14 /**
15 * Handles deprecation notices and triggering of legacy action hooks.
16 */
17 class Deprecated_Hooks {
18
19 /**
20 * Array of deprecated actions hooks we need to handle. Format of 'new' => 'old'.
21 *
22 * @var array
23 */
24 private $deprecated_action_hooks = array(
25 'wp_smush_before_smush_file' => 'smush_s3_integration_fetch_file',
26 'wp_smush_after_remove_file' => 'smush_s3_backup_remove',
27 );
28
29 /**
30 * Array of deprecated filters hooks we need to handle. Format of 'new' => 'old'.
31 *
32 * @var array
33 */
34 private $deprecated_filter_hooks = array(
35 'wp_smush_backup_exists' => 'smush_backup_exists',
36 'wp_smush_file_exists' => 'smush_file_exists',
37 );
38
39 /**
40 * Array of versions on each hook has been deprecated.
41 *
42 * @var array
43 */
44 private $deprecated_version = array(
45 'smush_backup_exists' => '3.9.6',
46 'smush_s3_integration_fetch_file' => '3.9.6',
47 'smush_s3_backup_remove' => '3.9.6',
48 'smush_file_exists' => '3.9.6',
49 );
50
51 /**
52 * Is action hook.
53 *
54 * @var bool
55 */
56 private $is_action;
57
58 /**
59 * Constructor.
60 *
61 * Hook into the new hook so we can handle deprecated hooks once fired.
62 */
63 public function __construct() {
64 $deprecated_hooks = array_merge( array_keys( $this->deprecated_action_hooks ), array_keys( $this->deprecated_filter_hooks ) );
65 if ( $deprecated_hooks ) {
66 foreach ( $deprecated_hooks as $new_action ) {
67 add_filter( $new_action, array( $this, 'maybe_handle_deprecated_hook' ), -1000, 8 );
68 }
69 }
70 }
71
72 /**
73 * Get old hooks to map to new hook.
74 *
75 * @param string $new_hook New hook name.
76 * @return array
77 */
78 private function get_old_hooks( $new_hook ) {
79 $old_hooks = array();
80 if ( isset( $this->deprecated_action_hooks[ $new_hook ] ) ) {
81 $old_hooks = $this->deprecated_action_hooks[ $new_hook ];
82
83 $this->is_action = true;
84 } elseif ( isset( $this->deprecated_filter_hooks[ $new_hook ] ) ) {
85 $old_hooks = $this->deprecated_filter_hooks[ $new_hook ];
86 // reset hook type.
87 $this->is_action = null;
88 }
89
90 return is_array( $old_hooks ) ? $old_hooks : array( $old_hooks );
91 }
92
93 /**
94 * If the hook is Deprecated, call the old hooks here.
95 */
96 public function maybe_handle_deprecated_hook() {
97 $new_hook = current_filter();
98 $new_callback_args = func_get_args();
99 $return_value = $new_callback_args[0];
100 $old_hooks = $this->get_old_hooks( $new_hook );
101 if ( $old_hooks ) {
102 foreach ( $old_hooks as $old_hook ) {
103 if ( has_filter( $old_hook ) ) {
104 $this->display_notice( $old_hook, $new_hook );
105 $return_value = $this->trigger_hook( $old_hook, $new_callback_args );
106 }
107 }
108 }
109
110 return $return_value;
111 }
112
113 /**
114 * Display a deprecated notice for old hooks.
115 *
116 * @param string $old_hook Old hook.
117 * @param string $new_hook New hook.
118 */
119 protected function display_notice( $old_hook, $new_hook ) {
120 _deprecated_hook( esc_html( $old_hook ), esc_html( $this->get_deprecated_version( $old_hook ) ), esc_html( $new_hook ) );
121 }
122
123 /**
124 * Fire off a legacy hook with it's args.
125 *
126 * @param string $old_hook Old hook name.
127 * @param array $new_callback_args New callback args.
128 * @return mixed|void
129 */
130 protected function trigger_hook( $old_hook, $new_callback_args ) {
131 if ( $this->is_action ) {
132 do_action_ref_array( $old_hook, $new_callback_args );
133 } else {
134 return apply_filters_ref_array( $old_hook, $new_callback_args );
135 }
136 }
137
138 /**
139 * Get deprecated version.
140 *
141 * @param string $old_hook Old hook name.
142 * @return string
143 */
144 protected function get_deprecated_version( $old_hook ) {
145 return ! empty( $this->deprecated_version[ $old_hook ] ) ? $this->deprecated_version[ $old_hook ] : WP_SMUSH_VERSION;
146 }
147 }
148