| @@ -8,168 +8,173 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | 10 | namespace MainWP\Dashboard; |
| 11 | 11 | |
| 12 | +// Exit if accessed directly. | |
| 13 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 14 | + exit; | |
| 15 | +} | |
| 16 | + | |
| 12 | 17 | /** |
| 13 | 18 | * Class MainWP_Deprecated_Hooks |
| 14 | 19 | * |
| 15 | 20 | * @package MainWP\Dashboard |
| 16 | 21 | */ |
| 17 | -class MainWP_Deprecated_Hooks { | |
| 22 | +class MainWP_Deprecated_Hooks { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. | |
| 18 | 23 | |
| 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; | |
| 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; | |
| 27 | 32 | |
| 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 | - ); | |
| 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 | + ); | |
| 42 | 47 | |
| 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 | - ); | |
| 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 | + ); | |
| 56 | 61 | |
| 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 | - ); | |
| 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 | + ); | |
| 81 | 86 | |
| 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 | - } | |
| 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 | + } | |
| 92 | 97 | |
| 93 | - return self::$instance; | |
| 94 | - } | |
| 98 | + return static::$instance; | |
| 99 | + } | |
| 95 | 100 | |
| 96 | - /** | |
| 97 | - * MainWP_Deprecated_Hooks constructor. | |
| 98 | - * | |
| 99 | - * Run each time the class is called. | |
| 100 | - */ | |
| 101 | - public function __construct() { | |
| 102 | - } | |
| 101 | + /** | |
| 102 | + * MainWP_Deprecated_Hooks constructor. | |
| 103 | + * | |
| 104 | + * Run each time the class is called. | |
| 105 | + */ | |
| 106 | + public function __construct() { | |
| 107 | + } | |
| 103 | 108 | |
| 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 | - } | |
| 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 | + } | |
| 114 | 119 | |
| 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 | - } | |
| 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 | + } | |
| 130 | 135 | |
| 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 | - } | |
| 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 | + } | |
| 140 | 145 | |
| 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 | - } | |
| 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 | + } | |
| 151 | 156 | |
| 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 ) ); | |
| 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 ) ); | |
| 161 | 166 | |
| 162 | - $is_ajax = function_exists( 'wp_doing_ajax' ) ? wp_doing_ajax() : defined( 'DOING_AJAX' ); | |
| 167 | + $is_ajax = function_exists( 'wp_doing_ajax' ) ? wp_doing_ajax() : defined( 'DOING_AJAX' ); | |
| 163 | 168 | |
| 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 | - } | |
| 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 | + } | |
| 175 | 180 | } |