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