| @@ -1,59 +1,213 @@ | ||
| 1 | 1 | <?php |
| 2 | -/* | |
| 3 | -Plugin Name: Multi Device Switcher | |
| 4 | -Plugin URI: https://github.com/thingsym/multi-device-switcher | |
| 5 | -Description: This WordPress plugin allows you to set a separate theme for device (Smart Phone, Tablet PC, Mobile Phone, Game and custom). | |
| 6 | -Version: 1.4.0 | |
| 7 | -Author: thingsym | |
| 8 | -Author URI: http://www.thingslabo.com/ | |
| 9 | -License: GPL2 | |
| 10 | -Text Domain: multi-device-switcher | |
| 11 | -Domain Path: /languages/ | |
| 12 | -*/ | |
| 2 | +/** | |
| 3 | + * Plugin Name: Multi Device Switcher | |
| 4 | + * Plugin URI: https://github.com/thingsym/multi-device-switcher | |
| 5 | + * Description: This WordPress plugin allows you to set a separate theme for device (Smart Phone, Tablet PC, Mobile Phone, Game and custom). | |
| 6 | + * Version: 1.8.7 | |
| 7 | + * Author: thingsym | |
| 8 | + * Author URI: https://www.thingslabo.com/ | |
| 9 | + * License: GPLv2 or later | |
| 10 | + * License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
| 11 | + * Text Domain: multi-device-switcher | |
| 12 | + * Domain Path: /languages/ | |
| 13 | + * | |
| 14 | + * @package Multi_Device_Switcher | |
| 15 | + */ | |
| 13 | 16 | |
| 14 | -/* | |
| 15 | - Copyright 2012 thingsym (http://www.thingslabo.com/) | |
| 17 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 18 | + exit; | |
| 19 | +} | |
| 16 | 20 | |
| 17 | - This program is free software; you can redistribute it and/or modify | |
| 18 | - it under the terms of the GNU General Public License as published by | |
| 19 | - the Free Software Foundation; either version 2 of the License, or | |
| 20 | - (at your option) any later version. | |
| 21 | +/** | |
| 22 | + * Core class Multi_Device_Switcher | |
| 23 | + * | |
| 24 | + * @since 1.0.0 | |
| 25 | + */ | |
| 26 | +class Multi_Device_Switcher { | |
| 21 | 27 | |
| 22 | - This program is distributed in the hope that it will be useful, | |
| 23 | - but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 24 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 25 | - GNU General Public License for more details. | |
| 28 | + /** | |
| 29 | + * Public variable. | |
| 30 | + * | |
| 31 | + * @access public | |
| 32 | + * | |
| 33 | + * @var string $option_group The group name of option | |
| 34 | + */ | |
| 35 | + public $option_group = 'multi_device_switcher'; | |
| 26 | 36 | |
| 27 | - You should have received a copy of the GNU General Public License | |
| 28 | - along with this program; if not, write to the Free Software | |
| 29 | - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA | |
| 30 | -*/ | |
| 37 | + /** | |
| 38 | + * Public variable. | |
| 39 | + * | |
| 40 | + * @access public | |
| 41 | + * | |
| 42 | + * @var string $option_name The option name | |
| 43 | + */ | |
| 44 | + public $option_name = 'multi_device_switcher_options'; | |
| 31 | 45 | |
| 32 | -class Multi_Device_Switcher { | |
| 46 | + /** | |
| 47 | + * Public variable. | |
| 48 | + * | |
| 49 | + * @access public | |
| 50 | + * | |
| 51 | + * @var string $capability The types of capability | |
| 52 | + */ | |
| 53 | + public $capability = 'switch_themes'; | |
| 33 | 54 | |
| 55 | + /** | |
| 56 | + * Public variable. | |
| 57 | + * | |
| 58 | + * @access public | |
| 59 | + * | |
| 60 | + * @var string $cookie_name_multi_device_switcher | |
| 61 | + */ | |
| 62 | + public $cookie_name_multi_device_switcher = 'multi-device-switcher'; | |
| 63 | + | |
| 64 | + /** | |
| 65 | + * Public variable. | |
| 66 | + * | |
| 67 | + * @access public | |
| 68 | + * | |
| 69 | + * @var string $cookie_name_disable_switcher | |
| 70 | + */ | |
| 71 | + public $cookie_name_disable_switcher = 'disable-switcher'; | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * Public variable. | |
| 75 | + * | |
| 76 | + * @access public | |
| 77 | + * | |
| 78 | + * @var string $cookie_name_pc_switcher | |
| 79 | + */ | |
| 80 | + public $cookie_name_pc_switcher = 'pc-switcher'; | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * Public variable. | |
| 84 | + * | |
| 85 | + * @access public | |
| 86 | + * | |
| 87 | + * @var array $default_options { | |
| 88 | + * default options | |
| 89 | + * | |
| 90 | + * @type bool pc_switcher | |
| 91 | + * @type bool default_css | |
| 92 | + * @type string theme_smartphone | |
| 93 | + * @type string theme_tablet | |
| 94 | + * @type string theme_mobile | |
| 95 | + * @type string theme_game | |
| 96 | + * @type string userAgent_smart | |
| 97 | + * @type string userAgent_tablet | |
| 98 | + * @type string userAgent_mobile | |
| 99 | + * @type string userAgent_game | |
| 100 | + * @type string disable_path | |
| 101 | + * @type bool enable_regex | |
| 102 | + * } | |
| 103 | + * | |
| 104 | + * @since 1.7.0 | |
| 105 | + */ | |
| 106 | + public $default_options = array( | |
| 107 | + 'pc_switcher' => 1, | |
| 108 | + 'default_css' => 1, | |
| 109 | + 'theme_smartphone' => 'None', | |
| 110 | + 'theme_tablet' => 'None', | |
| 111 | + 'theme_mobile' => 'None', | |
| 112 | + 'theme_game' => 'None', | |
| 113 | + 'userAgent_smart' => 'iPhone, iPod, Android.*Mobile, dream, CUPCAKE, Windows Phone, IEMobile.*Touch, webOS, BB10.*Mobile, BlackBerry.*Mobile, Mobile.*Gecko', | |
| 114 | + 'userAgent_tablet' => 'iPad, Kindle, Silk, Android(?!.*Mobile), Windows.*Touch, PlayBook, Tablet.*Gecko', | |
| 115 | + 'userAgent_mobile' => 'DoCoMo, SoftBank, J-PHONE, Vodafone, KDDI, UP.Browser, WILLCOM, emobile, DDIPOCKET, Windows CE, BlackBerry, Symbian, PalmOS, Huawei, IAC, Nokia', | |
| 116 | + 'userAgent_game' => 'PSP, PS2, PLAYSTATION 3, PlayStation (Portable|Vita|4|5), Nitro, Nintendo (3DS|Wii|WiiU|Switch), Xbox', | |
| 117 | + 'disable_path' => '', | |
| 118 | + 'enable_regex' => 0, | |
| 119 | + ); | |
| 120 | + | |
| 121 | + /** | |
| 122 | + * Public variable. | |
| 123 | + * | |
| 124 | + * @access public | |
| 125 | + * | |
| 126 | + * @var string $device | |
| 127 | + */ | |
| 128 | + public $device = ''; | |
| 129 | + | |
| 130 | + /** | |
| 131 | + * Public variable. | |
| 132 | + * | |
| 133 | + * @access public | |
| 134 | + * | |
| 135 | + * @var array|null $plugin_data | |
| 136 | + */ | |
| 137 | + public $plugin_data = array(); | |
| 138 | + | |
| 139 | + /** | |
| 140 | + * Constructor | |
| 141 | + * | |
| 142 | + * @access public | |
| 143 | + * | |
| 144 | + * @since 1.0.0 | |
| 145 | + */ | |
| 34 | 146 | public function __construct() { |
| 35 | - $this->device = ''; | |
| 147 | + add_action( 'init', array( $this, 'load_plugin_data' ) ); | |
| 148 | + add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); | |
| 149 | + add_action( 'plugins_loaded', array( $this, 'init' ) ); | |
| 36 | 150 | |
| 37 | - if ( isset( $_COOKIE['disable-switcher'] ) ) { | |
| 38 | - setcookie( 'disable-switcher', null, time() - 3600, '/' ); | |
| 151 | + if ( ! is_admin() ) { | |
| 152 | + add_filter( 'wp_headers', array( $this, 'add_header_vary' ) ); | |
| 153 | + add_action( 'plugins_loaded', array( $this, 'detect_device' ) ); | |
| 154 | + add_action( 'plugins_loaded', array( $this, 'switch_theme' ) ); | |
| 39 | 155 | } |
| 40 | 156 | |
| 41 | - if ( $this->get_disable() ) { | |
| 42 | - setcookie( 'disable-switcher', 1, null, '/' ); | |
| 157 | + add_action( 'admin_init', array( $this, 'register_settings' ) ); | |
| 158 | + add_action( 'admin_menu', array( $this, 'add_option_page' ) ); | |
| 159 | + add_action( 'customize_register', array( $this, 'customizer' ) ); | |
| 160 | + add_action( 'plugins_loaded', array( $this, 'load_file' ) ); | |
| 161 | + } | |
| 162 | + | |
| 163 | + /** | |
| 164 | + * Initialize. | |
| 165 | + * | |
| 166 | + * Hooks to plugins_loaded | |
| 167 | + * | |
| 168 | + * @access public | |
| 169 | + * | |
| 170 | + * @since 1.6.0 | |
| 171 | + */ | |
| 172 | + public function init() { | |
| 173 | + add_filter( 'option_page_capability_' . $this->option_group, array( $this, 'option_page_capability' ) ); | |
| 174 | + add_filter( 'plugin_action_links_' . plugin_basename( __MULTI_DEVICE_SWITCHER_FILE__ ), array( $this, 'plugin_action_links' ) ); | |
| 175 | + add_filter( 'plugin_row_meta', array( $this, 'plugin_metadata_links' ), 10, 2 ); | |
| 176 | + | |
| 177 | + add_shortcode( 'multi', array( $this, 'shortcode_display_switcher' ) ); | |
| 178 | + } | |
| 179 | + | |
| 180 | + /** | |
| 181 | + * Detect device. | |
| 182 | + * | |
| 183 | + * @access public | |
| 184 | + * | |
| 185 | + * @return void | |
| 186 | + * | |
| 187 | + * @since 1.7.0 | |
| 188 | + */ | |
| 189 | + public function detect_device() { | |
| 190 | + if ( isset( $_COOKIE[ $this->cookie_name_disable_switcher ] ) ) { | |
| 191 | + add_action( 'wp_headers', array( $this, 'set_cookie_rest_disable_switcher' ) ); | |
| 192 | + } | |
| 193 | + | |
| 194 | + if ( $this->is_disable_switcher() ) { | |
| 195 | + add_action( 'wp_headers', array( $this, 'set_cookie_enable_disable_switcher' ) ); | |
| 43 | 196 | return; |
| 44 | 197 | } |
| 45 | 198 | |
| 46 | - add_action( 'init', array( &$this, 'session' ) ); | |
| 199 | + add_action( 'init', array( $this, 'session' ) ); | |
| 47 | 200 | |
| 48 | - $userAgent = $this->get_options_userAgent(); | |
| 49 | - $server_ua = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : ''; | |
| 201 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 202 | + $server_ua = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : ''; | |
| 203 | + $user_agent = $this->get_options_user_agent(); | |
| 50 | 204 | |
| 51 | - foreach ( array_reverse( $userAgent ) as $key => $val ) { | |
| 205 | + foreach ( array_reverse( $user_agent ) as $key => $val ) { | |
| 52 | 206 | if ( ! preg_match( '/^custom_switcher_/', $key ) ) { |
| 53 | 207 | continue; |
| 54 | 208 | } |
| 55 | - if ( $userAgent[ $key ] && preg_match( '/' . implode( '|', $userAgent[ $key ] ) . '/i', $server_ua ) ) { | |
| 209 | + if ( $user_agent[ $key ] && preg_match( '/' . implode( '|', $user_agent[ $key ] ) . '/i', $server_ua ) ) { | |
| 56 | 210 | $this->device = $key; |
| 57 | 211 | break; |
| 58 | 212 | } |
| 59 | 213 | } |
| @@ -58,60 +212,97 @@ | ||
| 58 | 212 | } |
| 59 | 213 | } |
| 60 | 214 | |
| 61 | 215 | if ( ! $this->device ) { |
| 62 | - if ( $userAgent['game'] && preg_match( '/' . implode( '|', $userAgent['game'] ) . '/i', $server_ua ) ) { | |
| 216 | + if ( $user_agent['game'] && preg_match( '/' . implode( '|', $user_agent['game'] ) . '/i', $server_ua ) ) { | |
| 63 | 217 | $this->device = 'game'; |
| 64 | 218 | } |
| 65 | - elseif ( $userAgent['tablet'] && preg_match( '/' . implode( '|', $userAgent['tablet'] ) . '/i', $server_ua ) ) { | |
| 219 | + elseif ( $user_agent['tablet'] && preg_match( '/' . implode( '|', $user_agent['tablet'] ) . '/i', $server_ua ) ) { | |
| 66 | 220 | $this->device = 'tablet'; |
| 67 | 221 | } |
| 68 | - elseif ( $userAgent['smart'] && preg_match( '/' . implode( '|', $userAgent['smart'] ) . '/i', $server_ua ) ) { | |
| 222 | + elseif ( $user_agent['smart'] && preg_match( '/' . implode( '|', $user_agent['smart'] ) . '/i', $server_ua ) ) { | |
| 69 | 223 | $this->device = 'smart'; |
| 70 | 224 | } |
| 71 | - elseif ( $userAgent['mobile'] && preg_match( '/' . implode( '|', $userAgent['mobile'] ) . '/i', $server_ua ) ) { | |
| 225 | + elseif ( $user_agent['mobile'] && preg_match( '/' . implode( '|', $user_agent['mobile'] ) . '/i', $server_ua ) ) { | |
| 72 | 226 | $this->device = 'mobile'; |
| 73 | 227 | } |
| 74 | 228 | } |
| 75 | 229 | |
| 230 | + /** | |
| 231 | + * Action hook: multi_device_switcher/detect_device. | |
| 232 | + * | |
| 233 | + * @since 1.7.0 | |
| 234 | + */ | |
| 235 | + do_action( 'multi_device_switcher/detect_device' ); | |
| 236 | + } | |
| 237 | + | |
| 238 | + /** | |
| 239 | + * Switch theme. | |
| 240 | + * | |
| 241 | + * @access public | |
| 242 | + * | |
| 243 | + * @return void | |
| 244 | + * | |
| 245 | + * @since 1.0.0 | |
| 246 | + */ | |
| 247 | + public function switch_theme() { | |
| 76 | 248 | if ( $this->device ) { |
| 77 | - load_plugin_textdomain( 'multi-device-switcher', false, 'multi-device-switcher/languages' ); | |
| 78 | - add_filter( 'stylesheet', array( &$this, 'get_stylesheet' ) ); | |
| 79 | - add_filter( 'template', array( &$this, 'get_template' ) ); | |
| 80 | - add_action( 'wp_footer', array( &$this, 'add_pc_switcher' ) ); | |
| 81 | - | |
| 82 | - setcookie( 'multi-device-switcher', preg_replace( '/^custom_switcher_/', '', $this->device ), null, '/' ); | |
| 249 | + add_filter( 'stylesheet', array( $this, 'get_stylesheet' ) ); | |
| 250 | + add_filter( 'template', array( $this, 'get_template' ) ); | |
| 251 | + add_action( 'wp_footer', array( $this, 'add_pc_switcher' ) ); | |
| 252 | + add_action( 'wp_headers', array( $this, 'set_cookie_switch_theme' ) ); | |
| 83 | 253 | } |
| 84 | 254 | else { |
| 85 | - setcookie( 'multi-device-switcher', null, time() - 3600, '/' ); | |
| 255 | + add_action( 'wp_headers', array( $this, 'set_cookie_normal_theme' ) ); | |
| 86 | 256 | } |
| 87 | 257 | |
| 88 | - if ( isset( $_COOKIE['pc-switcher'] ) ) { | |
| 89 | - remove_filter( 'stylesheet', array( &$this, 'get_stylesheet' ) ); | |
| 90 | - remove_filter( 'template', array( &$this, 'get_template' ) ); | |
| 258 | + if ( isset( $_COOKIE[ $this->cookie_name_pc_switcher ] ) ) { | |
| 259 | + remove_filter( 'stylesheet', array( $this, 'get_stylesheet' ) ); | |
| 260 | + remove_filter( 'template', array( $this, 'get_template' ) ); | |
| 91 | 261 | } |
| 92 | 262 | } |
| 93 | 263 | |
| 94 | - public function get_options_userAgent() { | |
| 95 | - $options = multi_device_switcher_get_options(); | |
| 264 | + /** | |
| 265 | + * Gets UserAgents. | |
| 266 | + * | |
| 267 | + * @access public | |
| 268 | + * | |
| 269 | + * @return array | |
| 270 | + * | |
| 271 | + * @since 1.0.0 | |
| 272 | + */ | |
| 273 | + public function get_options_user_agent() { | |
| 274 | + $options = $this->get_options(); | |
| 96 | 275 | |
| 97 | - $userAgent['smart'] = empty( $options['userAgent_smart'] ) ? '' : preg_split( '/,\s*/', $options['userAgent_smart'] ); | |
| 98 | - $userAgent['tablet'] = empty( $options['userAgent_tablet'] ) ? '' : preg_split( '/,\s*/', $options['userAgent_tablet'] ); | |
| 99 | - $userAgent['mobile'] = empty( $options['userAgent_mobile'] ) ? '' : preg_split( '/,\s*/', $options['userAgent_mobile'] ); | |
| 100 | - $userAgent['game'] = empty( $options['userAgent_game'] ) ? '' : preg_split( '/,\s*/', $options['userAgent_game'] ); | |
| 276 | + $user_agent['smart'] = empty( $options['userAgent_smart'] ) ? '' : preg_split( '/,\s*/', $options['userAgent_smart'], -1, PREG_SPLIT_NO_EMPTY ); | |
| 277 | + $user_agent['tablet'] = empty( $options['userAgent_tablet'] ) ? '' : preg_split( '/,\s*/', $options['userAgent_tablet'], -1, PREG_SPLIT_NO_EMPTY ); | |
| 278 | + $user_agent['mobile'] = empty( $options['userAgent_mobile'] ) ? '' : preg_split( '/,\s*/', $options['userAgent_mobile'], -1, PREG_SPLIT_NO_EMPTY ); | |
| 279 | + $user_agent['game'] = empty( $options['userAgent_game'] ) ? '' : preg_split( '/,\s*/', $options['userAgent_game'], -1, PREG_SPLIT_NO_EMPTY ); | |
| 101 | 280 | |
| 102 | - foreach ( $options as $key => $val ) { | |
| 281 | + foreach ( (array) $options as $key => $val ) { | |
| 103 | 282 | if ( ! preg_match( '/^custom_switcher_userAgent_/', $key ) ) { |
| 104 | 283 | continue; |
| 105 | 284 | } |
| 106 | 285 | |
| 107 | 286 | $custom_switcher_name = preg_replace( '/^custom_switcher_userAgent_/', '', $key ); |
| 108 | - $userAgent[ 'custom_switcher_' . $custom_switcher_name ] = empty( $val ) ? '' : preg_split( '/,\s*/', $val ); | |
| 287 | + | |
| 288 | + $user_agent[ 'custom_switcher_' . $custom_switcher_name ] = empty( $val ) ? '' : preg_split( '/,\s*/', $val, -1, PREG_SPLIT_NO_EMPTY ); | |
| 109 | 289 | } |
| 110 | 290 | |
| 111 | - return $userAgent; | |
| 291 | + return $user_agent; | |
| 112 | 292 | } |
| 113 | 293 | |
| 294 | + /** | |
| 295 | + * Gets stylesheet. | |
| 296 | + * | |
| 297 | + * @access public | |
| 298 | + * | |
| 299 | + * @param string $stylesheet | |
| 300 | + * | |
| 301 | + * @return string | |
| 302 | + * | |
| 303 | + * @since 1.0.0 | |
| 304 | + */ | |
| 114 | 305 | public function get_stylesheet( $stylesheet = '' ) { |
| 115 | 306 | $name = $this->get_device_theme(); |
| 116 | 307 | |
| 117 | 308 | if ( empty( $name ) ) { |
| @@ -119,9 +310,9 @@ | ||
| 119 | 310 | } |
| 120 | 311 | |
| 121 | 312 | $themes = wp_get_themes(); |
| 122 | 313 | foreach ( $themes as $t ) { |
| 123 | - if ( $name == $t->get( 'Name' ) ) { | |
| 314 | + if ( $name === $t->get( 'Name' ) ) { | |
| 124 | 315 | $theme = $t; |
| 125 | 316 | break; |
| 126 | 317 | } |
| 127 | 318 | } |
| @@ -129,9 +320,9 @@ | ||
| 129 | 320 | if ( empty( $theme ) ) { |
| 130 | 321 | return $stylesheet; |
| 131 | 322 | } |
| 132 | 323 | |
| 133 | - if ( 'publish' != $theme->get( 'Status' ) ) { | |
| 324 | + if ( 'publish' !== $theme->get( 'Status' ) ) { | |
| 134 | 325 | return $stylesheet; |
| 135 | 326 | } |
| 136 | 327 | |
| 137 | 328 | return $theme['Stylesheet']; |
| @@ -136,8 +327,19 @@ | ||
| 136 | 327 | |
| 137 | 328 | return $theme['Stylesheet']; |
| 138 | 329 | } |
| 139 | 330 | |
| 331 | + /** | |
| 332 | + * Gets template. | |
| 333 | + * | |
| 334 | + * @access public | |
| 335 | + * | |
| 336 | + * @param string $template | |
| 337 | + * | |
| 338 | + * @return string | |
| 339 | + * | |
| 340 | + * @since 1.0.0 | |
| 341 | + */ | |
| 140 | 342 | public function get_template( $template = '' ) { |
| 141 | 343 | $name = $this->get_device_theme(); |
| 142 | 344 | |
| 143 | 345 | if ( empty( $name ) ) { |
| @@ -145,9 +347,9 @@ | ||
| 145 | 347 | } |
| 146 | 348 | |
| 147 | 349 | $themes = wp_get_themes(); |
| 148 | 350 | foreach ( $themes as $t ) { |
| 149 | - if ( $name == $t->get( 'Name' ) ) { | |
| 351 | + if ( $name === $t->get( 'Name' ) ) { | |
| 150 | 352 | $theme = $t; |
| 151 | 353 | break; |
| 152 | 354 | } |
| 153 | 355 | } |
| @@ -155,9 +357,9 @@ | ||
| 155 | 357 | if ( empty( $theme ) ) { |
| 156 | 358 | return $template; |
| 157 | 359 | } |
| 158 | 360 | |
| 159 | - if ( 'publish' != $theme->get( 'Status' ) ) { | |
| 361 | + if ( 'publish' !== $theme->get( 'Status' ) ) { | |
| 160 | 362 | return $template; |
| 161 | 363 | } |
| 162 | 364 | |
| 163 | 365 | return $theme['Template']; |
| @@ -162,25 +364,34 @@ | ||
| 162 | 364 | |
| 163 | 365 | return $theme['Template']; |
| 164 | 366 | } |
| 165 | 367 | |
| 368 | + /** | |
| 369 | + * Gets template by device. | |
| 370 | + * | |
| 371 | + * @access public | |
| 372 | + * | |
| 373 | + * @return string | |
| 374 | + * | |
| 375 | + * @since 1.0.0 | |
| 376 | + */ | |
| 166 | 377 | public function get_device_theme() { |
| 167 | - $options = multi_device_switcher_get_options(); | |
| 378 | + $options = $this->get_options(); | |
| 168 | 379 | |
| 169 | - if ( 'smart' == $this->device ) { | |
| 380 | + if ( 'smart' === $this->device ) { | |
| 170 | 381 | return $options['theme_smartphone']; |
| 171 | 382 | } |
| 172 | - elseif ( 'tablet' == $this->device ) { | |
| 383 | + elseif ( 'tablet' === $this->device ) { | |
| 173 | 384 | return $options['theme_tablet']; |
| 174 | 385 | } |
| 175 | - elseif ( 'mobile' == $this->device ) { | |
| 386 | + elseif ( 'mobile' === $this->device ) { | |
| 176 | 387 | return $options['theme_mobile']; |
| 177 | 388 | } |
| 178 | - elseif ( 'game' == $this->device ) { | |
| 389 | + elseif ( 'game' === $this->device ) { | |
| 179 | 390 | return $options['theme_game']; |
| 180 | 391 | } |
| 181 | 392 | else { |
| 182 | - foreach ( $options as $key => $val ) { | |
| 393 | + foreach ( (array) $options as $key => $val ) { | |
| 183 | 394 | if ( ! preg_match( '/^custom_switcher_theme_/', $key ) ) { |
| 184 | 395 | continue; |
| 185 | 396 | } |
| 186 | 397 | |
| @@ -185,861 +396,1176 @@ | ||
| 185 | 396 | } |
| 186 | 397 | |
| 187 | 398 | $custom_switcher_name = preg_replace( '/^custom_switcher_theme_/', '', $key ); |
| 188 | 399 | |
| 189 | - if ( 'custom_switcher_' . $custom_switcher_name == $this->device ) { | |
| 400 | + if ( 'custom_switcher_' . $custom_switcher_name === $this->device ) { | |
| 190 | 401 | return $options[ $key ]; |
| 191 | 402 | } |
| 192 | 403 | } |
| 193 | 404 | } |
| 194 | 405 | |
| 195 | - return; | |
| 406 | + return ''; | |
| 196 | 407 | } |
| 197 | 408 | |
| 409 | + /** | |
| 410 | + * Reset cookie for disable_switcher. | |
| 411 | + * | |
| 412 | + * @access public | |
| 413 | + * | |
| 414 | + * @return void | |
| 415 | + * | |
| 416 | + * @since 1.0.0 | |
| 417 | + */ | |
| 418 | + public function set_cookie_rest_disable_switcher() { | |
| 419 | + setcookie( $this->cookie_name_disable_switcher, '', time() - 3600, '/', '', is_ssl(), false ); | |
| 420 | + } | |
| 421 | + | |
| 422 | + /** | |
| 423 | + * Set enable to cookie for disable_switcher. | |
| 424 | + * | |
| 425 | + * @access public | |
| 426 | + * | |
| 427 | + * @return void | |
| 428 | + * | |
| 429 | + * @since 1.0.0 | |
| 430 | + */ | |
| 431 | + public function set_cookie_enable_disable_switcher() { | |
| 432 | + setcookie( $this->cookie_name_multi_device_switcher, '', time() - 3600, '/', '', is_ssl(), false ); | |
| 433 | + setcookie( $this->cookie_name_disable_switcher, '1', 0, '/', '', is_ssl(), false ); | |
| 434 | + } | |
| 435 | + | |
| 436 | + /** | |
| 437 | + * Set switched theme to cookie. | |
| 438 | + * | |
| 439 | + * @access public | |
| 440 | + * | |
| 441 | + * @return void | |
| 442 | + * | |
| 443 | + * @since 1.0.0 | |
| 444 | + */ | |
| 445 | + public function set_cookie_switch_theme() { | |
| 446 | + $device = preg_replace( '/^custom_switcher_/', '', $this->device ); | |
| 447 | + setcookie( $this->cookie_name_multi_device_switcher, (string) $device, 0, '/', '', is_ssl(), false ); | |
| 448 | + } | |
| 449 | + | |
| 450 | + /** | |
| 451 | + * Reset cookie for normal theme. | |
| 452 | + * | |
| 453 | + * @access public | |
| 454 | + * | |
| 455 | + * @return void | |
| 456 | + * | |
| 457 | + * @since 1.0.0 | |
| 458 | + */ | |
| 459 | + public function set_cookie_normal_theme() { | |
| 460 | + setcookie( $this->cookie_name_multi_device_switcher, '', time() - 3600, '/', '', is_ssl(), false ); | |
| 461 | + } | |
| 462 | + | |
| 463 | + /** | |
| 464 | + * Set session to cookie for pc switcher. | |
| 465 | + * | |
| 466 | + * @access public | |
| 467 | + * | |
| 468 | + * @return void | |
| 469 | + * | |
| 470 | + * @since 1.0.0 | |
| 471 | + */ | |
| 198 | 472 | public function session() { |
| 473 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 199 | 474 | if ( isset( $_GET['pc-switcher'] ) ) { |
| 200 | - setcookie( 'pc-switcher', $_GET['pc-switcher'] ? 1 : '', null, '/' ); | |
| 475 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 476 | + setcookie( $this->cookie_name_pc_switcher, sanitize_text_field( wp_unslash( $_GET['pc-switcher'] ) ) ? '1' : '', 0, '/', '', is_ssl(), false ); | |
| 201 | 477 | |
| 202 | - $uri = preg_replace( '/^(.+?)(\?.*)$/', '$1', $_SERVER['REQUEST_URI'] ); | |
| 478 | + if ( isset( $_SERVER['REQUEST_URI'] ) ) { | |
| 479 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 480 | + $uri = preg_replace( '/^(.+?)(\?.*)$/', '$1', $_SERVER['REQUEST_URI'] ); | |
| 481 | + } | |
| 203 | 482 | |
| 483 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 204 | 484 | unset( $_GET['pc-switcher'] ); |
| 485 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 205 | 486 | if ( ! empty( $_GET ) ) { |
| 487 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 206 | 488 | $uri = $uri . '?' . http_build_query( $_GET ); |
| 207 | 489 | } |
| 208 | 490 | |
| 209 | - wp_redirect( esc_url( $uri ) ); | |
| 491 | + wp_safe_redirect( esc_url( $uri ) ); | |
| 210 | 492 | exit; |
| 211 | 493 | } |
| 212 | 494 | } |
| 213 | 495 | |
| 496 | + /** | |
| 497 | + * Enqueue styles for default_css | |
| 498 | + * | |
| 499 | + * @access public | |
| 500 | + * | |
| 501 | + * @return void | |
| 502 | + * | |
| 503 | + * @since 1.8.5 | |
| 504 | + */ | |
| 505 | + public function enqueue_styles() { | |
| 506 | + wp_enqueue_style( | |
| 507 | + 'pc-switcher-options', | |
| 508 | + plugins_url() . '/multi-device-switcher/pc-switcher.css', | |
| 509 | + array(), | |
| 510 | + $this->plugin_data['Version'], | |
| 511 | + 'all' | |
| 512 | + ); | |
| 513 | + } | |
| 514 | + | |
| 515 | + /** | |
| 516 | + * Add pc switcher button. | |
| 517 | + * | |
| 518 | + * @access public | |
| 519 | + * | |
| 520 | + * @param bool $pc_switcher | |
| 521 | + * | |
| 522 | + * @return void | |
| 523 | + * | |
| 524 | + * @since 1.0.0 | |
| 525 | + */ | |
| 214 | 526 | public function add_pc_switcher( $pc_switcher = 0 ) { |
| 215 | - $options = multi_device_switcher_get_options(); | |
| 216 | - $name = $this->get_device_theme(); | |
| 527 | + $options = $this->get_options(); | |
| 528 | + $name = $this->get_device_theme(); | |
| 217 | 529 | |
| 218 | 530 | if ( $options['pc_switcher'] ) { |
| 219 | 531 | $pc_switcher = 1; |
| 220 | 532 | } |
| 221 | 533 | |
| 222 | - if ( $pc_switcher && $name && 'None' != $name ) { | |
| 534 | + if ( $pc_switcher && $name && 'None' !== $name ) { | |
| 223 | 535 | if ( $options['default_css'] ) { |
| 224 | - wp_enqueue_style( 'pc-switcher-options', plugins_url() . '/multi-device-switcher/pc-switcher.css', false, '2013-03-20' ); | |
| 536 | + $this->enqueue_styles(); | |
| 225 | 537 | } |
| 226 | 538 | |
| 227 | - if ( isset( $_COOKIE['pc-switcher'] ) ) { | |
| 228 | - $uri = get_home_url() . add_query_arg( 'pc-switcher', 0 ); | |
| 229 | - ?> | |
| 230 | -<div class="pc-switcher"><a href="<?php echo esc_url( $uri ); ?>"><?php _e( 'Mobile', 'multi-device-switcher' ); ?></a><span class="active"><?php _e( 'PC', 'multi-device-switcher' ); ?></span></div> | |
| 231 | - <?php | |
| 539 | + $uri = is_ssl() ? 'https://' : 'http://'; | |
| 540 | + | |
| 541 | + if ( isset( $_SERVER['HTTP_HOST'] ) ) { | |
| 542 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 543 | + $uri .= $_SERVER['HTTP_HOST']; | |
| 232 | 544 | } |
| 545 | + | |
| 546 | + if ( isset( $_COOKIE[ $this->cookie_name_pc_switcher ] ) ) { | |
| 547 | + $uri .= add_query_arg( 'pc-switcher', 0 ); | |
| 548 | + ?> | |
| 549 | +<div class="pc-switcher"><a href="<?php echo esc_url( $uri ); ?>"><?php esc_html_e( 'Mobile', 'multi-device-switcher' ); ?></a><span class="active"><?php esc_html_e( 'PC', 'multi-device-switcher' ); ?></span></div> | |
| 550 | + <?php | |
| 551 | + } | |
| 233 | 552 | else { |
| 234 | - $uri = get_home_url() . add_query_arg( 'pc-switcher', 1 ); | |
| 235 | - ?> | |
| 236 | -<div class="pc-switcher"><span class="active"><?php _e( 'Mobile', 'multi-device-switcher' ); ?></span><a href="<?php echo esc_url( $uri ); ?>"><?php _e( 'PC', 'multi-device-switcher' ); ?></a></div> | |
| 237 | - <?php | |
| 553 | + $uri .= add_query_arg( 'pc-switcher', 1 ); | |
| 554 | + ?> | |
| 555 | +<div class="pc-switcher"><span class="active"><?php esc_html_e( 'Mobile', 'multi-device-switcher' ); ?></span><a href="<?php echo esc_url( $uri ); ?>"><?php esc_html_e( 'PC', 'multi-device-switcher' ); ?></a></div> | |
| 556 | + <?php | |
| 238 | 557 | } |
| 239 | 558 | } |
| 240 | 559 | } |
| 241 | 560 | |
| 561 | + /** | |
| 562 | + * Check device. | |
| 563 | + * | |
| 564 | + * @access public | |
| 565 | + * | |
| 566 | + * @param string $device | |
| 567 | + * | |
| 568 | + * @return bool | |
| 569 | + * | |
| 570 | + * @since 1.0.0 | |
| 571 | + */ | |
| 242 | 572 | public function is_multi_device( $device = '' ) { |
| 243 | - if ( $device == $this->device ) { | |
| 244 | - return (boolean) 1; | |
| 573 | + if ( $device === $this->device ) { | |
| 574 | + return true; | |
| 245 | 575 | } |
| 246 | - if ( 'custom_switcher_' . $device == $this->device ) { | |
| 247 | - return (boolean) 1; | |
| 576 | + if ( 'custom_switcher_' . $device === $this->device ) { | |
| 577 | + return true; | |
| 248 | 578 | } |
| 249 | 579 | |
| 250 | - return (boolean) 0; | |
| 580 | + return false; | |
| 251 | 581 | } |
| 252 | 582 | |
| 253 | - public function get_disable( $disable = 0 ) { | |
| 254 | - $options = multi_device_switcher_get_options(); | |
| 583 | + /** | |
| 584 | + * Whether pc switcher enabled. | |
| 585 | + * | |
| 586 | + * @access public | |
| 587 | + * | |
| 588 | + * @return bool | |
| 589 | + * | |
| 590 | + * @since 1.0.0 | |
| 591 | + */ | |
| 592 | + public function is_pc_switcher() { | |
| 593 | + return isset( $_COOKIE[ $this->cookie_name_pc_switcher ] ); | |
| 594 | + } | |
| 595 | + | |
| 596 | + /** | |
| 597 | + * Whether theme switch disabled. | |
| 598 | + * | |
| 599 | + * @access public | |
| 600 | + * | |
| 601 | + * @param bool $disable | |
| 602 | + * | |
| 603 | + * @return bool | |
| 604 | + * | |
| 605 | + * @since 1.0.0 | |
| 606 | + */ | |
| 607 | + public function is_disable_switcher( $disable = false ) { | |
| 608 | + $options = $this->get_options(); | |
| 255 | 609 | $disable_path = preg_split( '/\R/', $options['disable_path'], -1, PREG_SPLIT_NO_EMPTY ); |
| 256 | 610 | |
| 257 | - foreach ( $disable_path as $path ) { | |
| 611 | + if ( isset( $_SERVER['REQUEST_URI'] ) ) { | |
| 612 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 613 | + $request_uri = $_SERVER['REQUEST_URI']; | |
| 614 | + } | |
| 615 | + | |
| 616 | + foreach ( (array) $disable_path as $path ) { | |
| 258 | 617 | if ( $options['enable_regex'] ) { |
| 259 | - if ( preg_match( '/' . $path . '/i', $_SERVER['REQUEST_URI'] ) ) { | |
| 260 | - $disable = 1; | |
| 618 | + if ( preg_match( '/' . $path . '/i', $request_uri ) ) { | |
| 619 | + $disable = true; | |
| 261 | 620 | break; |
| 262 | 621 | } |
| 263 | 622 | } |
| 623 | + // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found | |
| 264 | 624 | else { |
| 265 | - if ( preg_match( '/^' . preg_quote( $path , '/' ) . '$/i', $_SERVER['REQUEST_URI'] ) ) { | |
| 266 | - $disable = 1; | |
| 625 | + if ( preg_match( '/^' . preg_quote( (string) $path, '/' ) . '$/i', $request_uri ) ) { | |
| 626 | + $disable = true; | |
| 267 | 627 | break; |
| 268 | 628 | } |
| 269 | 629 | } |
| 270 | 630 | } |
| 271 | 631 | |
| 272 | - return (boolean) $disable; | |
| 632 | + return $disable; | |
| 273 | 633 | } |
| 274 | -} | |
| 275 | 634 | |
| 276 | -if ( ! is_admin() ) { | |
| 277 | - $multi_device_switcher = new Multi_Device_Switcher(); | |
| 278 | -} | |
| 635 | + /** | |
| 636 | + * Shortcode. | |
| 637 | + * | |
| 638 | + * @access public | |
| 639 | + * | |
| 640 | + * @param array $atts | |
| 641 | + * @param string $content | |
| 642 | + * | |
| 643 | + * @return string | |
| 644 | + * | |
| 645 | + * @since 1.0.0 | |
| 646 | + */ | |
| 647 | + public function shortcode_display_switcher( $atts, $content = '' ) { | |
| 648 | + $atts = shortcode_atts( | |
| 649 | + array( | |
| 650 | + 'device' => '', | |
| 651 | + ), | |
| 652 | + $atts | |
| 653 | + ); | |
| 279 | 654 | |
| 280 | -/** | |
| 281 | - * Add HTTP/1.1 Vary header. | |
| 282 | - * | |
| 283 | - * @since 1.1.1 | |
| 284 | - * | |
| 285 | - */ | |
| 286 | -function multi_device_switcher_add_header_vary( $headers ) { | |
| 287 | - if ( ! is_admin() ) { | |
| 288 | - $headers['Vary'] = 'User-Agent'; | |
| 655 | + if ( empty( $atts['device'] ) && ( $this->is_multi_device( $atts['device'] ) || $this->is_pc_switcher() ) ) { | |
| 656 | + return $content; | |
| 657 | + } | |
| 658 | + elseif ( ! empty( $atts['device'] ) && $this->is_multi_device( $atts['device'] ) && ! $this->is_pc_switcher() ) { | |
| 659 | + return $content; | |
| 660 | + } | |
| 661 | + | |
| 662 | + return ''; | |
| 663 | + } | |
| 664 | + | |
| 665 | + /** | |
| 666 | + * Add HTTP Vary header. | |
| 667 | + * | |
| 668 | + * @access public | |
| 669 | + * | |
| 670 | + * @param string $headers | |
| 671 | + * | |
| 672 | + * @return string | |
| 673 | + * | |
| 674 | + * @since 1.1.1 | |
| 675 | + */ | |
| 676 | + public function add_header_vary( $headers ) { | |
| 677 | + /** | |
| 678 | + * Filter hook: multi_device_switcher/add_header_vary. | |
| 679 | + * | |
| 680 | + * @param string 'User-Agent' header name. | |
| 681 | + * | |
| 682 | + * @since 1.6.2 | |
| 683 | + */ | |
| 684 | + $headers['Vary'] = apply_filters( 'multi_device_switcher/add_header_vary', 'User-Agent' ); | |
| 289 | 685 | return $headers; |
| 290 | 686 | } |
| 291 | -} | |
| 292 | -add_filter( 'wp_headers', 'multi_device_switcher_add_header_vary' ); | |
| 293 | 687 | |
| 294 | -/** | |
| 295 | - * Add PC Switcher. | |
| 296 | - * | |
| 297 | - * @since 1.2 | |
| 298 | - * | |
| 299 | - */ | |
| 300 | -function multi_device_switcher_add_pc_switcher() { | |
| 301 | - global $multi_device_switcher; | |
| 302 | - $multi_device_switcher->add_pc_switcher( 1 ); | |
| 303 | -} | |
| 688 | + /** | |
| 689 | + * Enqueue scripts. | |
| 690 | + * | |
| 691 | + * Hooks to admin_enqueue_scripts. | |
| 692 | + * | |
| 693 | + * @access public | |
| 694 | + * | |
| 695 | + * @since 1.0.0 | |
| 696 | + */ | |
| 697 | + public function admin_enqueue_scripts() { | |
| 698 | + wp_enqueue_script( | |
| 699 | + 'multi-device-switcher-options', | |
| 700 | + plugins_url() . '/multi-device-switcher/multi-device-switcher.js', | |
| 701 | + array( 'jquery', 'jquery-ui-tabs' ), | |
| 702 | + $this->plugin_data['Version'], | |
| 703 | + false | |
| 704 | + ); | |
| 705 | + } | |
| 304 | 706 | |
| 305 | -/** | |
| 306 | - * Return boolean whether a particular device. | |
| 307 | - * | |
| 308 | - * @since 1.2.4 | |
| 309 | - * | |
| 310 | - */ | |
| 311 | -if ( ! function_exists( 'is_multi_device' ) ) : | |
| 707 | + /** | |
| 708 | + * Enqueue styles. | |
| 709 | + * | |
| 710 | + * Hooks to admin_enqueue_styles. | |
| 711 | + * | |
| 712 | + * @access public | |
| 713 | + * | |
| 714 | + * @since 1.0.0 | |
| 715 | + */ | |
| 716 | + public function admin_enqueue_styles() { | |
| 717 | + wp_enqueue_style( | |
| 718 | + 'multi-device-switcher-options', | |
| 719 | + plugins_url() . '/multi-device-switcher/multi-device-switcher.css', | |
| 720 | + array(), | |
| 721 | + $this->plugin_data['Version'], | |
| 722 | + 'all' | |
| 723 | + ); | |
| 724 | + } | |
| 312 | 725 | |
| 313 | -function is_multi_device( $device = '' ) { | |
| 314 | - global $multi_device_switcher; | |
| 315 | - return $multi_device_switcher->is_multi_device( $device ); | |
| 316 | -} | |
| 317 | -endif; | |
| 726 | + /** | |
| 727 | + * Register the form setting. | |
| 728 | + * | |
| 729 | + * Hooks to admin_init. | |
| 730 | + * | |
| 731 | + * @access public | |
| 732 | + * | |
| 733 | + * @return void | |
| 734 | + * | |
| 735 | + * @since 1.0 | |
| 736 | + */ | |
| 737 | + public function register_settings() { | |
| 738 | + if ( is_null( $this->get_options() ) ) { | |
| 739 | + add_option( $this->option_name ); | |
| 740 | + } | |
| 318 | 741 | |
| 319 | -/** | |
| 320 | - * Properly enqueue scripts for our multi_device_switcher options page. | |
| 321 | - * | |
| 322 | - * This function is attached to the admin_enqueue_scripts action hook. | |
| 323 | - * | |
| 324 | - * @since 1.0 | |
| 325 | - * | |
| 326 | - */ | |
| 327 | -function multi_device_switcher_admin_enqueue_scripts( $hook_suffix ) { | |
| 328 | - wp_enqueue_script( 'multi-device-switcher-options', plugins_url() . '/multi-device-switcher/multi-device-switcher.js', array( 'jquery', 'jquery-ui-tabs' ), '2011-08-22' ); | |
| 329 | -} | |
| 742 | + register_setting( | |
| 743 | + $this->option_group, | |
| 744 | + $this->option_name, | |
| 745 | + array( $this, 'validate_options' ) | |
| 746 | + ); | |
| 747 | + } | |
| 330 | 748 | |
| 331 | -/** | |
| 332 | - * Properly enqueue styles for our multi_device_switcher options page. | |
| 333 | - * | |
| 334 | - * This function is attached to the admin_enqueue_styles action hook. | |
| 335 | - * | |
| 336 | - * @since 1.0 | |
| 337 | - * | |
| 338 | - */ | |
| 339 | -function multi_device_switcher_admin_enqueue_styles( $hook_suffix ) { | |
| 340 | - wp_enqueue_style( 'multi-device-switcher-options', plugins_url() . '/multi-device-switcher/multi-device-switcher.css', false, '2011-08-22' ); | |
| 341 | -} | |
| 342 | - | |
| 343 | -/** | |
| 344 | - * Register the form setting for our multi_device_switcher array. | |
| 345 | - * | |
| 346 | - * This function is attached to the admin_init action hook. | |
| 347 | - * | |
| 348 | - * This call to register_setting() registers a validation callback, multi_device_switcher_validate(), | |
| 349 | - * which is used when the option is saved, to ensure that our option values are complete, properly | |
| 350 | - * formatted, and safe. | |
| 351 | - * | |
| 352 | - * @since 1.0 | |
| 353 | - */ | |
| 354 | -function multi_device_switcher_init() { | |
| 355 | - // If we have no options in the database, let's add them now. | |
| 356 | - if ( false === multi_device_switcher_get_options() ) { | |
| 357 | - add_option( 'multi_device_switcher_options' ); | |
| 749 | + /** | |
| 750 | + * Returns capability. | |
| 751 | + * | |
| 752 | + * @access public | |
| 753 | + * | |
| 754 | + * @return string | |
| 755 | + * | |
| 756 | + * @since 1.0.0 | |
| 757 | + */ | |
| 758 | + public function option_page_capability() { | |
| 759 | + return $this->capability; | |
| 358 | 760 | } |
| 359 | 761 | |
| 360 | - register_setting( | |
| 361 | - 'multi_device_switcher', // Options group, see settings_fields() call in multi_device_switcher_render_page() | |
| 362 | - 'multi_device_switcher_options', // Database option, see multi_device_switcher_get_options() | |
| 363 | - 'multi_device_switcher_validate' // The sanitization callback, see multi_device_switcher_validate() | |
| 364 | - ); | |
| 365 | -} | |
| 762 | + /** | |
| 763 | + * Adds option page. | |
| 764 | + * | |
| 765 | + * @access public | |
| 766 | + * | |
| 767 | + * @return void | |
| 768 | + * | |
| 769 | + * @since 1.0.0 | |
| 770 | + */ | |
| 771 | + public function add_option_page() { | |
| 772 | + $page_hook = add_theme_page( | |
| 773 | + __( 'Multi Device Switcher', 'multi-device-switcher' ), | |
| 774 | + __( 'Multi Device Switcher', 'multi-device-switcher' ), | |
| 775 | + $this->option_page_capability(), | |
| 776 | + 'multi-device-switcher', | |
| 777 | + array( $this, 'render_option_page' ) | |
| 778 | + ); | |
| 366 | 779 | |
| 367 | -add_action( 'admin_init', 'multi_device_switcher_init' ); | |
| 780 | + if ( ! $page_hook ) { | |
| 781 | + return; | |
| 782 | + } | |
| 368 | 783 | |
| 369 | -/** | |
| 370 | - * Change the capability required to save the 'multi_device_switcher' options group. | |
| 371 | - * | |
| 372 | - * @see multi_device_switcher_init() First parameter to register_setting() is the name of the options group. | |
| 373 | - * @see multi_device_switcher_add_page() The edit_theme_options capability is used for viewing the page. | |
| 374 | - * | |
| 375 | - * By default, the options groups for all registered settings require the manage_options capability. | |
| 376 | - * By default, only administrators have either of these capabilities, but the desire here is | |
| 377 | - * to allow for finer-grained control for roles and users. | |
| 378 | - * | |
| 379 | - * @param string $capability The capability used for the page, which is manage_options by default. | |
| 380 | - * @return string The capability to actually use. | |
| 381 | - */ | |
| 382 | -function multi_device_switcher_page_capability( $capability ) { | |
| 383 | - return 'edit_theme_options'; | |
| 384 | -} | |
| 385 | -add_filter( 'option_page_capability_multi_device_switcher', 'multi_device_switcher_page_capability' ); | |
| 784 | + add_action( 'load-' . $page_hook, array( $this, 'page_hook_suffix' ) ); | |
| 785 | + } | |
| 386 | 786 | |
| 387 | -/** | |
| 388 | - * Add our options page to the admin menu, including some help documentation. | |
| 389 | - * | |
| 390 | - * This function is attached to the admin_menu action hook. | |
| 391 | - * | |
| 392 | - * @since 1.0 | |
| 393 | - */ | |
| 394 | -function multi_device_switcher_add_page() { | |
| 395 | - load_plugin_textdomain( 'multi-device-switcher', false, 'multi-device-switcher/languages' ); | |
| 787 | + /** | |
| 788 | + * Page Hook Suffix. | |
| 789 | + * | |
| 790 | + * Hooks to load-{$page_hook}. | |
| 791 | + * | |
| 792 | + * @access public | |
| 793 | + * | |
| 794 | + * @return void | |
| 795 | + * | |
| 796 | + * @since 1.2.4 | |
| 797 | + */ | |
| 798 | + public function page_hook_suffix() { | |
| 799 | + add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); | |
| 800 | + add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_styles' ) ); | |
| 801 | + } | |
| 396 | 802 | |
| 397 | - add_filter( 'plugin_action_links', 'multi_device_switcher_plugin_action_links', 10, 2 ); | |
| 803 | + /** | |
| 804 | + * Set link to customizer section on the plugins page. | |
| 805 | + * | |
| 806 | + * Hooks to plugin_action_links_{$plugin_file} | |
| 807 | + * | |
| 808 | + * @see https://developer.wordpress.org/reference/hooks/plugin_action_links_plugin_file/ | |
| 809 | + * | |
| 810 | + * @access public | |
| 811 | + * | |
| 812 | + * @param array $links An array of plugin action links. | |
| 813 | + * | |
| 814 | + * @return array $links | |
| 815 | + * | |
| 816 | + * @since 1.6.0 | |
| 817 | + */ | |
| 818 | + public function plugin_action_links( $links = array() ) { | |
| 819 | + $settings_link = '<a href="themes.php?page=multi-device-switcher">' . __( 'Settings', 'multi-device-switcher' ) . '</a>'; | |
| 398 | 820 | |
| 399 | - $page_hook = add_theme_page( | |
| 400 | - __( 'Multi Device Switcher', 'multi-device-switcher' ), // Name of page | |
| 401 | - __( 'Multi Device Switcher', 'multi-device-switcher' ), // Label in menu | |
| 402 | - 'manage_options', // Capability required | |
| 403 | - 'multi-device-switcher', // Menu slug, used to uniquely identify the page | |
| 404 | - 'multi_device_switcher_render_page' // Function that renders the options page | |
| 405 | - ); | |
| 821 | + array_unshift( $links, $settings_link ); | |
| 406 | 822 | |
| 407 | - if ( ! $page_hook ) { | |
| 408 | - return; | |
| 823 | + return $links; | |
| 409 | 824 | } |
| 410 | 825 | |
| 411 | - add_action( 'load-' . $page_hook , 'multi_device_switcher_page_hook_suffix' ); | |
| 412 | -} | |
| 413 | -add_action( 'admin_menu', 'multi_device_switcher_add_page' ); | |
| 826 | + /** | |
| 827 | + * Set links below a plugin on the Plugins page. | |
| 828 | + * | |
| 829 | + * Hooks to plugin_row_meta | |
| 830 | + * | |
| 831 | + * @see https://developer.wordpress.org/reference/hooks/plugin_row_meta/ | |
| 832 | + * | |
| 833 | + * @access public | |
| 834 | + * | |
| 835 | + * @param array $links An array of the plugin's metadata. | |
| 836 | + * @param string $file Path to the plugin file relative to the plugins directory. | |
| 837 | + * | |
| 838 | + * @return array $links | |
| 839 | + * | |
| 840 | + * @since 1.8.1 | |
| 841 | + */ | |
| 842 | + public function plugin_metadata_links( $links, $file ) { | |
| 843 | + if ( $file === plugin_basename( __MULTI_DEVICE_SWITCHER_FILE__ ) ) { | |
| 844 | + $links[] = '<a href="https://github.com/sponsors/thingsym">' . __( 'Become a sponsor', 'multi-device-switcher' ) . '</a>'; | |
| 845 | + } | |
| 414 | 846 | |
| 415 | -/** | |
| 416 | - * Page Hook Suffix | |
| 417 | - * | |
| 418 | - * This function is attached to the load-** action hook. | |
| 419 | - * | |
| 420 | - * @since 1.2.4 | |
| 421 | - */ | |
| 422 | -function multi_device_switcher_page_hook_suffix() { | |
| 423 | - add_action( 'admin_enqueue_scripts', 'multi_device_switcher_admin_enqueue_scripts' ); | |
| 424 | - add_action( 'admin_enqueue_scripts', 'multi_device_switcher_admin_enqueue_styles' ); | |
| 425 | -} | |
| 426 | - | |
| 427 | -/** | |
| 428 | - * Add the settings link to the plugin page. | |
| 429 | - * | |
| 430 | - * @since 1.2 | |
| 431 | - */ | |
| 432 | -function multi_device_switcher_plugin_action_links( $links, $file ) { | |
| 433 | - if ( $file != plugin_basename( __FILE__ ) ) { | |
| 434 | 847 | return $links; |
| 435 | 848 | } |
| 436 | 849 | |
| 437 | - $settings_link = '<a href="themes.php?page=multi-device-switcher">' . __( 'Settings', 'multi-device-switcher' ) . '</a>'; | |
| 850 | + /** | |
| 851 | + * Returns the default options. | |
| 852 | + * | |
| 853 | + * @access public | |
| 854 | + * | |
| 855 | + * @return array|null | |
| 856 | + * | |
| 857 | + * @since 1.0.0 | |
| 858 | + */ | |
| 859 | + public function get_default_options() { | |
| 860 | + return $this->default_options; | |
| 861 | + } | |
| 438 | 862 | |
| 439 | - array_unshift( $links, $settings_link ); | |
| 863 | + /** | |
| 864 | + * Returns the options array or value. | |
| 865 | + * | |
| 866 | + * @access public | |
| 867 | + * | |
| 868 | + * @param string $option_name Optional. The option name. | |
| 869 | + * | |
| 870 | + * @return array|null | |
| 871 | + * | |
| 872 | + * @since 1.0.0 | |
| 873 | + */ | |
| 874 | + public function get_options( $option_name = null ) { | |
| 875 | + $options = get_option( $this->option_name, $this->default_options ); | |
| 876 | + $options = array_merge( $this->default_options, $options ); | |
| 440 | 877 | |
| 441 | - return $links; | |
| 442 | -} | |
| 878 | + if ( is_null( $option_name ) ) { | |
| 879 | + /** | |
| 880 | + * Filter hook: multi_device_switcher/get_options. | |
| 881 | + * | |
| 882 | + * @param array $options The options. | |
| 883 | + * | |
| 884 | + * @since 1.7.0 | |
| 885 | + */ | |
| 886 | + return apply_filters( 'multi_device_switcher/get_options', $options ); | |
| 887 | + } | |
| 443 | 888 | |
| 444 | -/** | |
| 445 | - * Returns the default options. | |
| 446 | - * | |
| 447 | - * @since 1.0 | |
| 448 | - */ | |
| 449 | -function multi_device_switcher_get_default_options() { | |
| 450 | - $default_theme_options = array( | |
| 451 | - 'pc_switcher' => 1, | |
| 452 | - 'default_css' => 1, | |
| 453 | - 'theme_smartphone' => 'None', | |
| 454 | - 'theme_tablet' => 'None', | |
| 455 | - 'theme_mobile' => 'None', | |
| 456 | - 'theme_game' => 'None', | |
| 457 | - 'userAgent_smart' => 'iPhone, iPod, Android, dream, CUPCAKE, Windows Phone, webOS, BB10, BlackBerry8707, BlackBerry9000, BlackBerry9300, BlackBerry9500, BlackBerry9530, BlackBerry9520, BlackBerry9550, BlackBerry9700, BlackBerry 93, BlackBerry 97, BlackBerry 99, BlackBerry 98', | |
| 458 | - 'userAgent_tablet' => 'iPad, Kindle, Sony Tablet, Nexus 7', | |
| 459 | - 'userAgent_mobile' => 'DoCoMo, SoftBank, J-PHONE, Vodafone, KDDI, UP.Browser, WILLCOM, emobile, DDIPOCKET, Windows CE, BlackBerry, Symbian, PalmOS, Huawei, IAC, Nokia', | |
| 460 | - 'userAgent_game' => 'PlayStation Portable, PlayStation Vita, PSP, PS2, PLAYSTATION 3, PlayStation 4, Nitro, Nintendo 3DS, Nintendo Wii, Nintendo WiiU, Xbox', | |
| 461 | - 'disable_path' => '', | |
| 462 | - 'enable_regex' => 0, | |
| 463 | - ); | |
| 889 | + if ( array_key_exists( $option_name, $options ) ) { | |
| 890 | + /** | |
| 891 | + * Filter hook: multi_device_switcher/get_option. | |
| 892 | + * | |
| 893 | + * @param mixed $option The value of option. | |
| 894 | + * @param string $option_name The option name via argument. | |
| 895 | + * | |
| 896 | + * @since 1.7.0 | |
| 897 | + */ | |
| 898 | + return apply_filters( 'multi_device_switcher/get_option', $options[ $option_name ], $option_name ); | |
| 899 | + } | |
| 464 | 900 | |
| 465 | - return $default_theme_options; | |
| 466 | -} | |
| 901 | + return null; | |
| 902 | + } | |
| 467 | 903 | |
| 468 | -/** | |
| 469 | - * Returns the options array. | |
| 470 | - * | |
| 471 | - * @since 1.0 | |
| 472 | - */ | |
| 473 | -function multi_device_switcher_get_options() { | |
| 474 | - $options = get_option( 'multi_device_switcher_options' ); | |
| 475 | - $default_options = multi_device_switcher_get_default_options(); | |
| 904 | + /** | |
| 905 | + * Load textdomain | |
| 906 | + * | |
| 907 | + * @access public | |
| 908 | + * | |
| 909 | + * @return boolean | |
| 910 | + * | |
| 911 | + * @since 1.6.0 | |
| 912 | + */ | |
| 913 | + public function load_textdomain() { | |
| 914 | + return load_plugin_textdomain( | |
| 915 | + 'multi-device-switcher', | |
| 916 | + false, | |
| 917 | + 'multi-device-switcher/languages' | |
| 918 | + ); | |
| 919 | + } | |
| 476 | 920 | |
| 477 | - if ( ! isset( $options['pc_switcher'] ) ) { | |
| 478 | - $options['pc_switcher'] = $default_options['pc_switcher']; | |
| 479 | - } | |
| 480 | - if ( ! isset( $options['default_css'] ) ) { | |
| 481 | - $options['default_css'] = $default_options['default_css']; | |
| 482 | - } | |
| 921 | + /** | |
| 922 | + * Load plugin data | |
| 923 | + * | |
| 924 | + * @access public | |
| 925 | + * | |
| 926 | + * @return boolean | |
| 927 | + * | |
| 928 | + * @since 1.8.1 | |
| 929 | + */ | |
| 930 | + public function load_plugin_data() { | |
| 931 | + if ( ! function_exists( 'get_plugin_data' ) ) { | |
| 932 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; | |
| 933 | + } | |
| 483 | 934 | |
| 484 | - if ( ! isset( $options['theme_smartphone'] ) ) { | |
| 485 | - $options['theme_smartphone'] = $default_options['theme_smartphone']; | |
| 486 | - } | |
| 487 | - if ( ! isset( $options['theme_tablet'] ) ) { | |
| 488 | - $options['theme_tablet'] = $default_options['theme_tablet']; | |
| 489 | - } | |
| 490 | - if ( ! isset( $options['theme_mobile'] ) ) { | |
| 491 | - $options['theme_mobile'] = $default_options['theme_mobile']; | |
| 492 | - } | |
| 493 | - if ( ! isset( $options['theme_game'] ) ) { | |
| 494 | - $options['theme_game'] = $default_options['theme_game']; | |
| 495 | - } | |
| 935 | + $this->plugin_data = get_plugin_data( __MULTI_DEVICE_SWITCHER_FILE__ ); | |
| 496 | 936 | |
| 497 | - if ( ! isset( $options['userAgent_smart'] ) ) { | |
| 498 | - $options['userAgent_smart'] = $default_options['userAgent_smart']; | |
| 499 | - } | |
| 500 | - if ( ! isset( $options['userAgent_tablet'] ) ) { | |
| 501 | - $options['userAgent_tablet'] = $default_options['userAgent_tablet']; | |
| 502 | - } | |
| 503 | - if ( ! isset( $options['userAgent_mobile'] ) ) { | |
| 504 | - $options['userAgent_mobile'] = $default_options['userAgent_mobile']; | |
| 505 | - } | |
| 506 | - if ( ! isset( $options['userAgent_game'] ) ) { | |
| 507 | - $options['userAgent_game'] = $default_options['userAgent_game']; | |
| 508 | - } | |
| 937 | + if ( ! $this->plugin_data ) { | |
| 938 | + return false; | |
| 939 | + } | |
| 509 | 940 | |
| 510 | - if ( ! isset( $options['disable_path'] ) ) { | |
| 511 | - $options['disable_path'] = $default_options['disable_path']; | |
| 941 | + return true; | |
| 512 | 942 | } |
| 513 | - if ( ! isset( $options['enable_regex'] ) ) { | |
| 514 | - $options['enable_regex'] = $default_options['enable_regex']; | |
| 515 | - } | |
| 516 | 943 | |
| 517 | - return $options; | |
| 518 | -} | |
| 519 | - | |
| 520 | -/** | |
| 521 | - * Rendering Options Setting Page. | |
| 522 | - * | |
| 523 | - * @since 1.0 | |
| 524 | - */ | |
| 525 | -function multi_device_switcher_render_page() { | |
| 526 | - ?> | |
| 527 | - <div class="wrap"> | |
| 528 | - <div id="icon-themes" class="icon32"><br></div> | |
| 529 | - <h2><?php printf( __( 'Multi Device Switcher', 'multi-device-switcher' ), wp_get_theme()->get( 'Name' ) ); ?></h2> | |
| 944 | + /** | |
| 945 | + * Display option page. | |
| 946 | + * | |
| 947 | + * @access public | |
| 948 | + * | |
| 949 | + * @return void | |
| 950 | + * | |
| 951 | + * @since 1.0.0 | |
| 952 | + */ | |
| 953 | + public function render_option_page() { | |
| 954 | + ?> | |
| 955 | +<div class="wrap"> | |
| 956 | +<div id="icon-themes" class="icon32"><br></div> | |
| 957 | +<h2><?php esc_html_e( 'Multi Device Switcher', 'multi-device-switcher' ); ?></h2> | |
| 530 | 958 | <?php settings_errors(); ?> |
| 531 | 959 | |
| 532 | - <form method="post" action="options.php"> | |
| 533 | - <?php | |
| 534 | - settings_fields( 'multi_device_switcher' ); | |
| 535 | - $options = multi_device_switcher_get_options(); | |
| 960 | +<form method="post" action="options.php"> | |
| 961 | + <?php | |
| 962 | + settings_fields( 'multi_device_switcher' ); | |
| 963 | + $options = $this->get_options(); | |
| 536 | 964 | |
| 537 | - $default_theme = wp_get_theme()->get( 'Name' ); | |
| 538 | - $themes = wp_get_themes(); | |
| 539 | - $theme_names = array(); | |
| 965 | + $default_theme = wp_get_theme()->get( 'Name' ); | |
| 966 | + $themes = wp_get_themes(); | |
| 967 | + $theme_names = array(); | |
| 540 | 968 | |
| 541 | - if ( count( $themes ) ) { | |
| 542 | - foreach ( $themes as $t ) { | |
| 543 | - $theme_names[] = $t->get( 'Name' ); | |
| 544 | - } | |
| 545 | - natcasesort( $theme_names ); | |
| 546 | - } | |
| 547 | - ?> | |
| 969 | + if ( count( $themes ) ) { | |
| 970 | + foreach ( $themes as $t ) { | |
| 971 | + $theme_names[] = $t->get( 'Name' ); | |
| 972 | + } | |
| 973 | + natcasesort( $theme_names ); | |
| 974 | + } | |
| 975 | + ?> | |
| 548 | 976 | |
| 549 | - <div id="admin-tabs"> | |
| 550 | - <fieldset id="Theme" class="options"> | |
| 551 | - <h3 class="label"><?php _e( 'Theme', 'multi-device-switcher' ); ?></h3> | |
| 552 | - <table class="form-table"> | |
| 553 | - <tr><th scope="row"><?php _e( 'Smart Phone Theme', 'multi-device-switcher' ); ?></th> | |
| 554 | - <td> | |
| 977 | +<div id="admin-tabs"> | |
| 978 | +<fieldset id="Theme" class="options"> | |
| 979 | +<h3 class="label"><?php esc_html_e( 'Theme', 'multi-device-switcher' ); ?></h3> | |
| 980 | +<table class="form-table"> | |
| 981 | + <tr><th scope="row"><?php esc_html_e( 'Smart Phone Theme', 'multi-device-switcher' ); ?></th> | |
| 982 | + <td> | |
| 555 | 983 | |
| 556 | - <?php | |
| 557 | - if ( count( $theme_names ) ) { | |
| 558 | - $html = '<select name="multi_device_switcher_options[theme_smartphone]">'; | |
| 984 | + <?php | |
| 985 | + $html = ''; | |
| 986 | + if ( count( $theme_names ) ) { | |
| 987 | + $html = '<select name="multi_device_switcher_options[theme_smartphone]">'; | |
| 559 | 988 | |
| 560 | - if ( ( 'None' == $options['theme_smartphone'] ) || ( '' == $options['theme_smartphone'] ) ) { | |
| 561 | - $html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 562 | - } | |
| 563 | - else { | |
| 564 | - $html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 565 | - } | |
| 989 | + if ( ( 'None' === $options['theme_smartphone'] ) || ( '' === $options['theme_smartphone'] ) ) { | |
| 990 | + $html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 991 | + } | |
| 992 | + else { | |
| 993 | + $html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 994 | + } | |
| 566 | 995 | |
| 567 | - foreach ( $theme_names as $theme_name ) { | |
| 568 | - if ( $default_theme == $theme_name ) { | |
| 569 | - continue; | |
| 570 | - } | |
| 571 | - if ( $options['theme_smartphone'] == $theme_name ) { | |
| 572 | - $html .= '<option value="' . esc_attr( $theme_name ) . '" selected="selected">' . esc_html( $theme_name ) . '</option>'; | |
| 573 | - } | |
| 574 | - else { | |
| 575 | - $html .= '<option value="' . esc_attr( $theme_name ) . '">' . esc_html( $theme_name ) . '</option>'; | |
| 576 | - } | |
| 577 | - } | |
| 578 | - $html .= '</select>'; | |
| 996 | + foreach ( $theme_names as $theme_name ) { | |
| 997 | + if ( $default_theme === $theme_name ) { | |
| 998 | + continue; | |
| 579 | 999 | } |
| 580 | - echo $html; | |
| 581 | - ?> | |
| 582 | - </td> | |
| 583 | - </tr> | |
| 584 | - <tr><th scope="row"><?php _e( 'Tablet PC Theme', 'multi-device-switcher' ); ?></th> | |
| 585 | - <td> | |
| 1000 | + if ( $options['theme_smartphone'] === $theme_name ) { | |
| 1001 | + $html .= '<option value="' . esc_attr( $theme_name ) . '" selected="selected">' . esc_html( $theme_name ) . '</option>'; | |
| 1002 | + } | |
| 1003 | + else { | |
| 1004 | + $html .= '<option value="' . esc_attr( $theme_name ) . '">' . esc_html( $theme_name ) . '</option>'; | |
| 1005 | + } | |
| 1006 | + } | |
| 1007 | + $html .= '</select>'; | |
| 1008 | + } | |
| 1009 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1010 | + echo $html; | |
| 1011 | + ?> | |
| 586 | 1012 | |
| 587 | - <?php | |
| 588 | - if ( count( $theme_names ) ) { | |
| 589 | - $html = '<select name="multi_device_switcher_options[theme_tablet]">'; | |
| 1013 | + </td> | |
| 1014 | + </tr> | |
| 1015 | + <tr><th scope="row"><?php esc_html_e( 'Tablet PC Theme', 'multi-device-switcher' ); ?></th> | |
| 1016 | + <td> | |
| 590 | 1017 | |
| 591 | - if ( ( 'None' == $options['theme_tablet'] ) || ( '' == $options['theme_tablet'] ) ) { | |
| 592 | - $html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 593 | - } | |
| 594 | - else { | |
| 595 | - $html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 596 | - } | |
| 1018 | + <?php | |
| 1019 | + if ( count( $theme_names ) ) { | |
| 1020 | + $html = '<select name="multi_device_switcher_options[theme_tablet]">'; | |
| 597 | 1021 | |
| 598 | - foreach ( $theme_names as $theme_name ) { | |
| 599 | - if ( $default_theme == $theme_name ) { | |
| 600 | - continue; | |
| 601 | - } | |
| 602 | - if ( $options['theme_tablet'] == $theme_name ) { | |
| 603 | - $html .= '<option value="' . esc_attr( $theme_name ) . '" selected="selected">' . esc_html( $theme_name ) . '</option>'; | |
| 604 | - } | |
| 605 | - else { | |
| 606 | - $html .= '<option value="' . esc_attr( $theme_name ) . '">' . esc_html( $theme_name ) . '</option>'; | |
| 607 | - } | |
| 608 | - } | |
| 609 | - $html .= '</select>'; | |
| 1022 | + if ( ( 'None' === $options['theme_tablet'] ) || ( '' === $options['theme_tablet'] ) ) { | |
| 1023 | + $html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 1024 | + } | |
| 1025 | + else { | |
| 1026 | + $html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 1027 | + } | |
| 1028 | + | |
| 1029 | + foreach ( $theme_names as $theme_name ) { | |
| 1030 | + if ( $default_theme === $theme_name ) { | |
| 1031 | + continue; | |
| 610 | 1032 | } |
| 611 | - echo $html; | |
| 612 | - ?> | |
| 613 | - </td> | |
| 614 | - </tr> | |
| 615 | - <tr><th scope="row"><?php _e( 'Mobile Phone Theme', 'multi-device-switcher' ); ?></th> | |
| 616 | - <td> | |
| 1033 | + if ( $options['theme_tablet'] === $theme_name ) { | |
| 1034 | + $html .= '<option value="' . esc_attr( $theme_name ) . '" selected="selected">' . esc_html( $theme_name ) . '</option>'; | |
| 1035 | + } | |
| 1036 | + else { | |
| 1037 | + $html .= '<option value="' . esc_attr( $theme_name ) . '">' . esc_html( $theme_name ) . '</option>'; | |
| 1038 | + } | |
| 1039 | + } | |
| 1040 | + $html .= '</select>'; | |
| 1041 | + } | |
| 1042 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1043 | + echo $html; | |
| 1044 | + ?> | |
| 617 | 1045 | |
| 618 | - <?php | |
| 619 | - if ( count( $theme_names ) ) { | |
| 620 | - $html = '<select name="multi_device_switcher_options[theme_mobile]">'; | |
| 1046 | + </td> | |
| 1047 | + </tr> | |
| 1048 | + <tr><th scope="row"><?php esc_html_e( 'Mobile Phone Theme', 'multi-device-switcher' ); ?></th> | |
| 1049 | + <td> | |
| 621 | 1050 | |
| 622 | - if ( ( 'None' == $options['theme_mobile'] ) || ( '' == $options['theme_mobile'] ) ) { | |
| 623 | - $html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 624 | - } | |
| 625 | - else { | |
| 626 | - $html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 627 | - } | |
| 1051 | + <?php | |
| 1052 | + if ( count( $theme_names ) ) { | |
| 1053 | + $html = '<select name="multi_device_switcher_options[theme_mobile]">'; | |
| 628 | 1054 | |
| 629 | - foreach ( $theme_names as $theme_name ) { | |
| 630 | - if ( $default_theme == $theme_name ) { | |
| 631 | - continue; | |
| 632 | - } | |
| 633 | - if ( $options['theme_mobile'] == $theme_name ) { | |
| 634 | - $html .= '<option value="' . esc_attr( $theme_name ) . '" selected="selected">' . esc_html( $theme_name ) . '</option>'; | |
| 635 | - } | |
| 636 | - else { | |
| 637 | - $html .= '<option value="' . esc_attr( $theme_name ) . '">' . esc_html( $theme_name ) . '</option>'; | |
| 638 | - } | |
| 639 | - } | |
| 640 | - $html .= '</select>'; | |
| 1055 | + if ( ( 'None' === $options['theme_mobile'] ) || ( '' === $options['theme_mobile'] ) ) { | |
| 1056 | + $html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 1057 | + } | |
| 1058 | + else { | |
| 1059 | + $html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 1060 | + } | |
| 1061 | + | |
| 1062 | + foreach ( $theme_names as $theme_name ) { | |
| 1063 | + if ( $default_theme === $theme_name ) { | |
| 1064 | + continue; | |
| 641 | 1065 | } |
| 642 | - echo $html; | |
| 643 | - ?> | |
| 644 | - </td> | |
| 645 | - </tr> | |
| 646 | - <tr><th scope="row"><?php _e( 'Game Platforms Theme', 'multi-device-switcher' ); ?></th> | |
| 647 | - <td> | |
| 1066 | + if ( $options['theme_mobile'] === $theme_name ) { | |
| 1067 | + $html .= '<option value="' . esc_attr( $theme_name ) . '" selected="selected">' . esc_html( $theme_name ) . '</option>'; | |
| 1068 | + } | |
| 1069 | + else { | |
| 1070 | + $html .= '<option value="' . esc_attr( $theme_name ) . '">' . esc_html( $theme_name ) . '</option>'; | |
| 1071 | + } | |
| 1072 | + } | |
| 1073 | + $html .= '</select>'; | |
| 1074 | + } | |
| 1075 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1076 | + echo $html; | |
| 1077 | + ?> | |
| 648 | 1078 | |
| 649 | - <?php | |
| 650 | - if ( count( $theme_names ) ) { | |
| 651 | - $html = '<select name="multi_device_switcher_options[theme_game]">'; | |
| 1079 | + </td> | |
| 1080 | + </tr> | |
| 1081 | + <tr><th scope="row"><?php esc_html_e( 'Game Platforms Theme', 'multi-device-switcher' ); ?></th> | |
| 1082 | + <td> | |
| 652 | 1083 | |
| 653 | - if ( ( 'None' == $options['theme_game'] ) || ( '' == $options['theme_game'] ) ) { | |
| 654 | - $html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 655 | - } | |
| 656 | - else { | |
| 657 | - $html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 658 | - } | |
| 1084 | + <?php | |
| 1085 | + if ( count( $theme_names ) ) { | |
| 1086 | + $html = '<select name="multi_device_switcher_options[theme_game]">'; | |
| 659 | 1087 | |
| 660 | - foreach ( $theme_names as $theme_name ) { | |
| 661 | - if ( $default_theme == $theme_name ) { | |
| 662 | - continue; | |
| 663 | - } | |
| 664 | - if ( $options['theme_game'] == $theme_name ) { | |
| 665 | - $html .= '<option value="' . esc_attr( $theme_name ) . '" selected="selected">' . esc_html( $theme_name ) . '</option>'; | |
| 666 | - } | |
| 667 | - else { | |
| 668 | - $html .= '<option value="' . esc_attr( $theme_name ) . '">' . esc_html( $theme_name ) . '</option>'; | |
| 669 | - } | |
| 670 | - } | |
| 671 | - $html .= '</select>'; | |
| 1088 | + if ( ( 'None' === $options['theme_game'] ) || ( '' === $options['theme_game'] ) ) { | |
| 1089 | + $html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 1090 | + } | |
| 1091 | + else { | |
| 1092 | + $html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 1093 | + } | |
| 1094 | + | |
| 1095 | + foreach ( $theme_names as $theme_name ) { | |
| 1096 | + if ( $default_theme === $theme_name ) { | |
| 1097 | + continue; | |
| 672 | 1098 | } |
| 673 | - echo $html; | |
| 674 | - ?> | |
| 675 | - </td> | |
| 676 | - </tr> | |
| 677 | - </table> | |
| 1099 | + if ( $options['theme_game'] === $theme_name ) { | |
| 1100 | + $html .= '<option value="' . esc_attr( $theme_name ) . '" selected="selected">' . esc_html( $theme_name ) . '</option>'; | |
| 1101 | + } | |
| 1102 | + else { | |
| 1103 | + $html .= '<option value="' . esc_attr( $theme_name ) . '">' . esc_html( $theme_name ) . '</option>'; | |
| 1104 | + } | |
| 1105 | + } | |
| 1106 | + $html .= '</select>'; | |
| 1107 | + } | |
| 1108 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1109 | + echo $html; | |
| 1110 | + ?> | |
| 678 | 1111 | |
| 679 | - <h3><?php _e( 'Custom Switcher Theme', 'multi-device-switcher' ); ?></h3> | |
| 680 | - <table class="form-table"> | |
| 1112 | + </td> | |
| 1113 | + </tr> | |
| 1114 | +</table> | |
| 681 | 1115 | |
| 682 | - <?php | |
| 683 | - foreach ( $options as $custom_switcher_option => $custom_switcher_theme ) { | |
| 684 | - if ( ! preg_match( '/^custom_switcher_theme_/', $custom_switcher_option ) ) { | |
| 685 | - continue; | |
| 686 | - } | |
| 1116 | +<h3><?php esc_html_e( 'Custom Switcher Theme', 'multi-device-switcher' ); ?></h3> | |
| 1117 | +<table class="form-table"> | |
| 687 | 1118 | |
| 688 | - $custom_switcher_name = preg_replace( '/^custom_switcher_theme_/', '', $custom_switcher_option ); | |
| 1119 | + <?php | |
| 1120 | + foreach ( (array) $options as $custom_switcher_option => $custom_switcher_theme ) { | |
| 1121 | + if ( ! preg_match( '/^custom_switcher_theme_/', $custom_switcher_option ) ) { | |
| 1122 | + continue; | |
| 1123 | + } | |
| 1124 | + | |
| 1125 | + $custom_switcher_name = preg_replace( '/^custom_switcher_theme_/', '', $custom_switcher_option ); | |
| 689 | 1126 | ?> |
| 690 | 1127 | |
| 691 | - <tr><th scope="row"><?php echo esc_html( $custom_switcher_name ); ?></th> | |
| 692 | - <td> | |
| 1128 | + <tr><th scope="row"><?php echo esc_html( $custom_switcher_name ); ?></th> | |
| 1129 | + <td> | |
| 693 | 1130 | |
| 694 | 1131 | <?php |
| 695 | - if ( count( $theme_names ) ) { | |
| 696 | - $html = '<select name="multi_device_switcher_options[' . $custom_switcher_option . ']">'; | |
| 1132 | + if ( count( $theme_names ) ) { | |
| 1133 | + $html = '<select name="multi_device_switcher_options[' . $custom_switcher_option . ']">'; | |
| 697 | 1134 | |
| 698 | - if ( ( 'None' == $custom_switcher_theme ) || ( '' == $custom_switcher_theme ) ) { | |
| 699 | - $html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 1135 | + if ( ( 'None' === $custom_switcher_theme ) || ( '' === $custom_switcher_theme ) ) { | |
| 1136 | + $html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 1137 | + } | |
| 1138 | + else { | |
| 1139 | + $html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 1140 | + } | |
| 1141 | + | |
| 1142 | + foreach ( $theme_names as $theme_name ) { | |
| 1143 | + if ( $default_theme === $theme_name ) { | |
| 1144 | + continue; | |
| 700 | 1145 | } |
| 1146 | + if ( $custom_switcher_theme === $theme_name ) { | |
| 1147 | + $html .= '<option value="' . esc_attr( $theme_name ) . '" selected="selected">' . esc_html( $theme_name ) . '</option>'; | |
| 1148 | + } | |
| 701 | 1149 | else { |
| 702 | - $html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>'; | |
| 1150 | + $html .= '<option value="' . esc_attr( $theme_name ) . '">' . esc_html( $theme_name ) . '</option>'; | |
| 703 | 1151 | } |
| 704 | - | |
| 705 | - foreach ( $theme_names as $theme_name ) { | |
| 706 | - if ( $default_theme == $theme_name ) { | |
| 707 | - continue; | |
| 708 | - } | |
| 709 | - if ( $custom_switcher_theme == $theme_name ) { | |
| 710 | - $html .= '<option value="' . esc_attr( $theme_name ) . '" selected="selected">' . esc_html( $theme_name ) . '</option>'; | |
| 711 | - } | |
| 712 | - else { | |
| 713 | - $html .= '<option value="' . esc_attr( $theme_name ) . '">' . esc_html( $theme_name ) . '</option>'; | |
| 714 | - } | |
| 715 | - } | |
| 716 | - $html .= '</select>'; | |
| 717 | - $html .= ' <span class="submit"><input type="submit" name="multi_device_switcher_options[delete_custom_switcher_' . $custom_switcher_name . ']" value="' . __( 'Delete', 'multi-device-switcher' ) . '" onclick="return confirm(\'' . esc_html( sprintf( __( 'Are you sure you want to delete %1$s ?', 'multi-device-switcher' ), $custom_switcher_name ) ) . '\');" class="button"></span>'; | |
| 718 | 1152 | } |
| 719 | - echo $html; | |
| 1153 | + $html .= '</select>'; | |
| 1154 | + /* translators: confirm: 1: custom switcher name */ | |
| 1155 | + $html .= ' <span class="submit"><input type="submit" name="multi_device_switcher_options[delete_custom_switcher_' . $custom_switcher_name . ']" value="' . __( 'Delete', 'multi-device-switcher' ) . '" onclick="return confirm(\'' . esc_html( sprintf( __( 'Are you sure you want to delete %1$s ?', 'multi-device-switcher' ), $custom_switcher_name ) ) . '\');" class="button"></span>'; | |
| 1156 | + } | |
| 1157 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1158 | + echo $html; | |
| 720 | 1159 | ?> |
| 721 | - </td> | |
| 722 | - </tr> | |
| 1160 | + </td> | |
| 1161 | + </tr> | |
| 723 | 1162 | |
| 724 | 1163 | <?php |
| 725 | - } | |
| 726 | - ?> | |
| 1164 | + } | |
| 1165 | + ?> | |
| 727 | 1166 | |
| 728 | - <tr><th scope="row"><?php _e( 'Add Custom Switcher', 'multi-device-switcher' ); ?></th> | |
| 729 | - <td> | |
| 730 | - <legend class="screen-reader-text"><span><?php _e( 'Add Custom Switcher', 'thingscms' ); ?></span></legend> | |
| 731 | - <input type="text" name="multi_device_switcher_options[custom_switcher]" id="custom-switcher" value="" size="24"> | |
| 732 | - <span class="submit"><input type="submit" name="multi_device_switcher_options[add_custom_switcher]" value="<?php _e( 'Add', 'multi-device-switcher' ); ?>" class="button"></span><br> | |
| 733 | - <?php _e( '20 characters max, alphanumeric', 'multi-device-switcher' ); ?> | |
| 734 | - </td> | |
| 735 | - </tr> | |
| 736 | - </table> | |
| 1167 | + <tr><th scope="row"><?php esc_html_e( 'Add Custom Switcher', 'multi-device-switcher' ); ?></th> | |
| 1168 | + <td> | |
| 1169 | + <legend class="screen-reader-text"><span><?php esc_html_e( 'Add Custom Switcher', 'multi-device-switcher' ); ?></span></legend> | |
| 1170 | + <input type="text" name="multi_device_switcher_options[custom_switcher]" id="custom-switcher" value="" size="24"> | |
| 1171 | + <span class="submit"><input type="submit" name="multi_device_switcher_options[add_custom_switcher]" value="<?php esc_html_e( 'Add', 'multi-device-switcher' ); ?>" class="button"></span><br> | |
| 1172 | + <?php esc_html_e( '20 characters max, alphanumeric', 'multi-device-switcher' ); ?> | |
| 1173 | + </td> | |
| 1174 | + </tr> | |
| 1175 | +</table> | |
| 737 | 1176 | |
| 738 | - </fieldset> | |
| 1177 | +</fieldset> | |
| 739 | 1178 | |
| 740 | - <fieldset id="UserAgent" class="options"> | |
| 741 | - <h3 class="label"><?php _e( 'UserAgent', 'multi-device-switcher' ); ?></h3> | |
| 742 | - <p><?php _e( 'Enter Comma-separated values (csv) format.', 'multi-device-switcher' ); ?></p> | |
| 1179 | +<fieldset id="UserAgent" class="options"> | |
| 1180 | +<h3 class="label"><?php esc_html_e( 'UserAgent', 'multi-device-switcher' ); ?></h3> | |
| 1181 | +<p><?php esc_html_e( 'Enter Comma-separated values (csv) format.', 'multi-device-switcher' ); ?></p> | |
| 743 | 1182 | |
| 744 | - <table class="form-table"> | |
| 745 | - <tr><th scope="row"><?php _e( 'Smart Phone', 'multi-device-switcher' ); ?></th> | |
| 746 | - <td><textarea name="multi_device_switcher_options[userAgent_smart]" rows="4" cols="42"><?php echo esc_textarea( $options['userAgent_smart'] ); ?></textarea></td> | |
| 747 | - </tr> | |
| 748 | - <tr><th scope="row"><?php _e( 'Tablet PC', 'multi-device-switcher' ); ?></th> | |
| 749 | - <td><textarea name="multi_device_switcher_options[userAgent_tablet]" rows="4" cols="42"><?php echo esc_textarea( $options['userAgent_tablet'] ); ?></textarea></td> | |
| 750 | - </tr> | |
| 751 | - <tr><th scope="row"><?php _e( 'Mobile Phone', 'multi-device-switcher' ); ?></th> | |
| 752 | - <td><textarea name="multi_device_switcher_options[userAgent_mobile]" rows="4" cols="42"><?php echo esc_textarea( $options['userAgent_mobile'] ); ?></textarea></td> | |
| 753 | - </tr> | |
| 754 | - <tr><th scope="row"><?php _e( 'Game Platforms', 'multi-device-switcher' ); ?></th> | |
| 755 | - <td><textarea name="multi_device_switcher_options[userAgent_game]" rows="4" cols="42"><?php echo esc_textarea( $options['userAgent_game'] ); ?></textarea></td> | |
| 756 | - </tr> | |
| 757 | - <tr><th></th> | |
| 758 | - <td><span class="submit"><input type="submit" name="multi_device_switcher_options[restore_UserAgent]" value="<?php _e( 'Reset Settings to Default UserAgent', 'multi-device-switcher' ); ?>" class="button"></span></td> | |
| 759 | - </tr> | |
| 1183 | +<table class="form-table"> | |
| 1184 | + <tr><th scope="row"><?php esc_html_e( 'Smart Phone', 'multi-device-switcher' ); ?></th> | |
| 1185 | + <td><textarea name="multi_device_switcher_options[userAgent_smart]" rows="4" cols="42"><?php echo esc_textarea( $options['userAgent_smart'] ); ?></textarea></td> | |
| 1186 | + </tr> | |
| 1187 | + <tr><th scope="row"><?php esc_html_e( 'Tablet PC', 'multi-device-switcher' ); ?></th> | |
| 1188 | + <td><textarea name="multi_device_switcher_options[userAgent_tablet]" rows="4" cols="42"><?php echo esc_textarea( $options['userAgent_tablet'] ); ?></textarea></td> | |
| 1189 | + </tr> | |
| 1190 | + <tr><th scope="row"><?php esc_html_e( 'Mobile Phone', 'multi-device-switcher' ); ?></th> | |
| 1191 | + <td><textarea name="multi_device_switcher_options[userAgent_mobile]" rows="4" cols="42"><?php echo esc_textarea( $options['userAgent_mobile'] ); ?></textarea></td> | |
| 1192 | + </tr> | |
| 1193 | + <tr><th scope="row"><?php esc_html_e( 'Game Platforms', 'multi-device-switcher' ); ?></th> | |
| 1194 | + <td><textarea name="multi_device_switcher_options[userAgent_game]" rows="4" cols="42"><?php echo esc_textarea( $options['userAgent_game'] ); ?></textarea></td> | |
| 1195 | + </tr> | |
| 1196 | + <tr><th></th> | |
| 1197 | + <td><span class="submit"><input type="submit" name="multi_device_switcher_options[restore_UserAgent]" value="<?php esc_html_e( 'Reset Settings to Default UserAgent', 'multi-device-switcher' ); ?>" class="button"></span></td> | |
| 1198 | + </tr> | |
| 760 | 1199 | |
| 761 | - </table> | |
| 1200 | +</table> | |
| 762 | 1201 | |
| 763 | - <h3><?php _e( 'Custom Switcher UserAgent', 'multi-device-switcher' ); ?></h3> | |
| 764 | - <table class="form-table"> | |
| 765 | - <?php | |
| 766 | - foreach ( $options as $custom_switcher_option => $custom_switcher_userAgent ) { | |
| 767 | - if ( ! preg_match( '/^custom_switcher_userAgent_/', $custom_switcher_option ) ) { | |
| 768 | - continue; | |
| 769 | - } | |
| 1202 | +<h3><?php esc_html_e( 'Custom Switcher UserAgent', 'multi-device-switcher' ); ?></h3> | |
| 1203 | +<table class="form-table"> | |
| 1204 | + <?php | |
| 1205 | + foreach ( (array) $options as $custom_switcher_option => $custom_switcher_user_agent ) { | |
| 1206 | + if ( ! preg_match( '/^custom_switcher_userAgent_/', $custom_switcher_option ) ) { | |
| 1207 | + continue; | |
| 1208 | + } | |
| 770 | 1209 | |
| 771 | - $custom_switcher_name = preg_replace( '/^custom_switcher_userAgent_/', '', $custom_switcher_option ); | |
| 1210 | + $custom_switcher_name = preg_replace( '/^custom_switcher_userAgent_/', '', $custom_switcher_option ); | |
| 772 | 1211 | ?> |
| 773 | 1212 | |
| 774 | - <tr><th scope="row"><?php echo esc_html( $custom_switcher_name ); ?></th> | |
| 775 | - <td><textarea name="multi_device_switcher_options[<?php echo esc_attr( $custom_switcher_option ); ?>]" rows="4" cols="42"><?php echo esc_textarea( $custom_switcher_userAgent ); ?></textarea></td> | |
| 776 | - </tr> | |
| 1213 | + <tr><th scope="row"><?php echo esc_html( $custom_switcher_name ); ?></th> | |
| 1214 | + <td><textarea name="multi_device_switcher_options[<?php echo esc_attr( $custom_switcher_option ); ?>]" rows="4" cols="42"><?php echo esc_textarea( $custom_switcher_user_agent ); ?></textarea></td> | |
| 1215 | + </tr> | |
| 777 | 1216 | <?php |
| 778 | - } | |
| 779 | - ?> | |
| 1217 | + } | |
| 1218 | + ?> | |
| 780 | 1219 | |
| 781 | - </table> | |
| 782 | - </fieldset> | |
| 1220 | +</table> | |
| 1221 | +</fieldset> | |
| 783 | 1222 | |
| 784 | - <fieldset id="PC-Switcher" class="options"> | |
| 785 | - <h3 class="label"><?php _e( 'PC Switcher', 'multi-device-switcher' ); ?></h3> | |
| 1223 | +<fieldset id="PC-Switcher" class="options"> | |
| 1224 | +<h3 class="label"><?php esc_html_e( 'PC Switcher', 'multi-device-switcher' ); ?></h3> | |
| 786 | 1225 | |
| 787 | - <table class="form-table"> | |
| 788 | - <tr><th scope="row"><?php _e( 'Add PC Switcher', 'multi-device-switcher' ); ?></th> | |
| 789 | - <td> | |
| 790 | - <legend class="screen-reader-text"><span><?php _e( 'Add PC Switcher', 'multi-device-switcher' ); ?></span></legend> | |
| 791 | - <label><input type="checkbox" name="multi_device_switcher_options[pc_switcher]" id="pc-switcher" value="1"<?php checked( 1, $options['pc_switcher'] ); ?>> <?php _e( 'Add a PC Switcher to the footer.', 'multi-device-switcher' ); ?></label> | |
| 792 | - </td> | |
| 793 | - </tr> | |
| 794 | - <tr><th scope="row"><?php _e( 'Add default CSS', 'multi-device-switcher' ); ?></th> | |
| 795 | - <td> | |
| 796 | - <legend class="screen-reader-text"><span><?php _e( 'Add default CSS', 'multi-device-switcher' ); ?></span></legend> | |
| 797 | - <label><input type="checkbox" name="multi_device_switcher_options[default_css]" id="add-default-css" value="1"<?php checked( 1, $options['default_css'] ); ?>> <?php _e( 'Add a default CSS.', 'multi-device-switcher' ); ?></label> | |
| 798 | - </td> | |
| 799 | - </tr> | |
| 800 | - </table> | |
| 801 | - </fieldset> | |
| 1226 | +<table class="form-table"> | |
| 1227 | + <tr><th scope="row"><?php esc_html_e( 'Add PC Switcher', 'multi-device-switcher' ); ?></th> | |
| 1228 | + <td> | |
| 1229 | + <legend class="screen-reader-text"><span><?php esc_html_e( 'Add PC Switcher', 'multi-device-switcher' ); ?></span></legend> | |
| 1230 | + <label><input type="checkbox" name="multi_device_switcher_options[pc_switcher]" id="pc-switcher" value="1"<?php checked( 1, $options['pc_switcher'] ); ?>> <?php esc_html_e( 'Add a PC Switcher to the footer.', 'multi-device-switcher' ); ?></label> | |
| 1231 | + </td> | |
| 1232 | + </tr> | |
| 1233 | + <tr><th scope="row"><?php esc_html_e( 'Add default CSS', 'multi-device-switcher' ); ?></th> | |
| 1234 | + <td> | |
| 1235 | + <legend class="screen-reader-text"><span><?php esc_html_e( 'Add default CSS', 'multi-device-switcher' ); ?></span></legend> | |
| 1236 | + <label><input type="checkbox" name="multi_device_switcher_options[default_css]" id="add-default-css" value="1"<?php checked( 1, $options['default_css'] ); ?>> <?php esc_html_e( 'Add a default CSS.', 'multi-device-switcher' ); ?></label> | |
| 1237 | + </td> | |
| 1238 | + </tr> | |
| 1239 | +</table> | |
| 1240 | +</fieldset> | |
| 802 | 1241 | |
| 803 | - <fieldset id="Disable-Switcher" class="options"> | |
| 804 | - <h3 class="label"><?php _e( 'Disable Switcher', 'multi-device-switcher' ); ?></h3> | |
| 1242 | +<fieldset id="Disable-Switcher" class="options"> | |
| 1243 | +<h3 class="label"><?php esc_html_e( 'Disable Switcher', 'multi-device-switcher' ); ?></h3> | |
| 805 | 1244 | |
| 806 | - <table class="form-table"> | |
| 807 | - <tr><th scope="row"><?php _e( 'Path', 'multi-device-switcher' ); ?></th> | |
| 808 | - <td> | |
| 809 | - <legend class="screen-reader-text"><span><?php _e( 'Path', 'multi-device-switcher' ); ?></span></legend> | |
| 810 | - <?php echo esc_html( home_url() ); ?> | |
| 811 | - <textarea name="multi_device_switcher_options[disable_path]" rows="16" cols="42" wrap="off"><?php echo esc_textarea( $options['disable_path'] ); ?></textarea> | |
| 812 | - </td> | |
| 813 | - </tr> | |
| 814 | - <tr><th scope="row"><?php _e( 'Regex mode', 'multi-device-switcher' ); ?></th> | |
| 815 | - <td> | |
| 816 | - <legend class="screen-reader-text"><span><?php _e( 'Regex mode', 'multi-device-switcher' ); ?></span></legend> | |
| 817 | - <label><input type="checkbox" name="multi_device_switcher_options[enable_regex]" id="enable-regex" value="1"<?php checked( 1, $options['enable_regex'] ); ?>> <?php _e( 'Enable Regex', 'multi-device-switcher' ); ?></label> | |
| 818 | - </td> | |
| 819 | - </tr> | |
| 820 | - </table> | |
| 821 | - </fieldset> | |
| 1245 | +<table class="form-table"> | |
| 1246 | + <tr><th scope="row"><?php esc_html_e( 'Path', 'multi-device-switcher' ); ?></th> | |
| 1247 | + <td> | |
| 1248 | + <legend class="screen-reader-text"><span><?php esc_html_e( 'Path', 'multi-device-switcher' ); ?></span></legend> | |
| 1249 | + <?php echo esc_html( home_url() ); ?><br> | |
| 1250 | + <textarea name="multi_device_switcher_options[disable_path]" rows="16" cols="42" wrap="off"><?php echo esc_textarea( $options['disable_path'] ); ?></textarea> | |
| 1251 | + </td> | |
| 1252 | + </tr> | |
| 1253 | + <tr><th scope="row"><?php esc_html_e( 'Regex mode', 'multi-device-switcher' ); ?></th> | |
| 1254 | + <td> | |
| 1255 | + <legend class="screen-reader-text"><span><?php esc_html_e( 'Regex mode', 'multi-device-switcher' ); ?></span></legend> | |
| 1256 | + <label><input type="checkbox" name="multi_device_switcher_options[enable_regex]" id="enable-regex" value="1"<?php checked( 1, $options['enable_regex'] ); ?>> <?php esc_html_e( 'Enable Regex', 'multi-device-switcher' ); ?></label> | |
| 1257 | + </td> | |
| 1258 | + </tr> | |
| 1259 | +</table> | |
| 1260 | +</fieldset> | |
| 822 | 1261 | |
| 823 | - </div> | |
| 824 | - <?php submit_button(); ?> | |
| 825 | - </form> | |
| 826 | - </div> | |
| 827 | - | |
| 828 | - <div id="donate"> | |
| 829 | - <h2><?php _e( 'Donationware', 'multi-device-switcher' ); ?></h2> | |
| 830 | - <p><?php _e( 'If you like this plugin, please donate to support development and maintenance.', 'multi-device-switcher' ); ?></p> | |
| 831 | -<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> | |
| 832 | -<input type="hidden" name="cmd" value="_s-xclick"> | |
| 833 | -<input type="hidden" name="hosted_button_id" value="9L53NELFMHTWW"> | |
| 834 | -<table> | |
| 835 | -<tr><td><input type="hidden" name="on0" value="Donationware">Donationware</td></tr><tr><td><select name="os0"> | |
| 836 | - <option value="1. Donate">1. Donate $3.00 USD</option> | |
| 837 | - <option value="2. Donate">2. Donate $5.00 USD</option> | |
| 838 | - <option value="3. Donate">3. Donate $7.00 USD</option> | |
| 839 | - <option value="4. Donate" selected="selected">4. Donate $10.00 USD</option> | |
| 840 | - <option value="5. Donate">5. Donate $20.00 USD</option> | |
| 841 | - <option value="6. Donate">6. Donate $30.00 USD</option> | |
| 842 | - <option value="7. Donate">7. Donate $40.00 USD</option> | |
| 843 | - <option value="8. Donate">8. Donate $50.00 USD</option> | |
| 844 | - <option value="9. Donate">9. Donate $60.00 USD</option> | |
| 845 | - <option value="10. Donate">10. Donate $70.00 USD</option> | |
| 846 | -</select> </td></tr> | |
| 847 | -</table> | |
| 848 | -<input type="hidden" name="currency_code" value="USD"> | |
| 849 | -<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"> | |
| 850 | -<img alt="" border="0" src="https://www.paypalobjects.com/ja_JP/i/scr/pixel.gif" width="1" height="1"> | |
| 1262 | +</div> | |
| 1263 | + <?php submit_button(); ?> | |
| 851 | 1264 | </form> |
| 852 | - </div> | |
| 1265 | +</div> | |
| 853 | 1266 | |
| 854 | - <?php | |
| 855 | -} | |
| 1267 | + <?php | |
| 1268 | + } | |
| 856 | 1269 | |
| 857 | -/** | |
| 858 | - * Sanitize and validate form input. Accepts an array, return a sanitized array. | |
| 859 | - * | |
| 860 | - * @see multi_device_switcher_init() | |
| 861 | - * | |
| 862 | - * @since 1.0 | |
| 863 | - */ | |
| 864 | -function multi_device_switcher_validate( $input ) { | |
| 865 | - $output = $default_options = multi_device_switcher_get_default_options(); | |
| 1270 | + /** | |
| 1271 | + * Validate options. | |
| 1272 | + * | |
| 1273 | + * @access public | |
| 1274 | + * | |
| 1275 | + * @param array $input | |
| 1276 | + * | |
| 1277 | + * @return array | |
| 1278 | + */ | |
| 1279 | + public function validate_options( $input ) { | |
| 1280 | + $output = $this->default_options; | |
| 866 | 1281 | |
| 867 | - if ( isset( $input['theme_smartphone'] ) ) { | |
| 868 | - $output['theme_smartphone'] = $input['theme_smartphone']; | |
| 869 | - } | |
| 870 | - if ( isset( $input['theme_tablet'] ) ) { | |
| 871 | - $output['theme_tablet'] = $input['theme_tablet']; | |
| 872 | - } | |
| 873 | - if ( isset( $input['theme_mobile'] ) ) { | |
| 874 | - $output['theme_mobile'] = $input['theme_mobile']; | |
| 875 | - } | |
| 876 | - if ( isset( $input['theme_game'] ) ) { | |
| 877 | - $output['theme_game'] = $input['theme_game']; | |
| 878 | - } | |
| 879 | - | |
| 880 | - if ( isset( $input['restore_UserAgent'] ) ) { | |
| 881 | - $output['userAgent_smart'] = $default_options['userAgent_smart']; | |
| 882 | - $output['userAgent_tablet'] = $default_options['userAgent_tablet']; | |
| 883 | - $output['userAgent_mobile'] = $default_options['userAgent_mobile']; | |
| 884 | - $output['userAgent_game'] = $default_options['userAgent_game']; | |
| 885 | - } | |
| 886 | - else { | |
| 887 | - if ( isset( $input['userAgent_smart'] ) ) { | |
| 888 | - $output['userAgent_smart'] = $input['userAgent_smart']; | |
| 1282 | + if ( isset( $input['theme_smartphone'] ) ) { | |
| 1283 | + $output['theme_smartphone'] = $input['theme_smartphone']; | |
| 889 | 1284 | } |
| 890 | - if ( isset( $input['userAgent_tablet'] ) ) { | |
| 891 | - $output['userAgent_tablet'] = $input['userAgent_tablet']; | |
| 1285 | + if ( isset( $input['theme_tablet'] ) ) { | |
| 1286 | + $output['theme_tablet'] = $input['theme_tablet']; | |
| 892 | 1287 | } |
| 893 | - if ( isset( $input['userAgent_mobile'] ) ) { | |
| 894 | - $output['userAgent_mobile'] = $input['userAgent_mobile']; | |
| 1288 | + if ( isset( $input['theme_mobile'] ) ) { | |
| 1289 | + $output['theme_mobile'] = $input['theme_mobile']; | |
| 895 | 1290 | } |
| 896 | - if ( isset( $input['userAgent_game'] ) ) { | |
| 897 | - $output['userAgent_game'] = $input['userAgent_game']; | |
| 1291 | + if ( isset( $input['theme_game'] ) ) { | |
| 1292 | + $output['theme_game'] = $input['theme_game']; | |
| 898 | 1293 | } |
| 899 | - } | |
| 900 | 1294 | |
| 901 | - foreach ( $input as $key => $val ) { | |
| 902 | - if ( ! preg_match( '/^custom_switcher_theme_/', $key ) ) { | |
| 903 | - continue; | |
| 1295 | + if ( isset( $input['restore_UserAgent'] ) ) { | |
| 1296 | + $output['userAgent_smart'] = $this->default_options['userAgent_smart']; | |
| 1297 | + $output['userAgent_tablet'] = $this->default_options['userAgent_tablet']; | |
| 1298 | + $output['userAgent_mobile'] = $this->default_options['userAgent_mobile']; | |
| 1299 | + $output['userAgent_game'] = $this->default_options['userAgent_game']; | |
| 904 | 1300 | } |
| 1301 | + else { | |
| 1302 | + if ( isset( $input['userAgent_smart'] ) ) { | |
| 1303 | + $output['userAgent_smart'] = $input['userAgent_smart']; | |
| 1304 | + } | |
| 1305 | + if ( isset( $input['userAgent_tablet'] ) ) { | |
| 1306 | + $output['userAgent_tablet'] = $input['userAgent_tablet']; | |
| 1307 | + } | |
| 1308 | + if ( isset( $input['userAgent_mobile'] ) ) { | |
| 1309 | + $output['userAgent_mobile'] = $input['userAgent_mobile']; | |
| 1310 | + } | |
| 1311 | + if ( isset( $input['userAgent_game'] ) ) { | |
| 1312 | + $output['userAgent_game'] = $input['userAgent_game']; | |
| 1313 | + } | |
| 1314 | + } | |
| 905 | 1315 | |
| 906 | - $custom_switcher_name = preg_replace( '/^custom_switcher_theme_/', '', $key ); | |
| 1316 | + foreach ( $input as $key => $val ) { | |
| 1317 | + if ( ! preg_match( '/^custom_switcher_theme_/', $key ) ) { | |
| 1318 | + continue; | |
| 1319 | + } | |
| 907 | 1320 | |
| 908 | - if ( isset( $input[ 'custom_switcher_theme_' . $custom_switcher_name ] ) ) { | |
| 909 | - $output[ 'custom_switcher_theme_' . $custom_switcher_name ] = $input[ 'custom_switcher_theme_' . $custom_switcher_name ]; | |
| 1321 | + $custom_switcher_name = preg_replace( '/^custom_switcher_theme_/', '', $key ); | |
| 1322 | + | |
| 1323 | + if ( isset( $input[ 'custom_switcher_theme_' . $custom_switcher_name ] ) ) { | |
| 1324 | + $output[ 'custom_switcher_theme_' . $custom_switcher_name ] = $input[ 'custom_switcher_theme_' . $custom_switcher_name ]; | |
| 1325 | + } | |
| 1326 | + if ( isset( $input[ 'custom_switcher_userAgent_' . $custom_switcher_name ] ) ) { | |
| 1327 | + $output[ 'custom_switcher_userAgent_' . $custom_switcher_name ] = $input[ 'custom_switcher_userAgent_' . $custom_switcher_name ]; | |
| 1328 | + } | |
| 910 | 1329 | } |
| 911 | - if ( isset( $input[ 'custom_switcher_userAgent_' . $custom_switcher_name ] ) ) { | |
| 912 | - $output[ 'custom_switcher_userAgent_' . $custom_switcher_name ] = $input[ 'custom_switcher_userAgent_' . $custom_switcher_name ]; | |
| 1330 | + | |
| 1331 | + foreach ( $input as $key => $val ) { | |
| 1332 | + if ( ! preg_match( '/^delete_custom_switcher_/', $key ) ) { | |
| 1333 | + continue; | |
| 1334 | + } | |
| 1335 | + | |
| 1336 | + $custom_switcher_name = preg_replace( '/^delete_custom_switcher_/', '', $key ); | |
| 1337 | + | |
| 1338 | + unset( $output[ 'custom_switcher_theme_' . $custom_switcher_name ] ); | |
| 1339 | + unset( $output[ 'custom_switcher_userAgent_' . $custom_switcher_name ] ); | |
| 913 | 1340 | } |
| 914 | - } | |
| 915 | 1341 | |
| 916 | - foreach ( $input as $key => $val ) { | |
| 917 | - if ( ! preg_match( '/^delete_custom_switcher_/', $key ) ) { | |
| 918 | - continue; | |
| 1342 | + if ( isset( $input['add_custom_switcher'] ) && ! empty( $input['custom_switcher'] ) && ! isset( $output[ 'custom_switcher_theme_' . $input['custom_switcher'] ] ) ) { | |
| 1343 | + if ( ! in_array( $input['custom_switcher'], array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ), true ) | |
| 1344 | + && preg_match( '/^[A-Za-z0-9]{1,20}$/', $input['custom_switcher'] ) ) { | |
| 1345 | + $output[ 'custom_switcher_theme_' . $input['custom_switcher'] ] = 'None'; | |
| 1346 | + $output[ 'custom_switcher_userAgent_' . $input['custom_switcher'] ] = ''; | |
| 1347 | + } | |
| 919 | 1348 | } |
| 920 | 1349 | |
| 921 | - $custom_switcher_name = preg_replace( '/^delete_custom_switcher_/', '', $key ); | |
| 1350 | + $output['pc_switcher'] = isset( $input['pc_switcher'] ) ? $input['pc_switcher'] : 0; | |
| 1351 | + $output['default_css'] = isset( $input['default_css'] ) ? $input['default_css'] : 0; | |
| 922 | 1352 | |
| 923 | - unset( $output[ 'custom_switcher_theme_' . $custom_switcher_name ] ); | |
| 924 | - unset( $output[ 'custom_switcher_userAgent_' . $custom_switcher_name ] ); | |
| 1353 | + $output['disable_path'] = isset( $input['disable_path'] ) ? $input['disable_path'] : ''; | |
| 1354 | + $output['enable_regex'] = isset( $input['enable_regex'] ) ? $input['enable_regex'] : 0; | |
| 1355 | + | |
| 1356 | + /** | |
| 1357 | + * Filter hook: multi_device_switcher/validate_options. | |
| 1358 | + * | |
| 1359 | + * @param array $options The options. | |
| 1360 | + * @param array $input The options. | |
| 1361 | + * @param array $default The options. | |
| 1362 | + * | |
| 1363 | + * @since 1.7.0 | |
| 1364 | + */ | |
| 1365 | + return apply_filters( 'multi_device_switcher/validate_options', $output, $input, $this->default_options ); | |
| 925 | 1366 | } |
| 926 | 1367 | |
| 927 | - if ( isset( $input['add_custom_switcher'] ) && ! empty( $input['custom_switcher'] ) && ! $output[ 'custom_switcher_theme_' . $input['custom_switcher'] ] ) { | |
| 928 | - if ( ! in_array( $input['custom_switcher'], array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ) ) | |
| 929 | - && preg_match( '/^[A-Za-z0-9]{1,20}$/', $input['custom_switcher'] ) ) { | |
| 930 | - $output[ 'custom_switcher_theme_' . $input['custom_switcher'] ] = 'None'; | |
| 931 | - $output[ 'custom_switcher_userAgent_' . $input['custom_switcher'] ] = ''; | |
| 932 | - } | |
| 933 | - } | |
| 1368 | + /** | |
| 1369 | + * Register customize options to Customizer. | |
| 1370 | + * | |
| 1371 | + * @access public | |
| 1372 | + * | |
| 1373 | + * @param object $wp_customize | |
| 1374 | + * | |
| 1375 | + * @return void | |
| 1376 | + * | |
| 1377 | + * @since 1.3.1 | |
| 1378 | + */ | |
| 1379 | + public function customizer( $wp_customize ) { | |
| 1380 | + $options = $this->get_options(); | |
| 1381 | + $default_theme_options = $this->default_options; | |
| 1382 | + $default_theme = wp_get_theme()->get( 'Name' ); | |
| 1383 | + $themes = wp_get_themes(); | |
| 934 | 1384 | |
| 935 | - $output['pc_switcher'] = isset( $input['pc_switcher'] ) ? $input['pc_switcher'] : 0; | |
| 936 | - $output['default_css'] = isset( $input['default_css'] ) ? $input['default_css'] : 0; | |
| 1385 | + $theme_names = array(); | |
| 1386 | + $choices = array(); | |
| 937 | 1387 | |
| 938 | - $output['disable_path'] = isset( $input['disable_path'] ) ? $input['disable_path'] : ''; | |
| 939 | - $output['enable_regex'] = isset( $input['enable_regex'] ) ? $input['enable_regex'] : 0; | |
| 1388 | + if ( count( $themes ) ) { | |
| 1389 | + foreach ( $themes as $t ) { | |
| 1390 | + $theme_names[] = $t->get( 'Name' ); | |
| 1391 | + } | |
| 1392 | + natcasesort( $theme_names ); | |
| 940 | 1393 | |
| 941 | - return apply_filters( 'multi_device_switcher_validate', $output, $input, $default_options ); | |
| 942 | -} | |
| 1394 | + $choices['None'] = __( 'None', 'multi-device-switcher' ); | |
| 1395 | + foreach ( $theme_names as $theme_name ) { | |
| 1396 | + if ( $default_theme === $theme_name ) { | |
| 1397 | + continue; | |
| 1398 | + } | |
| 1399 | + $choices[ $theme_name ] = $theme_name; | |
| 1400 | + } | |
| 1401 | + } | |
| 943 | 1402 | |
| 944 | -/** | |
| 945 | - * plugin customization options | |
| 946 | - * | |
| 947 | - * @param $wp_customize Theme Customizer object | |
| 948 | - * @return void | |
| 949 | - * | |
| 950 | - * @since 1.3.1 | |
| 951 | - */ | |
| 952 | -function multi_device_switcher_customize_register( $wp_customize ) { | |
| 953 | - load_plugin_textdomain( 'multi-device-switcher', false, 'multi-device-switcher/languages' ); | |
| 954 | - $options = multi_device_switcher_get_options(); | |
| 955 | - $default_theme_options = multi_device_switcher_get_default_options(); | |
| 956 | - $default_theme = wp_get_theme()->get( 'Name' ); | |
| 957 | - $themes = wp_get_themes(); | |
| 1403 | + $switcher = array( | |
| 1404 | + 'theme_smartphone' => __( 'Smart Phone Theme', 'multi-device-switcher' ), | |
| 1405 | + 'theme_tablet' => __( 'Tablet PC Theme', 'multi-device-switcher' ), | |
| 1406 | + 'theme_mobile' => __( 'Mobile Phone Theme', 'multi-device-switcher' ), | |
| 1407 | + 'theme_game' => __( 'Game Platforms Theme', 'multi-device-switcher' ), | |
| 1408 | + ); | |
| 958 | 1409 | |
| 959 | - $theme_names = array(); | |
| 960 | - $choices = array(); | |
| 1410 | + $wp_customize->add_section( | |
| 1411 | + 'multi_device_switcher', | |
| 1412 | + array( | |
| 1413 | + 'title' => __( 'Multi Device Switcher', 'multi-device-switcher' ), | |
| 1414 | + 'priority' => 80, | |
| 1415 | + ) | |
| 1416 | + ); | |
| 961 | 1417 | |
| 962 | - if ( count( $themes ) ) { | |
| 963 | - foreach ( $themes as $t ) { | |
| 964 | - $theme_names[] = $t->get( 'Name' ); | |
| 1418 | + foreach ( $switcher as $name => $label ) { | |
| 1419 | + $wp_customize->add_setting( | |
| 1420 | + 'multi_device_switcher_options[' . $name . ']', | |
| 1421 | + array( | |
| 1422 | + 'default' => $default_theme_options[ $name ], | |
| 1423 | + 'type' => 'option', | |
| 1424 | + 'capability' => $this->capability, | |
| 1425 | + ) | |
| 1426 | + ); | |
| 1427 | + | |
| 1428 | + $wp_customize->add_control( | |
| 1429 | + 'multi_device_switcher_options[' . $name . ']', | |
| 1430 | + array( | |
| 1431 | + 'label' => $label, | |
| 1432 | + 'section' => 'multi_device_switcher', | |
| 1433 | + 'type' => 'select', | |
| 1434 | + 'choices' => $choices, | |
| 1435 | + ) | |
| 1436 | + ); | |
| 965 | 1437 | } |
| 966 | - natcasesort( $theme_names ); | |
| 967 | 1438 | |
| 968 | - $choices['None'] = __( 'None', 'multi-device-switcher' ); | |
| 969 | - foreach ( $theme_names as $theme_name ) { | |
| 970 | - if ( $default_theme == $theme_name ) { | |
| 1439 | + foreach ( (array) $options as $custom_switcher_option => $custom_switcher_theme ) { | |
| 1440 | + if ( ! preg_match( '/^custom_switcher_theme_/', $custom_switcher_option ) ) { | |
| 971 | 1441 | continue; |
| 972 | 1442 | } |
| 973 | - $choices[ $theme_name ] = $theme_name; | |
| 974 | - } | |
| 975 | - } | |
| 976 | 1443 | |
| 977 | - $switcher = array( | |
| 978 | - 'theme_smartphone' => __( 'Smart Phone Theme', 'multi-device-switcher' ), | |
| 979 | - 'theme_tablet' => __( 'Tablet PC Theme', 'multi-device-switcher' ), | |
| 980 | - 'theme_mobile' => __( 'Mobile Phone Theme', 'multi-device-switcher' ), | |
| 981 | - 'theme_game' => __( 'Game Platforms Theme', 'multi-device-switcher' ), | |
| 982 | - ); | |
| 1444 | + $label = preg_replace( '/^custom_switcher_theme_/', '', $custom_switcher_option ); | |
| 983 | 1445 | |
| 984 | - $wp_customize->add_section( 'multi_device_switcher', array( | |
| 985 | - 'title' => __( 'Multi Device Switcher', 'multi-device-switcher' ), | |
| 986 | - 'priority' => 80, | |
| 987 | - ) ); | |
| 1446 | + $wp_customize->add_setting( | |
| 1447 | + 'multi_device_switcher_options[' . $custom_switcher_option . ']', | |
| 1448 | + array( | |
| 1449 | + 'default' => __( 'None', 'multi-device-switcher' ), | |
| 1450 | + 'type' => 'option', | |
| 1451 | + 'capability' => $this->capability, | |
| 1452 | + ) | |
| 1453 | + ); | |
| 988 | 1454 | |
| 989 | - foreach ( $switcher as $name => $label ) { | |
| 990 | - $wp_customize->add_setting( 'multi_device_switcher_options[' . $name . ']', array( | |
| 991 | - 'default' => $default_theme_options[ $name ], | |
| 992 | - 'type' => 'option', | |
| 993 | - 'capability' => 'edit_theme_options', | |
| 994 | - ) ); | |
| 1455 | + $wp_customize->add_control( | |
| 1456 | + 'multi_device_switcher_options[' . $custom_switcher_option . ']', | |
| 1457 | + array( | |
| 1458 | + 'label' => $label, | |
| 1459 | + 'section' => 'multi_device_switcher', | |
| 1460 | + 'type' => 'select', | |
| 1461 | + 'choices' => $choices, | |
| 1462 | + ) | |
| 1463 | + ); | |
| 995 | 1464 | |
| 996 | - $wp_customize->add_control( 'multi_device_switcher_options[' . $name . ']', array( | |
| 997 | - 'label' => $label, | |
| 998 | - 'section' => 'multi_device_switcher', | |
| 999 | - 'type' => 'select', | |
| 1000 | - 'choices' => $choices, | |
| 1001 | - ) ); | |
| 1465 | + } | |
| 1002 | 1466 | } |
| 1003 | 1467 | |
| 1004 | - foreach ( $options as $custom_switcher_option => $custom_switcher_theme ) { | |
| 1005 | - if ( ! preg_match( '/^custom_switcher_theme_/', $custom_switcher_option ) ) { | |
| 1006 | - continue; | |
| 1468 | + /** | |
| 1469 | + * Load files. | |
| 1470 | + * | |
| 1471 | + * @access public | |
| 1472 | + * | |
| 1473 | + * @since 1.0.0 | |
| 1474 | + */ | |
| 1475 | + public function load_file() { | |
| 1476 | + /** | |
| 1477 | + * Include PC Switcher Widget. | |
| 1478 | + * | |
| 1479 | + * @since 1.2 | |
| 1480 | + */ | |
| 1481 | + require_once dirname( __MULTI_DEVICE_SWITCHER_FILE__ ) . '/pc-switcher-widget.php'; | |
| 1482 | + | |
| 1483 | + /** | |
| 1484 | + * Include Multi Device Switcher Command | |
| 1485 | + * | |
| 1486 | + * @since 1.4 | |
| 1487 | + */ | |
| 1488 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { | |
| 1489 | + require_once dirname( __MULTI_DEVICE_SWITCHER_FILE__ ) . '/wp-cli.php'; | |
| 1007 | 1490 | } |
| 1491 | + } | |
| 1492 | +} | |
| 1008 | 1493 | |
| 1009 | - $label = preg_replace( '/^custom_switcher_theme_/', '', $custom_switcher_option ); | |
| 1494 | +define( '__MULTI_DEVICE_SWITCHER_FILE__', __FILE__ ); | |
| 1010 | 1495 | |
| 1011 | - $wp_customize->add_setting( 'multi_device_switcher_options[' . $custom_switcher_option . ']', array( | |
| 1012 | - 'default' => __( 'None', 'multi-device-switcher' ), | |
| 1013 | - 'type' => 'option', | |
| 1014 | - 'capability' => 'edit_theme_options', | |
| 1015 | - ) ); | |
| 1496 | +if ( class_exists( 'Multi_Device_Switcher' ) ) { | |
| 1497 | + global $multi_device_switcher; | |
| 1498 | + $multi_device_switcher = new Multi_Device_Switcher(); | |
| 1499 | +} | |
| 1016 | 1500 | |
| 1017 | - $wp_customize->add_control( 'multi_device_switcher_options[' . $custom_switcher_option . ']', array( | |
| 1018 | - 'label' => $label, | |
| 1019 | - 'section' => 'multi_device_switcher', | |
| 1020 | - 'type' => 'select', | |
| 1021 | - 'choices' => $choices, | |
| 1022 | - ) ); | |
| 1501 | +/** | |
| 1502 | + * Add PC Switcher. | |
| 1503 | + * | |
| 1504 | + * @since 1.2 | |
| 1505 | + */ | |
| 1506 | +function multi_device_switcher_add_pc_switcher() { | |
| 1507 | + global $multi_device_switcher; | |
| 1508 | + if ( is_object( $multi_device_switcher ) ) { | |
| 1509 | + $multi_device_switcher->add_pc_switcher( 1 ); | |
| 1510 | + } | |
| 1511 | +} | |
| 1023 | 1512 | |
| 1513 | +/** | |
| 1514 | + * Return boolean whether a particular device. | |
| 1515 | + * | |
| 1516 | + * @since 1.2.4 | |
| 1517 | + */ | |
| 1518 | +if ( ! function_exists( 'is_multi_device' ) ) : | |
| 1519 | + | |
| 1520 | + function is_multi_device( $device = '' ) { | |
| 1521 | + global $multi_device_switcher; | |
| 1522 | + if ( is_object( $multi_device_switcher ) ) { | |
| 1523 | + return $multi_device_switcher->is_multi_device( $device ); | |
| 1524 | + } | |
| 1024 | 1525 | } |
| 1025 | -} | |
| 1526 | +endif; | |
| 1026 | 1527 | |
| 1027 | -add_action( 'customize_register', 'multi_device_switcher_customize_register' ); | |
| 1528 | +/** | |
| 1529 | + * Return the state of PC Switcher. | |
| 1530 | + * | |
| 1531 | + * @since 1.4.1 | |
| 1532 | + */ | |
| 1533 | +if ( ! function_exists( 'is_pc_switcher' ) ) : | |
| 1028 | 1534 | |
| 1535 | + function is_pc_switcher() { | |
| 1536 | + global $multi_device_switcher; | |
| 1537 | + if ( is_object( $multi_device_switcher ) ) { | |
| 1538 | + return $multi_device_switcher->is_pc_switcher(); | |
| 1539 | + } | |
| 1540 | + } | |
| 1541 | +endif; | |
| 1542 | + | |
| 1029 | 1543 | /** |
| 1030 | - * include PC Switcher Widget. | |
| 1544 | + * Return the state of disabled. | |
| 1031 | 1545 | * |
| 1032 | - * @since 1.2 | |
| 1546 | + * @since 1.4.1 | |
| 1033 | 1547 | */ |
| 1034 | -require_once( dirname( __FILE__ ) . '/pc-switcher-widget.php' ); | |
| 1548 | +if ( ! function_exists( 'is_disable_switcher' ) ) : | |
| 1035 | 1549 | |
| 1550 | + function is_disable_switcher() { | |
| 1551 | + global $multi_device_switcher; | |
| 1552 | + if ( is_object( $multi_device_switcher ) ) { | |
| 1553 | + return $multi_device_switcher->is_disable_switcher(); | |
| 1554 | + } | |
| 1555 | + } | |
| 1556 | +endif; | |
| 1557 | + | |
| 1036 | 1558 | /** |
| 1037 | - * include Multi Device Switcher Command | |
| 1559 | + * Returns the default options. | |
| 1038 | 1560 | * |
| 1039 | - * @since 1.4 | |
| 1561 | + * @since 1.5.3 | |
| 1040 | 1562 | */ |
| 1041 | -if ( defined( 'WP_CLI' ) && WP_CLI ) { | |
| 1042 | - require_once( dirname( __FILE__ ) . '/wp-cli.php' ); | |
| 1043 | -} | |
| 1563 | +if ( ! function_exists( 'multi_device_switcher_get_default_options' ) ) : | |
| 1044 | 1564 | |
| 1045 | -?> | |
| 1565 | + function multi_device_switcher_get_default_options() { | |
| 1566 | + global $multi_device_switcher; | |
| 1567 | + if ( is_object( $multi_device_switcher ) ) { | |
| 1568 | + return $multi_device_switcher->get_default_options(); | |
| 1569 | + } | |
| 1570 | + } | |
| 1571 | +endif; | |