PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / trunk
MainWP Dashboard: Self-hosted WordPress Management for Agencies vtrunk
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-deprecated-hooks.php

class-mainwp-deprecated-hooks.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies trunk, at class/class-mainwp-deprecated-hooks.php

181 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Deprecated Hooks
4 *
5 * Init mainwp deprecated hooks
6 *
7 * @package MainWP/Dashboard
8 */
9
10 namespace MainWP\Dashboard;
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Class MainWP_Deprecated_Hooks
19 *
20 * @package MainWP\Dashboard
21 */
22 class MainWP_Deprecated_Hooks { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
23
24 /**
25 * Protected static variable to hold the single instance of the class.
26 *
27 * @static
28 *
29 * @var mixed Default null
30 */
31 protected static $instance = null;
32
33 /**
34 * Array of deprecated filters. Format of 'old' => 'new'.
35 *
36 * @var array
37 */
38 public $deprecated_filters = array(
39 'mainwp-getsites' => 'mainwp_getsites',
40 'mainwp-getdbsites' => 'mainwp_getdbsites',
41 'mainwp-getgroups' => 'mainwp_getgroups',
42 'mainwp-activated-check' => 'mainwp_activated_check',
43 'mainwp-extension-available-check' => '',
44 'mainwp-manager-getextensions' => 'mainwp_manager_getextensions',
45 'mainwp-extension-enabled-check' => 'mainwp_extension_enabled_check',
46 );
47
48 /**
49 * Array of deprecated actions. Format of 'old' => 'new'.
50 *
51 * @var array
52 */
53 public $deprecated_actions = array(
54 'mainwp_activate_extention' => 'mainwp_activate_extension',
55 'mainwp_deactivate_extention' => 'mainwp_deactivate_extension',
56 'mainwp-pageheader-sites' => 'mainwp_pageheader_sites',
57 'mainwp-pagefooter-sites' => 'mainwp_pagefooter_sites',
58 'mainwp-pageheader-extensions' => 'mainwp_pageheader_extensions',
59 'mainwp-pagefooter-extensions' => 'mainwp_pagefooter_extensions',
60 );
61
62 /**
63 * Array of versions of deprecated hooks.
64 *
65 * @var array
66 */
67 public $deprecated_version = array(
68 'mainwp-getsites' => '4.1',
69 'mainwp-getdbsites' => '4.1',
70 'mainwp-activated' => '4.1',
71 'mainwp-activated-check' => '4.1',
72 'mainwp-extension-available-check' => '4.1',
73 'mainwp-getgroups' => '4.1',
74 'mainwp-manager-getextensions' => '4.1',
75 'mainwp_activate_extention' => '4.1',
76 'mainwp_deactivate_extention' => '4.1',
77 'mainwp-extension-enabled-check' => '4.1',
78 'mainwp-pageheader-sites' => '4.1',
79 'mainwp-pagefooter-sites' => '4.1',
80 'mainwp-pageheader-extensions' => '4.1',
81 'mainwp-pagefooter-extensions' => '4.1',
82 'mainwp-pageheader-post' => '4.1.5.1', // NOSONAR - no IP.
83 'mainwp-pagefooter-post' => '4.1.5.1', // NOSONAR - no IP.
84 'mainwp-pageheader-page' => '4.1.5.1', // NOSONAR - no IP.
85 );
86
87 /**
88 * Method instance()
89 *
90 * @static
91 * @return class instance
92 */
93 public static function instance() {
94 if ( is_null( static::$instance ) ) {
95 static::$instance = new self();
96 }
97
98 return static::$instance;
99 }
100
101 /**
102 * MainWP_Deprecated_Hooks constructor.
103 *
104 * Run each time the class is called.
105 */
106 public function __construct() {
107 }
108
109 /**
110 * Method get_class_name()
111 *
112 * Get Class Name.
113 *
114 * @return object
115 */
116 public static function get_class_name() {
117 return __CLASS__;
118 }
119
120 /**
121 * Get old hooks to map to replacement hook.
122 *
123 * @param string $old_hook Old hook name.
124 * @return array
125 */
126 public function get_replacement_hooks( $old_hook ) {
127 if ( isset( $this->deprecated_filters[ $old_hook ] ) ) {
128 return $this->deprecated_filters[ $old_hook ];
129 }
130 if ( isset( $this->deprecated_actions[ $old_hook ] ) ) {
131 return $this->deprecated_actions[ $old_hook ];
132 }
133 return false;
134 }
135
136 /**
137 * Get deprecated version.
138 *
139 * @param string $old_hook Old hook name.
140 * @return string
141 */
142 protected function get_deprecated_version( $old_hook ) {
143 return ! empty( $this->deprecated_version[ $old_hook ] ) ? $this->deprecated_version[ $old_hook ] : MAINWP_VERSION;
144 }
145
146 /**
147 * If the filter is Deprecated, display a deprecated notice.
148 */
149 public static function maybe_handle_deprecated_hook() {
150 $current_hook = current_filter();
151 $new_hook = static::instance()->get_replacement_hooks( $current_hook );
152 if ( false !== $new_hook ) {
153 static::instance()->deprecated_message( $current_hook, $new_hook );
154 }
155 }
156
157 /**
158 * Display a deprecated notice for old hooks.
159 *
160 * @param string $old_hook Old hook.
161 * @param string $new_hook New hook.
162 * @param string $message message.
163 */
164 public function deprecated_message( $old_hook, $new_hook, $message = null ) {
165 $version = esc_html( $this->get_deprecated_version( $old_hook ) );
166
167 $is_ajax = function_exists( 'wp_doing_ajax' ) ? wp_doing_ajax() : defined( 'DOING_AJAX' );
168
169 // @codingStandardsIgnoreStart
170 if ( $is_ajax ) {
171 do_action( 'deprecated_hook_run', $old_hook, $new_hook, $version, $message );
172 $log_string = "{$old_hook} is deprecated since version {$version}";
173 $log_string .= $new_hook ? "! Use {$new_hook} instead." : ' with no alternative available.';
174 error_log( $log_string );
175 } else {
176 _deprecated_hook( $old_hook, $version, $new_hook, $message );
177 }
178 // @codingStandardsIgnoreEnd
179 }
180 }
181