Version Description
- add test case for cdn
- add multi_device_switcher/detect_device action hook
- split switch_theme method into detect_device and switch_theme
- fix wp-cli
- add bats test case for cli
- refactoring with phpstan
- fix default options via method
- change tag name
- change method name
- improve get_options method
- replace from get_default_options() to class value default_options
- fix not valid snake_case format
- add public as access modifier keywords
- add PHPDoc
- add reset-wp-tests.sh, uninstall-wp-tests.sh
- fix header
- fix textdomain
- fix indent and reformat with phpcs and phpcbf
- add composer.json for test
- add static code analysis config
Download this release
Release Info
Developer | thingsym |
Plugin | Multi Device Switcher |
Version | 1.7.0 |
Comparing to | |
See all releases |
Code changes from version 1.6.2 to 1.7.0
- README.md +34 -0
- multi-device-switcher.php +808 -520
- pc-switcher-widget.php +17 -27
- readme.txt +36 -5
- uninstall.php +14 -2
- wp-cli.php +75 -58
README.md
CHANGED
@@ -287,6 +287,19 @@ None
|
|
287 |
|
288 |
(boolean) Return the state of disabled.
|
289 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
## Multi Device Switcher Command
|
291 |
|
292 |
The **Multi Device Switcher Command** is command-line tool.
|
@@ -396,6 +409,27 @@ Small patches and bug reports can be submitted a issue tracker in Github. Forkin
|
|
396 |
|
397 |
## Changelog
|
398 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
399 |
* Version 1.6.2
|
400 |
* add prefix into hook tag, change tag name from add_header_vary to multi_device_switcher_add_header_vary
|
401 |
* for php5.3, change called function via hook from anonymous function to public function
|
287 |
|
288 |
(boolean) Return the state of disabled.
|
289 |
|
290 |
+
## Hooks
|
291 |
+
|
292 |
+
### Filter hooks
|
293 |
+
|
294 |
+
* multi_device_switcher/get_options
|
295 |
+
* multi_device_switcher/get_option
|
296 |
+
* multi_device_switcher/add_header_vary
|
297 |
+
* multi_device_switcher/validate_options
|
298 |
+
|
299 |
+
### Action hooks
|
300 |
+
|
301 |
+
* multi_device_switcher/detect_device
|
302 |
+
|
303 |
## Multi Device Switcher Command
|
304 |
|
305 |
The **Multi Device Switcher Command** is command-line tool.
|
409 |
|
410 |
## Changelog
|
411 |
|
412 |
+
* Version 1.7.0
|
413 |
+
* add test case for cdn
|
414 |
+
* add multi_device_switcher/detect_device action hook
|
415 |
+
* split switch_theme method into detect_device and switch_theme
|
416 |
+
* fix wp-cli
|
417 |
+
* add bats test case for cli
|
418 |
+
* refactoring with phpstan
|
419 |
+
* fix default options via method
|
420 |
+
* change tag name
|
421 |
+
* change method name
|
422 |
+
* improve get_options method
|
423 |
+
* replace from get_default_options() to class value default_options
|
424 |
+
* fix not valid snake_case format
|
425 |
+
* add public as access modifier keywords
|
426 |
+
* add PHPDoc
|
427 |
+
* add reset-wp-tests.sh, uninstall-wp-tests.sh
|
428 |
+
* fix header
|
429 |
+
* fix textdomain
|
430 |
+
* fix indent and reformat with phpcs and phpcbf
|
431 |
+
* add composer.json for test
|
432 |
+
* add static code analysis config
|
433 |
* Version 1.6.2
|
434 |
* add prefix into hook tag, change tag name from add_header_vary to multi_device_switcher_add_header_vary
|
435 |
* for php5.3, change called function via hook from anonymous function to public function
|
multi-device-switcher.php
CHANGED
@@ -1,65 +1,150 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin Name: Multi Device Switcher
|
4 |
-
* Plugin URI:
|
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:
|
7 |
-
* Author:
|
8 |
-
* Author URI:
|
9 |
-
* License:
|
|
|
10 |
* Text Domain: multi-device-switcher
|
11 |
* Domain Path: /languages/
|
12 |
-
*/
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Copyright 2012 thingsym (http://www.thingslabo.com/)
|
16 |
-
*
|
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 |
-
*
|
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.
|
26 |
-
*
|
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 |
*/
|
31 |
|
32 |
if ( ! defined( 'ABSPATH' ) ) {
|
33 |
exit;
|
34 |
}
|
35 |
|
|
|
|
|
|
|
|
|
|
|
36 |
class Multi_Device_Switcher {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
protected $option_group = 'multi_device_switcher';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
protected $option_name = 'multi_device_switcher_options';
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
43 |
protected $capability = 'switch_themes';
|
44 |
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
47 |
protected $cookie_name_multi_device_switcher = 'multi-device-switcher';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
protected $cookie_name_disable_switcher = 'disable-switcher';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
protected $cookie_name_pc_switcher = 'pc-switcher';
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
public $device = '';
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
public function __construct() {
|
54 |
add_action( 'init', array( $this, 'load_textdomain' ) );
|
55 |
add_action( 'init', array( $this, 'init' ) );
|
56 |
|
57 |
if ( ! is_admin() ) {
|
58 |
add_filter( 'wp_headers', array( $this, 'add_header_vary' ) );
|
|
|
59 |
add_action( 'plugins_loaded', array( $this, 'switch_theme' ) );
|
60 |
}
|
61 |
|
62 |
-
add_action( 'admin_init', array( $this, '
|
63 |
add_action( 'admin_menu', array( $this, 'add_option_page' ) );
|
64 |
add_action( 'customize_register', array( $this, 'customize_register' ) );
|
65 |
add_action( 'plugins_loaded', array( $this, 'load_file' ) );
|
@@ -81,54 +166,81 @@ class Multi_Device_Switcher {
|
|
81 |
add_shortcode( 'multi', array( $this, 'shortcode_display_switcher' ) );
|
82 |
}
|
83 |
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
if ( isset( $_COOKIE[ $this->cookie_name_disable_switcher ] ) ) {
|
86 |
-
add_action( 'wp_headers', array( $this, 'set_cookie_rest_disable_switcher' ));
|
87 |
}
|
88 |
|
89 |
if ( $this->is_disable_switcher() ) {
|
90 |
-
add_action( 'wp_headers', array( $this, 'set_cookie_enable_disable_switcher' ));
|
91 |
return;
|
92 |
}
|
93 |
|
94 |
add_action( 'init', array( $this, 'session' ) );
|
95 |
|
96 |
-
$
|
97 |
-
$
|
98 |
|
99 |
-
foreach ( array_reverse( $
|
100 |
if ( ! preg_match( '/^custom_switcher_/', $key ) ) {
|
101 |
continue;
|
102 |
}
|
103 |
-
if ( $
|
104 |
$this->device = $key;
|
105 |
break;
|
106 |
}
|
107 |
}
|
108 |
|
109 |
if ( ! $this->device ) {
|
110 |
-
if ( $
|
111 |
$this->device = 'game';
|
112 |
}
|
113 |
-
elseif ( $
|
114 |
$this->device = 'tablet';
|
115 |
}
|
116 |
-
elseif ( $
|
117 |
$this->device = 'smart';
|
118 |
}
|
119 |
-
elseif ( $
|
120 |
$this->device = 'mobile';
|
121 |
}
|
122 |
}
|
123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
if ( $this->device ) {
|
125 |
add_filter( 'stylesheet', array( $this, 'get_stylesheet' ) );
|
126 |
add_filter( 'template', array( $this, 'get_template' ) );
|
127 |
add_action( 'wp_footer', array( $this, 'add_pc_switcher' ) );
|
128 |
-
add_action( 'wp_headers', array( $this, 'set_cookie_switch_theme' ));
|
129 |
}
|
130 |
else {
|
131 |
-
add_action( 'wp_headers', array( $this, 'set_cookie_normal_theme' ));
|
132 |
}
|
133 |
|
134 |
if ( isset( $_COOKIE[ $this->cookie_name_pc_switcher ] ) ) {
|
@@ -137,26 +249,47 @@ class Multi_Device_Switcher {
|
|
137 |
}
|
138 |
}
|
139 |
|
140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
$options = $this->get_options();
|
142 |
|
143 |
-
$
|
144 |
-
$
|
145 |
-
$
|
146 |
-
$
|
147 |
|
148 |
-
foreach ( $options as $key => $val ) {
|
149 |
if ( ! preg_match( '/^custom_switcher_userAgent_/', $key ) ) {
|
150 |
continue;
|
151 |
}
|
152 |
|
153 |
$custom_switcher_name = preg_replace( '/^custom_switcher_userAgent_/', '', $key );
|
154 |
-
|
|
|
155 |
}
|
156 |
|
157 |
-
return $
|
158 |
}
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
public function get_stylesheet( $stylesheet = '' ) {
|
161 |
$name = $this->get_device_theme();
|
162 |
|
@@ -183,6 +316,17 @@ class Multi_Device_Switcher {
|
|
183 |
return $theme['Stylesheet'];
|
184 |
}
|
185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
public function get_template( $template = '' ) {
|
187 |
$name = $this->get_device_theme();
|
188 |
|
@@ -209,6 +353,15 @@ class Multi_Device_Switcher {
|
|
209 |
return $theme['Template'];
|
210 |
}
|
211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
public function get_device_theme() {
|
213 |
$options = $this->get_options();
|
214 |
|
@@ -225,7 +378,7 @@ class Multi_Device_Switcher {
|
|
225 |
return $options['theme_game'];
|
226 |
}
|
227 |
else {
|
228 |
-
foreach ( $options as $key => $val ) {
|
229 |
if ( ! preg_match( '/^custom_switcher_theme_/', $key ) ) {
|
230 |
continue;
|
231 |
}
|
@@ -238,35 +391,81 @@ class Multi_Device_Switcher {
|
|
238 |
}
|
239 |
}
|
240 |
|
241 |
-
return;
|
242 |
}
|
243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
public function set_cookie_rest_disable_switcher() {
|
245 |
-
setcookie( $this->cookie_name_disable_switcher,
|
246 |
}
|
247 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
248 |
public function set_cookie_enable_disable_switcher() {
|
249 |
-
setcookie( $this->cookie_name_multi_device_switcher,
|
250 |
-
setcookie( $this->cookie_name_disable_switcher, 1,
|
251 |
-
}
|
252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
public function set_cookie_switch_theme() {
|
254 |
-
|
|
|
255 |
}
|
256 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
public function set_cookie_normal_theme() {
|
258 |
-
setcookie( $this->cookie_name_multi_device_switcher,
|
259 |
}
|
260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
public function session() {
|
262 |
if ( isset( $_GET['pc-switcher'] ) ) {
|
263 |
-
setcookie( $this->cookie_name_pc_switcher, $_GET['pc-switcher'] ? 1 : '',
|
264 |
|
265 |
$uri = preg_replace( '/^(.+?)(\?.*)$/', '$1', $_SERVER['REQUEST_URI'] );
|
266 |
|
267 |
unset( $_GET['pc-switcher'] );
|
268 |
if ( ! empty( $_GET ) ) {
|
269 |
-
$uri
|
270 |
}
|
271 |
|
272 |
wp_redirect( esc_url( $uri ) );
|
@@ -274,9 +473,20 @@ class Multi_Device_Switcher {
|
|
274 |
}
|
275 |
}
|
276 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
public function add_pc_switcher( $pc_switcher = 0 ) {
|
278 |
$options = $this->get_options();
|
279 |
-
$name
|
280 |
|
281 |
if ( $options['pc_switcher'] ) {
|
282 |
$pc_switcher = 1;
|
@@ -287,29 +497,40 @@ class Multi_Device_Switcher {
|
|
287 |
wp_enqueue_style(
|
288 |
'pc-switcher-options',
|
289 |
plugins_url() . '/multi-device-switcher/pc-switcher.css',
|
290 |
-
|
291 |
'2013-03-20'
|
292 |
);
|
293 |
}
|
294 |
|
295 |
-
$uri
|
296 |
$uri .= $_SERVER['HTTP_HOST'];
|
297 |
|
298 |
if ( isset( $_COOKIE[ $this->cookie_name_pc_switcher ] ) ) {
|
299 |
$uri .= add_query_arg( 'pc-switcher', 0 );
|
300 |
-
|
301 |
-
<div class="pc-switcher"><a href="<?php echo esc_url( $uri ); ?>"><?php esc_html_e( 'Mobile',
|
302 |
-
|
303 |
}
|
304 |
else {
|
305 |
$uri .= add_query_arg( 'pc-switcher', 1 );
|
306 |
-
|
307 |
-
<div class="pc-switcher"><span class="active"><?php esc_html_e( 'Mobile',
|
308 |
-
|
309 |
}
|
310 |
}
|
311 |
}
|
312 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
313 |
public function is_multi_device( $device = '' ) {
|
314 |
if ( $device === $this->device ) {
|
315 |
return true;
|
@@ -321,15 +542,35 @@ class Multi_Device_Switcher {
|
|
321 |
return false;
|
322 |
}
|
323 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
324 |
public function is_pc_switcher() {
|
325 |
return isset( $_COOKIE[ $this->cookie_name_pc_switcher ] );
|
326 |
}
|
327 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
328 |
public function is_disable_switcher( $disable = false ) {
|
329 |
-
$options
|
330 |
$disable_path = preg_split( '/\R/', $options['disable_path'], -1, PREG_SPLIT_NO_EMPTY );
|
331 |
|
332 |
-
foreach ( $disable_path as $path ) {
|
333 |
if ( $options['enable_regex'] ) {
|
334 |
if ( preg_match( '/' . $path . '/i', $_SERVER['REQUEST_URI'] ) ) {
|
335 |
$disable = true;
|
@@ -337,7 +578,7 @@ class Multi_Device_Switcher {
|
|
337 |
}
|
338 |
}
|
339 |
else {
|
340 |
-
if ( preg_match( '/^' . preg_quote( $path
|
341 |
$disable = true;
|
342 |
break;
|
343 |
}
|
@@ -347,10 +588,25 @@ class Multi_Device_Switcher {
|
|
347 |
return $disable;
|
348 |
}
|
349 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
350 |
public function shortcode_display_switcher( $atts, $content = '' ) {
|
351 |
-
$atts = shortcode_atts(
|
352 |
-
|
353 |
-
|
|
|
|
|
|
|
354 |
|
355 |
if ( empty( $atts['device'] ) && ( $this->is_multi_device( $atts['device'] ) || $this->is_pc_switcher() ) ) {
|
356 |
return $content;
|
@@ -363,23 +619,36 @@ class Multi_Device_Switcher {
|
|
363 |
}
|
364 |
|
365 |
/**
|
366 |
-
* Add HTTP
|
367 |
*
|
368 |
-
* @
|
|
|
|
|
|
|
|
|
369 |
*
|
|
|
370 |
*/
|
371 |
public function add_header_vary( $headers ) {
|
372 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
373 |
return $headers;
|
374 |
}
|
375 |
|
376 |
/**
|
377 |
-
*
|
378 |
*
|
379 |
-
*
|
380 |
*
|
381 |
-
* @
|
382 |
*
|
|
|
383 |
*/
|
384 |
public function admin_enqueue_scripts( $hook_suffix ) {
|
385 |
wp_enqueue_script(
|
@@ -391,77 +660,74 @@ class Multi_Device_Switcher {
|
|
391 |
}
|
392 |
|
393 |
/**
|
394 |
-
*
|
395 |
*
|
396 |
-
*
|
397 |
*
|
398 |
-
* @
|
399 |
*
|
|
|
400 |
*/
|
401 |
public function admin_enqueue_styles( $hook_suffix ) {
|
402 |
wp_enqueue_style(
|
403 |
'multi-device-switcher-options',
|
404 |
plugins_url() . '/multi-device-switcher/multi-device-switcher.css',
|
405 |
-
|
406 |
'2011-08-22'
|
407 |
);
|
408 |
}
|
409 |
|
410 |
/**
|
411 |
-
* Register the form setting
|
|
|
|
|
412 |
*
|
413 |
-
*
|
414 |
*
|
415 |
-
*
|
416 |
-
* which is used when the option is saved, to ensure that our option values are complete, properly
|
417 |
-
* formatted, and safe.
|
418 |
*
|
419 |
* @since 1.0
|
420 |
*/
|
421 |
-
public function
|
422 |
-
|
423 |
-
if ( false === $this->get_options() ) {
|
424 |
add_option( $this->option_name );
|
425 |
}
|
426 |
|
427 |
register_setting(
|
428 |
$this->option_group,
|
429 |
$this->option_name,
|
430 |
-
array( $this, '
|
431 |
);
|
432 |
}
|
433 |
|
434 |
/**
|
435 |
-
*
|
436 |
*
|
437 |
-
* @
|
438 |
-
* @see add_option_page() The edit_theme_options capability is used for viewing the page.
|
439 |
*
|
440 |
-
*
|
441 |
-
* By default, only administrators have either of these capabilities, but the desire here is
|
442 |
-
* to allow for finer-grained control for roles and users.
|
443 |
*
|
444 |
-
* @
|
445 |
-
* @return string The capability to actually use.
|
446 |
*/
|
447 |
public function option_page_capability() {
|
448 |
return $this->capability;
|
449 |
}
|
450 |
|
451 |
/**
|
452 |
-
*
|
|
|
|
|
453 |
*
|
454 |
-
*
|
455 |
*
|
456 |
-
* @since 1.0
|
457 |
*/
|
458 |
public function add_option_page() {
|
459 |
-
|
460 |
$page_hook = add_theme_page(
|
461 |
-
__(
|
462 |
-
__(
|
463 |
$this->option_page_capability(),
|
464 |
-
|
465 |
array( $this, 'render_option_page' )
|
466 |
);
|
467 |
|
@@ -469,13 +735,17 @@ class Multi_Device_Switcher {
|
|
469 |
return;
|
470 |
}
|
471 |
|
472 |
-
add_action( 'load-' . $page_hook
|
473 |
}
|
474 |
|
475 |
/**
|
476 |
-
* Page Hook Suffix
|
|
|
|
|
477 |
*
|
478 |
-
*
|
|
|
|
|
479 |
*
|
480 |
* @since 1.2.4
|
481 |
*/
|
@@ -500,7 +770,7 @@ class Multi_Device_Switcher {
|
|
500 |
* @since 1.6.0
|
501 |
*/
|
502 |
public function plugin_action_links( $links = array() ) {
|
503 |
-
$settings_link = '<a href="themes.php?page=multi-device-switcher">' . __( 'Settings',
|
504 |
|
505 |
array_unshift( $links, $settings_link );
|
506 |
|
@@ -510,77 +780,55 @@ class Multi_Device_Switcher {
|
|
510 |
/**
|
511 |
* Returns the default options.
|
512 |
*
|
513 |
-
* @
|
|
|
|
|
|
|
|
|
514 |
*/
|
515 |
public function get_default_options() {
|
516 |
-
$
|
517 |
-
'pc_switcher' => 1,
|
518 |
-
'default_css' => 1,
|
519 |
-
'theme_smartphone' => 'None',
|
520 |
-
'theme_tablet' => 'None',
|
521 |
-
'theme_mobile' => 'None',
|
522 |
-
'theme_game' => 'None',
|
523 |
-
'userAgent_smart' => 'iPhone, iPod, Android.*Mobile, dream, CUPCAKE, Windows Phone, IEMobile.*Touch, webOS, BB10.*Mobile, BlackBerry.*Mobile, Mobile.*Gecko',
|
524 |
-
'userAgent_tablet' => 'iPad, Kindle, Silk, Android(?!.*Mobile), Windows.*Touch, PlayBook, Tablet.*Gecko',
|
525 |
-
'userAgent_mobile' => 'DoCoMo, SoftBank, J-PHONE, Vodafone, KDDI, UP.Browser, WILLCOM, emobile, DDIPOCKET, Windows CE, BlackBerry, Symbian, PalmOS, Huawei, IAC, Nokia',
|
526 |
-
'userAgent_game' => 'PlayStation Portable, PlayStation Vita, PSP, PS2, PLAYSTATION 3, PlayStation 4, Nitro, Nintendo 3DS, Nintendo Wii, Nintendo WiiU, Xbox',
|
527 |
-
'disable_path' => '',
|
528 |
-
'enable_regex' => 0,
|
529 |
-
);
|
530 |
-
|
531 |
-
return $default_theme_options;
|
532 |
}
|
533 |
|
534 |
/**
|
535 |
-
* Returns the options array.
|
536 |
*
|
537 |
-
* @
|
|
|
|
|
|
|
|
|
|
|
|
|
538 |
*/
|
539 |
-
public function get_options() {
|
540 |
-
$options = get_option( $this->option_name );
|
541 |
-
$
|
542 |
-
|
543 |
-
if (
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
}
|
553 |
-
if ( ! isset( $options['theme_tablet'] ) ) {
|
554 |
-
$options['theme_tablet'] = $default_options['theme_tablet'];
|
555 |
-
}
|
556 |
-
if ( ! isset( $options['theme_mobile'] ) ) {
|
557 |
-
$options['theme_mobile'] = $default_options['theme_mobile'];
|
558 |
-
}
|
559 |
-
if ( ! isset( $options['theme_game'] ) ) {
|
560 |
-
$options['theme_game'] = $default_options['theme_game'];
|
561 |
-
}
|
562 |
-
|
563 |
-
if ( ! isset( $options['userAgent_smart'] ) ) {
|
564 |
-
$options['userAgent_smart'] = $default_options['userAgent_smart'];
|
565 |
-
}
|
566 |
-
if ( ! isset( $options['userAgent_tablet'] ) ) {
|
567 |
-
$options['userAgent_tablet'] = $default_options['userAgent_tablet'];
|
568 |
-
}
|
569 |
-
if ( ! isset( $options['userAgent_mobile'] ) ) {
|
570 |
-
$options['userAgent_mobile'] = $default_options['userAgent_mobile'];
|
571 |
-
}
|
572 |
-
if ( ! isset( $options['userAgent_game'] ) ) {
|
573 |
-
$options['userAgent_game'] = $default_options['userAgent_game'];
|
574 |
}
|
575 |
|
576 |
-
if (
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
|
|
|
|
|
|
|
|
|
|
581 |
}
|
582 |
|
583 |
-
return
|
584 |
}
|
585 |
|
586 |
/**
|
@@ -601,316 +849,325 @@ class Multi_Device_Switcher {
|
|
601 |
}
|
602 |
|
603 |
/**
|
604 |
-
*
|
605 |
*
|
606 |
-
* @
|
|
|
|
|
|
|
|
|
607 |
*/
|
608 |
public function render_option_page() {
|
609 |
?>
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
<?php settings_errors(); ?>
|
614 |
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
|
639 |
-
|
640 |
-
|
641 |
-
|
|
|
642 |
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
}
|
654 |
-
if ( $options['theme_smartphone'] === $theme_name ) {
|
655 |
-
$html .= '<option value="' . esc_attr( $theme_name ) . '" selected="selected">' . esc_html( $theme_name ) . '</option>';
|
656 |
-
}
|
657 |
-
else {
|
658 |
-
$html .= '<option value="' . esc_attr( $theme_name ) . '">' . esc_html( $theme_name ) . '</option>';
|
659 |
-
}
|
660 |
-
}
|
661 |
-
$html .= '</select>';
|
662 |
}
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
|
|
|
|
|
|
|
|
|
|
669 |
|
670 |
-
|
671 |
-
|
672 |
-
|
|
|
673 |
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
else {
|
678 |
-
$html .= '<option value="None">' . __( 'None', $this->textdomain ) . '</option>';
|
679 |
-
}
|
680 |
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
}
|
692 |
-
$html .= '</select>';
|
693 |
}
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
|
|
|
|
|
|
|
|
|
|
700 |
|
701 |
-
|
702 |
-
|
703 |
-
|
|
|
704 |
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
else {
|
709 |
-
$html .= '<option value="None">' . __( 'None', $this->textdomain ) . '</option>';
|
710 |
-
}
|
711 |
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
}
|
723 |
-
$html .= '</select>';
|
724 |
}
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
|
|
|
|
|
|
|
|
|
|
731 |
|
732 |
-
|
733 |
-
|
734 |
-
|
|
|
735 |
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
else {
|
740 |
-
$html .= '<option value="None">' . __( 'None', $this->textdomain ) . '</option>';
|
741 |
-
}
|
742 |
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
}
|
754 |
-
$html .= '</select>';
|
755 |
}
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
761 |
|
762 |
-
|
763 |
-
|
|
|
764 |
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
|
|
|
|
|
|
770 |
|
771 |
-
|
772 |
?>
|
773 |
|
774 |
-
|
775 |
-
|
776 |
|
777 |
<?php
|
778 |
-
|
779 |
-
|
780 |
|
781 |
-
|
782 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
783 |
}
|
784 |
-
|
785 |
-
$html .= '<option value="
|
786 |
}
|
787 |
-
|
788 |
-
|
789 |
-
if ( $default_theme === $theme_name ) {
|
790 |
-
continue;
|
791 |
-
}
|
792 |
-
if ( $custom_switcher_theme === $theme_name ) {
|
793 |
-
$html .= '<option value="' . esc_attr( $theme_name ) . '" selected="selected">' . esc_html( $theme_name ) . '</option>';
|
794 |
-
}
|
795 |
-
else {
|
796 |
-
$html .= '<option value="' . esc_attr( $theme_name ) . '">' . esc_html( $theme_name ) . '</option>';
|
797 |
-
}
|
798 |
}
|
799 |
-
$html .= '</select>';
|
800 |
-
$html .= ' <span class="submit"><input type="submit" name="multi_device_switcher_options[delete_custom_switcher_' . $custom_switcher_name . ']" value="' . __( 'Delete', $this->textdomain ) . '" onclick="return confirm(\'' . esc_html( sprintf( __( 'Are you sure you want to delete %1$s ?', $this->textdomain ), $custom_switcher_name ) ) . '\');" class="button"></span>';
|
801 |
}
|
802 |
-
|
|
|
|
|
|
|
803 |
?>
|
804 |
-
|
805 |
-
|
806 |
|
807 |
<?php
|
808 |
-
|
809 |
-
|
810 |
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
</table>
|
845 |
-
|
846 |
-
<h3><?php esc_html_e( 'Custom Switcher UserAgent', $this->textdomain ); ?></h3>
|
847 |
-
<table class="form-table">
|
848 |
-
<?php
|
849 |
-
foreach ( $options as $custom_switcher_option => $custom_switcher_userAgent ) {
|
850 |
-
if ( ! preg_match( '/^custom_switcher_userAgent_/', $custom_switcher_option ) ) {
|
851 |
-
continue;
|
852 |
-
}
|
853 |
|
854 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
855 |
?>
|
856 |
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
<?php
|
861 |
-
|
862 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
863 |
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
<fieldset id="PC-Switcher" class="options">
|
868 |
-
<h3 class="label"><?php esc_html_e( 'PC Switcher', $this->textdomain ); ?></h3>
|
869 |
-
|
870 |
-
<table class="form-table">
|
871 |
-
<tr><th scope="row"><?php esc_html_e( 'Add PC Switcher', $this->textdomain ); ?></th>
|
872 |
-
<td>
|
873 |
-
<legend class="screen-reader-text"><span><?php esc_html_e( 'Add PC Switcher', $this->textdomain ); ?></span></legend>
|
874 |
-
<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.', $this->textdomain ); ?></label>
|
875 |
-
</td>
|
876 |
-
</tr>
|
877 |
-
<tr><th scope="row"><?php esc_html_e( 'Add default CSS', $this->textdomain ); ?></th>
|
878 |
-
<td>
|
879 |
-
<legend class="screen-reader-text"><span><?php esc_html_e( 'Add default CSS', $this->textdomain ); ?></span></legend>
|
880 |
-
<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.', $this->textdomain ); ?></label>
|
881 |
-
</td>
|
882 |
-
</tr>
|
883 |
-
</table>
|
884 |
-
</fieldset>
|
885 |
-
|
886 |
-
<fieldset id="Disable-Switcher" class="options">
|
887 |
-
<h3 class="label"><?php esc_html_e( 'Disable Switcher', $this->textdomain ); ?></h3>
|
888 |
-
|
889 |
-
<table class="form-table">
|
890 |
-
<tr><th scope="row"><?php esc_html_e( 'Path', $this->textdomain ); ?></th>
|
891 |
-
<td>
|
892 |
-
<legend class="screen-reader-text"><span><?php esc_html_e( 'Path', $this->textdomain ); ?></span></legend>
|
893 |
-
<?php echo esc_html( home_url() ); ?><br>
|
894 |
-
<textarea name="multi_device_switcher_options[disable_path]" rows="16" cols="42" wrap="off"><?php echo esc_textarea( $options['disable_path'] ); ?></textarea>
|
895 |
-
</td>
|
896 |
-
</tr>
|
897 |
-
<tr><th scope="row"><?php esc_html_e( 'Regex mode', $this->textdomain ); ?></th>
|
898 |
-
<td>
|
899 |
-
<legend class="screen-reader-text"><span><?php esc_html_e( 'Regex mode', $this->textdomain ); ?></span></legend>
|
900 |
-
<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', $this->textdomain ); ?></label>
|
901 |
-
</td>
|
902 |
-
</tr>
|
903 |
-
</table>
|
904 |
-
</fieldset>
|
905 |
-
|
906 |
-
</div>
|
907 |
-
<?php submit_button(); ?>
|
908 |
-
</form>
|
909 |
-
</div>
|
910 |
-
|
911 |
-
<div id="donate">
|
912 |
-
<h2><?php esc_html_e( 'Donationware', $this->textdomain ); ?></h2>
|
913 |
-
<p><?php esc_html_e( 'If you like this plugin, please donate to support development and maintenance.', $this->textdomain ); ?></p>
|
914 |
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
|
915 |
<input type="hidden" name="cmd" value="_s-xclick">
|
916 |
<input type="hidden" name="hosted_button_id" value="9L53NELFMHTWW">
|
@@ -932,19 +1189,21 @@ class Multi_Device_Switcher {
|
|
932 |
<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!">
|
933 |
<img alt="" border="0" src="https://www.paypalobjects.com/ja_JP/i/scr/pixel.gif" width="1" height="1">
|
934 |
</form>
|
935 |
-
|
936 |
-
|
937 |
}
|
938 |
|
939 |
/**
|
940 |
-
*
|
941 |
*
|
942 |
-
* @
|
943 |
*
|
944 |
-
* @
|
|
|
|
|
945 |
*/
|
946 |
-
public function
|
947 |
-
$output = $
|
948 |
|
949 |
if ( isset( $input['theme_smartphone'] ) ) {
|
950 |
$output['theme_smartphone'] = $input['theme_smartphone'];
|
@@ -960,10 +1219,10 @@ class Multi_Device_Switcher {
|
|
960 |
}
|
961 |
|
962 |
if ( isset( $input['restore_UserAgent'] ) ) {
|
963 |
-
$output['userAgent_smart']
|
964 |
-
$output['userAgent_tablet'] = $default_options['userAgent_tablet'];
|
965 |
-
$output['userAgent_mobile'] = $default_options['userAgent_mobile'];
|
966 |
-
$output['userAgent_game']
|
967 |
}
|
968 |
else {
|
969 |
if ( isset( $input['userAgent_smart'] ) ) {
|
@@ -1009,7 +1268,7 @@ class Multi_Device_Switcher {
|
|
1009 |
if ( isset( $input['add_custom_switcher'] ) && ! empty( $input['custom_switcher'] ) && ! isset( $output[ 'custom_switcher_theme_' . $input['custom_switcher'] ] ) ) {
|
1010 |
if ( ! in_array( $input['custom_switcher'], array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ) )
|
1011 |
&& preg_match( '/^[A-Za-z0-9]{1,20}$/', $input['custom_switcher'] ) ) {
|
1012 |
-
$output[ 'custom_switcher_theme_' . $input['custom_switcher'] ]
|
1013 |
$output[ 'custom_switcher_userAgent_' . $input['custom_switcher'] ] = '';
|
1014 |
}
|
1015 |
}
|
@@ -1020,25 +1279,37 @@ class Multi_Device_Switcher {
|
|
1020 |
$output['disable_path'] = isset( $input['disable_path'] ) ? $input['disable_path'] : '';
|
1021 |
$output['enable_regex'] = isset( $input['enable_regex'] ) ? $input['enable_regex'] : 0;
|
1022 |
|
1023 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1024 |
}
|
1025 |
|
1026 |
/**
|
1027 |
-
*
|
|
|
|
|
|
|
|
|
1028 |
*
|
1029 |
-
* @param $wp_customize Theme Customizer object
|
1030 |
* @return void
|
1031 |
*
|
1032 |
* @since 1.3.1
|
1033 |
*/
|
1034 |
public function customize_register( $wp_customize ) {
|
1035 |
-
$options
|
1036 |
-
$default_theme_options = $this->
|
1037 |
-
$default_theme
|
1038 |
-
$themes
|
1039 |
|
1040 |
$theme_names = array();
|
1041 |
-
$choices
|
1042 |
|
1043 |
if ( count( $themes ) ) {
|
1044 |
foreach ( $themes as $t ) {
|
@@ -1046,7 +1317,7 @@ class Multi_Device_Switcher {
|
|
1046 |
}
|
1047 |
natcasesort( $theme_names );
|
1048 |
|
1049 |
-
$choices['None'] = __( 'None',
|
1050 |
foreach ( $theme_names as $theme_name ) {
|
1051 |
if ( $default_theme === $theme_name ) {
|
1052 |
continue;
|
@@ -1056,72 +1327,92 @@ class Multi_Device_Switcher {
|
|
1056 |
}
|
1057 |
|
1058 |
$switcher = array(
|
1059 |
-
'theme_smartphone'
|
1060 |
-
'theme_tablet'
|
1061 |
-
'theme_mobile'
|
1062 |
-
'theme_game'
|
1063 |
);
|
1064 |
|
1065 |
-
$wp_customize->add_section(
|
1066 |
-
'
|
1067 |
-
|
1068 |
-
|
|
|
|
|
|
|
1069 |
|
1070 |
foreach ( $switcher as $name => $label ) {
|
1071 |
-
$wp_customize->add_setting(
|
1072 |
-
'
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
|
1081 |
-
'
|
1082 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1083 |
}
|
1084 |
|
1085 |
-
foreach ( $options as $custom_switcher_option => $custom_switcher_theme ) {
|
1086 |
if ( ! preg_match( '/^custom_switcher_theme_/', $custom_switcher_option ) ) {
|
1087 |
continue;
|
1088 |
}
|
1089 |
|
1090 |
$label = preg_replace( '/^custom_switcher_theme_/', '', $custom_switcher_option );
|
1091 |
|
1092 |
-
$wp_customize->add_setting(
|
1093 |
-
'
|
1094 |
-
|
1095 |
-
|
1096 |
-
|
1097 |
-
|
1098 |
-
|
1099 |
-
|
1100 |
-
|
1101 |
-
|
1102 |
-
'
|
1103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1104 |
|
1105 |
}
|
1106 |
}
|
1107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1108 |
public function load_file() {
|
1109 |
/**
|
1110 |
-
*
|
1111 |
*
|
1112 |
* @since 1.2
|
1113 |
-
*
|
1114 |
*/
|
1115 |
-
require_once
|
1116 |
|
1117 |
/**
|
1118 |
-
*
|
1119 |
*
|
1120 |
* @since 1.4
|
1121 |
-
*
|
1122 |
*/
|
1123 |
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
1124 |
-
require_once
|
1125 |
}
|
1126 |
}
|
1127 |
}
|
@@ -1129,6 +1420,7 @@ class Multi_Device_Switcher {
|
|
1129 |
define( '__MULTI_DEVICE_SWITCHER_FILE__', __FILE__ );
|
1130 |
|
1131 |
if ( class_exists( 'Multi_Device_Switcher' ) ) {
|
|
|
1132 |
$multi_device_switcher = new Multi_Device_Switcher();
|
1133 |
};
|
1134 |
|
@@ -1136,7 +1428,6 @@ if ( class_exists( 'Multi_Device_Switcher' ) ) {
|
|
1136 |
* Add PC Switcher.
|
1137 |
*
|
1138 |
* @since 1.2
|
1139 |
-
*
|
1140 |
*/
|
1141 |
function multi_device_switcher_add_pc_switcher() {
|
1142 |
global $multi_device_switcher;
|
@@ -1149,48 +1440,45 @@ function multi_device_switcher_add_pc_switcher() {
|
|
1149 |
* Return boolean whether a particular device.
|
1150 |
*
|
1151 |
* @since 1.2.4
|
1152 |
-
*
|
1153 |
*/
|
1154 |
if ( ! function_exists( 'is_multi_device' ) ) :
|
1155 |
|
1156 |
-
function is_multi_device( $device = '' ) {
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
|
|
1160 |
}
|
1161 |
-
}
|
1162 |
endif;
|
1163 |
|
1164 |
/**
|
1165 |
* Return the state of PC Switcher.
|
1166 |
*
|
1167 |
* @since 1.4.1
|
1168 |
-
*
|
1169 |
*/
|
1170 |
if ( ! function_exists( 'is_pc_switcher' ) ) :
|
1171 |
|
1172 |
-
function is_pc_switcher() {
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
|
|
1176 |
}
|
1177 |
-
}
|
1178 |
endif;
|
1179 |
|
1180 |
/**
|
1181 |
* Return the state of disabled.
|
1182 |
*
|
1183 |
* @since 1.4.1
|
1184 |
-
*
|
1185 |
*/
|
1186 |
if ( ! function_exists( 'is_disable_switcher' ) ) :
|
1187 |
|
1188 |
-
function is_disable_switcher() {
|
1189 |
-
|
1190 |
-
|
1191 |
-
|
|
|
1192 |
}
|
1193 |
-
}
|
1194 |
endif;
|
1195 |
|
1196 |
/**
|
@@ -1200,10 +1488,10 @@ endif;
|
|
1200 |
*/
|
1201 |
if ( ! function_exists( 'multi_device_switcher_get_default_options' ) ) :
|
1202 |
|
1203 |
-
function multi_device_switcher_get_default_options() {
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
|
|
1207 |
}
|
1208 |
-
}
|
1209 |
endif;
|
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.7.0
|
7 |
+
* Author: thingsym
|
8 |
+
* Author URI: http://www.thingslabo.com/
|
9 |
+
* License: GPL2 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 |
*/
|
16 |
|
17 |
if ( ! defined( 'ABSPATH' ) ) {
|
18 |
exit;
|
19 |
}
|
20 |
|
21 |
+
/**
|
22 |
+
* Core class Multi_Device_Switcher
|
23 |
+
*
|
24 |
+
* @since 1.0.0
|
25 |
+
*/
|
26 |
class Multi_Device_Switcher {
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Protected value.
|
30 |
+
*
|
31 |
+
* @access protected
|
32 |
+
*
|
33 |
+
* @var string $option_group The group name of option
|
34 |
+
*/
|
35 |
protected $option_group = 'multi_device_switcher';
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Protected value.
|
39 |
+
*
|
40 |
+
* @access protected
|
41 |
+
*
|
42 |
+
* @var string $option_name The option name
|
43 |
+
*/
|
44 |
protected $option_name = 'multi_device_switcher_options';
|
45 |
|
46 |
+
/**
|
47 |
+
* Protected value.
|
48 |
+
*
|
49 |
+
* @access protected
|
50 |
+
*
|
51 |
+
* @var string $capability The types of capability
|
52 |
+
*/
|
53 |
protected $capability = 'switch_themes';
|
54 |
|
55 |
+
/**
|
56 |
+
* Protected value.
|
57 |
+
*
|
58 |
+
* @access protected
|
59 |
+
*
|
60 |
+
* @var string $cookie_name_multi_device_switcher
|
61 |
+
*/
|
62 |
protected $cookie_name_multi_device_switcher = 'multi-device-switcher';
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Protected value.
|
66 |
+
*
|
67 |
+
* @access protected
|
68 |
+
*
|
69 |
+
* @var string $cookie_name_disable_switcher
|
70 |
+
*/
|
71 |
protected $cookie_name_disable_switcher = 'disable-switcher';
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Protected value.
|
75 |
+
*
|
76 |
+
* @access protected
|
77 |
+
*
|
78 |
+
* @var string $cookie_name_pc_switcher
|
79 |
+
*/
|
80 |
protected $cookie_name_pc_switcher = 'pc-switcher';
|
81 |
|
82 |
+
/**
|
83 |
+
* Protected value.
|
84 |
+
*
|
85 |
+
* @access protected
|
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 |
+
protected $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' => 'PlayStation Portable, PlayStation Vita, PSP, PS2, PLAYSTATION 3, PlayStation 4, Nitro, Nintendo 3DS, Nintendo Wii, Nintendo WiiU, Xbox',
|
117 |
+
'disable_path' => '',
|
118 |
+
'enable_regex' => 0,
|
119 |
+
);
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Public value.
|
123 |
+
*
|
124 |
+
* @access public
|
125 |
+
*
|
126 |
+
* @var string $device
|
127 |
+
*/
|
128 |
public $device = '';
|
129 |
|
130 |
+
/**
|
131 |
+
* Constructor
|
132 |
+
*
|
133 |
+
* @access public
|
134 |
+
*
|
135 |
+
* @since 1.0.0
|
136 |
+
*/
|
137 |
public function __construct() {
|
138 |
add_action( 'init', array( $this, 'load_textdomain' ) );
|
139 |
add_action( 'init', array( $this, 'init' ) );
|
140 |
|
141 |
if ( ! is_admin() ) {
|
142 |
add_filter( 'wp_headers', array( $this, 'add_header_vary' ) );
|
143 |
+
add_action( 'plugins_loaded', array( $this, 'detect_device' ) );
|
144 |
add_action( 'plugins_loaded', array( $this, 'switch_theme' ) );
|
145 |
}
|
146 |
|
147 |
+
add_action( 'admin_init', array( $this, 'register_settings' ) );
|
148 |
add_action( 'admin_menu', array( $this, 'add_option_page' ) );
|
149 |
add_action( 'customize_register', array( $this, 'customize_register' ) );
|
150 |
add_action( 'plugins_loaded', array( $this, 'load_file' ) );
|
166 |
add_shortcode( 'multi', array( $this, 'shortcode_display_switcher' ) );
|
167 |
}
|
168 |
|
169 |
+
/**
|
170 |
+
* Detect device.
|
171 |
+
*
|
172 |
+
* @access public
|
173 |
+
*
|
174 |
+
* @return void
|
175 |
+
*
|
176 |
+
* @since 1.7.0
|
177 |
+
*/
|
178 |
+
public function detect_device() {
|
179 |
if ( isset( $_COOKIE[ $this->cookie_name_disable_switcher ] ) ) {
|
180 |
+
add_action( 'wp_headers', array( $this, 'set_cookie_rest_disable_switcher' ) );
|
181 |
}
|
182 |
|
183 |
if ( $this->is_disable_switcher() ) {
|
184 |
+
add_action( 'wp_headers', array( $this, 'set_cookie_enable_disable_switcher' ) );
|
185 |
return;
|
186 |
}
|
187 |
|
188 |
add_action( 'init', array( $this, 'session' ) );
|
189 |
|
190 |
+
$server_ua = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '';
|
191 |
+
$user_agent = $this->get_options_user_agent();
|
192 |
|
193 |
+
foreach ( array_reverse( $user_agent ) as $key => $val ) {
|
194 |
if ( ! preg_match( '/^custom_switcher_/', $key ) ) {
|
195 |
continue;
|
196 |
}
|
197 |
+
if ( $user_agent[ $key ] && preg_match( '/' . implode( '|', $user_agent[ $key ] ) . '/i', $server_ua ) ) {
|
198 |
$this->device = $key;
|
199 |
break;
|
200 |
}
|
201 |
}
|
202 |
|
203 |
if ( ! $this->device ) {
|
204 |
+
if ( $user_agent['game'] && preg_match( '/' . implode( '|', $user_agent['game'] ) . '/i', $server_ua ) ) {
|
205 |
$this->device = 'game';
|
206 |
}
|
207 |
+
elseif ( $user_agent['tablet'] && preg_match( '/' . implode( '|', $user_agent['tablet'] ) . '/i', $server_ua ) ) {
|
208 |
$this->device = 'tablet';
|
209 |
}
|
210 |
+
elseif ( $user_agent['smart'] && preg_match( '/' . implode( '|', $user_agent['smart'] ) . '/i', $server_ua ) ) {
|
211 |
$this->device = 'smart';
|
212 |
}
|
213 |
+
elseif ( $user_agent['mobile'] && preg_match( '/' . implode( '|', $user_agent['mobile'] ) . '/i', $server_ua ) ) {
|
214 |
$this->device = 'mobile';
|
215 |
}
|
216 |
}
|
217 |
|
218 |
+
/**
|
219 |
+
* Action hook: multi_device_switcher/detect_device.
|
220 |
+
*
|
221 |
+
* @since 1.7.0
|
222 |
+
*/
|
223 |
+
do_action( 'multi_device_switcher/detect_device' );
|
224 |
+
}
|
225 |
+
|
226 |
+
/**
|
227 |
+
* Switch theme.
|
228 |
+
*
|
229 |
+
* @access public
|
230 |
+
*
|
231 |
+
* @return void
|
232 |
+
*
|
233 |
+
* @since 1.0.0
|
234 |
+
*/
|
235 |
+
public function switch_theme() {
|
236 |
if ( $this->device ) {
|
237 |
add_filter( 'stylesheet', array( $this, 'get_stylesheet' ) );
|
238 |
add_filter( 'template', array( $this, 'get_template' ) );
|
239 |
add_action( 'wp_footer', array( $this, 'add_pc_switcher' ) );
|
240 |
+
add_action( 'wp_headers', array( $this, 'set_cookie_switch_theme' ) );
|
241 |
}
|
242 |
else {
|
243 |
+
add_action( 'wp_headers', array( $this, 'set_cookie_normal_theme' ) );
|
244 |
}
|
245 |
|
246 |
if ( isset( $_COOKIE[ $this->cookie_name_pc_switcher ] ) ) {
|
249 |
}
|
250 |
}
|
251 |
|
252 |
+
/**
|
253 |
+
* Gets UserAgents.
|
254 |
+
*
|
255 |
+
* @access public
|
256 |
+
*
|
257 |
+
* @return array
|
258 |
+
*
|
259 |
+
* @since 1.0.0
|
260 |
+
*/
|
261 |
+
public function get_options_user_agent() {
|
262 |
$options = $this->get_options();
|
263 |
|
264 |
+
$user_agent['smart'] = empty( $options['userAgent_smart'] ) ? '' : preg_split( '/,\s*/', $options['userAgent_smart'], -1, PREG_SPLIT_NO_EMPTY );
|
265 |
+
$user_agent['tablet'] = empty( $options['userAgent_tablet'] ) ? '' : preg_split( '/,\s*/', $options['userAgent_tablet'], -1, PREG_SPLIT_NO_EMPTY );
|
266 |
+
$user_agent['mobile'] = empty( $options['userAgent_mobile'] ) ? '' : preg_split( '/,\s*/', $options['userAgent_mobile'], -1, PREG_SPLIT_NO_EMPTY );
|
267 |
+
$user_agent['game'] = empty( $options['userAgent_game'] ) ? '' : preg_split( '/,\s*/', $options['userAgent_game'], -1, PREG_SPLIT_NO_EMPTY );
|
268 |
|
269 |
+
foreach ( (array) $options as $key => $val ) {
|
270 |
if ( ! preg_match( '/^custom_switcher_userAgent_/', $key ) ) {
|
271 |
continue;
|
272 |
}
|
273 |
|
274 |
$custom_switcher_name = preg_replace( '/^custom_switcher_userAgent_/', '', $key );
|
275 |
+
|
276 |
+
$user_agent[ 'custom_switcher_' . $custom_switcher_name ] = empty( $val ) ? '' : preg_split( '/,\s*/', $val, -1, PREG_SPLIT_NO_EMPTY );
|
277 |
}
|
278 |
|
279 |
+
return $user_agent;
|
280 |
}
|
281 |
|
282 |
+
/**
|
283 |
+
* Gets stylesheet.
|
284 |
+
*
|
285 |
+
* @access public
|
286 |
+
*
|
287 |
+
* @param string $stylesheet
|
288 |
+
*
|
289 |
+
* @return string
|
290 |
+
*
|
291 |
+
* @since 1.0.0
|
292 |
+
*/
|
293 |
public function get_stylesheet( $stylesheet = '' ) {
|
294 |
$name = $this->get_device_theme();
|
295 |
|
316 |
return $theme['Stylesheet'];
|
317 |
}
|
318 |
|
319 |
+
/**
|
320 |
+
* Gets template.
|
321 |
+
*
|
322 |
+
* @access public
|
323 |
+
*
|
324 |
+
* @param string $template
|
325 |
+
*
|
326 |
+
* @return string
|
327 |
+
*
|
328 |
+
* @since 1.0.0
|
329 |
+
*/
|
330 |
public function get_template( $template = '' ) {
|
331 |
$name = $this->get_device_theme();
|
332 |
|
353 |
return $theme['Template'];
|
354 |
}
|
355 |
|
356 |
+
/**
|
357 |
+
* Gets template by device.
|
358 |
+
*
|
359 |
+
* @access public
|
360 |
+
*
|
361 |
+
* @return string
|
362 |
+
*
|
363 |
+
* @since 1.0.0
|
364 |
+
*/
|
365 |
public function get_device_theme() {
|
366 |
$options = $this->get_options();
|
367 |
|
378 |
return $options['theme_game'];
|
379 |
}
|
380 |
else {
|
381 |
+
foreach ( (array) $options as $key => $val ) {
|
382 |
if ( ! preg_match( '/^custom_switcher_theme_/', $key ) ) {
|
383 |
continue;
|
384 |
}
|
391 |
}
|
392 |
}
|
393 |
|
394 |
+
return '';
|
395 |
}
|
396 |
|
397 |
+
/**
|
398 |
+
* Reset cookie for disable_switcher.
|
399 |
+
*
|
400 |
+
* @access public
|
401 |
+
*
|
402 |
+
* @return void
|
403 |
+
*
|
404 |
+
* @since 1.0.0
|
405 |
+
*/
|
406 |
public function set_cookie_rest_disable_switcher() {
|
407 |
+
setcookie( $this->cookie_name_disable_switcher, '', time() - 3600, '/', '', is_ssl(), false );
|
408 |
}
|
409 |
|
410 |
+
/**
|
411 |
+
* Set enable to cookie for disable_switcher.
|
412 |
+
*
|
413 |
+
* @access public
|
414 |
+
*
|
415 |
+
* @return void
|
416 |
+
*
|
417 |
+
* @since 1.0.0
|
418 |
+
*/
|
419 |
public function set_cookie_enable_disable_switcher() {
|
420 |
+
setcookie( $this->cookie_name_multi_device_switcher, '', time() - 3600, '/', '', is_ssl(), false );
|
421 |
+
setcookie( $this->cookie_name_disable_switcher, '1', 0, '/', '', is_ssl(), false );
|
422 |
+
}
|
423 |
|
424 |
+
/**
|
425 |
+
* Set switched theme to cookie.
|
426 |
+
*
|
427 |
+
* @access public
|
428 |
+
*
|
429 |
+
* @return void
|
430 |
+
*
|
431 |
+
* @since 1.0.0
|
432 |
+
*/
|
433 |
public function set_cookie_switch_theme() {
|
434 |
+
$device = preg_replace( '/^custom_switcher_/', '', $this->device );
|
435 |
+
setcookie( $this->cookie_name_multi_device_switcher, (string) $device, 0, '/', '', is_ssl(), false );
|
436 |
}
|
437 |
|
438 |
+
/**
|
439 |
+
* Reset cookie for normal theme.
|
440 |
+
*
|
441 |
+
* @access public
|
442 |
+
*
|
443 |
+
* @return void
|
444 |
+
*
|
445 |
+
* @since 1.0.0
|
446 |
+
*/
|
447 |
public function set_cookie_normal_theme() {
|
448 |
+
setcookie( $this->cookie_name_multi_device_switcher, '', time() - 3600, '/', '', is_ssl(), false );
|
449 |
}
|
450 |
|
451 |
+
/**
|
452 |
+
* Set session to cookie for pc switcher.
|
453 |
+
*
|
454 |
+
* @access public
|
455 |
+
*
|
456 |
+
* @return void
|
457 |
+
*
|
458 |
+
* @since 1.0.0
|
459 |
+
*/
|
460 |
public function session() {
|
461 |
if ( isset( $_GET['pc-switcher'] ) ) {
|
462 |
+
setcookie( $this->cookie_name_pc_switcher, $_GET['pc-switcher'] ? '1' : '', 0, '/', '', is_ssl(), false );
|
463 |
|
464 |
$uri = preg_replace( '/^(.+?)(\?.*)$/', '$1', $_SERVER['REQUEST_URI'] );
|
465 |
|
466 |
unset( $_GET['pc-switcher'] );
|
467 |
if ( ! empty( $_GET ) ) {
|
468 |
+
$uri = $uri . '?' . http_build_query( $_GET );
|
469 |
}
|
470 |
|
471 |
wp_redirect( esc_url( $uri ) );
|
473 |
}
|
474 |
}
|
475 |
|
476 |
+
/**
|
477 |
+
* Add pc switcher button.
|
478 |
+
*
|
479 |
+
* @access public
|
480 |
+
*
|
481 |
+
* @param bool $pc_switcher
|
482 |
+
*
|
483 |
+
* @return void
|
484 |
+
*
|
485 |
+
* @since 1.0.0
|
486 |
+
*/
|
487 |
public function add_pc_switcher( $pc_switcher = 0 ) {
|
488 |
$options = $this->get_options();
|
489 |
+
$name = $this->get_device_theme();
|
490 |
|
491 |
if ( $options['pc_switcher'] ) {
|
492 |
$pc_switcher = 1;
|
497 |
wp_enqueue_style(
|
498 |
'pc-switcher-options',
|
499 |
plugins_url() . '/multi-device-switcher/pc-switcher.css',
|
500 |
+
array(),
|
501 |
'2013-03-20'
|
502 |
);
|
503 |
}
|
504 |
|
505 |
+
$uri = is_ssl() ? 'https://' : 'http://';
|
506 |
$uri .= $_SERVER['HTTP_HOST'];
|
507 |
|
508 |
if ( isset( $_COOKIE[ $this->cookie_name_pc_switcher ] ) ) {
|
509 |
$uri .= add_query_arg( 'pc-switcher', 0 );
|
510 |
+
?>
|
511 |
+
<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>
|
512 |
+
<?php
|
513 |
}
|
514 |
else {
|
515 |
$uri .= add_query_arg( 'pc-switcher', 1 );
|
516 |
+
?>
|
517 |
+
<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>
|
518 |
+
<?php
|
519 |
}
|
520 |
}
|
521 |
}
|
522 |
|
523 |
+
/**
|
524 |
+
* Check device.
|
525 |
+
*
|
526 |
+
* @access public
|
527 |
+
*
|
528 |
+
* @param string $device
|
529 |
+
*
|
530 |
+
* @return bool
|
531 |
+
*
|
532 |
+
* @since 1.0.0
|
533 |
+
*/
|
534 |
public function is_multi_device( $device = '' ) {
|
535 |
if ( $device === $this->device ) {
|
536 |
return true;
|
542 |
return false;
|
543 |
}
|
544 |
|
545 |
+
/**
|
546 |
+
* Whether pc switcher enabled.
|
547 |
+
*
|
548 |
+
* @access public
|
549 |
+
*
|
550 |
+
* @return bool
|
551 |
+
*
|
552 |
+
* @since 1.0.0
|
553 |
+
*/
|
554 |
public function is_pc_switcher() {
|
555 |
return isset( $_COOKIE[ $this->cookie_name_pc_switcher ] );
|
556 |
}
|
557 |
|
558 |
+
/**
|
559 |
+
* Whether theme switch disabled.
|
560 |
+
*
|
561 |
+
* @access public
|
562 |
+
*
|
563 |
+
* @param bool $disable
|
564 |
+
*
|
565 |
+
* @return bool
|
566 |
+
*
|
567 |
+
* @since 1.0.0
|
568 |
+
*/
|
569 |
public function is_disable_switcher( $disable = false ) {
|
570 |
+
$options = $this->get_options();
|
571 |
$disable_path = preg_split( '/\R/', $options['disable_path'], -1, PREG_SPLIT_NO_EMPTY );
|
572 |
|
573 |
+
foreach ( (array) $disable_path as $path ) {
|
574 |
if ( $options['enable_regex'] ) {
|
575 |
if ( preg_match( '/' . $path . '/i', $_SERVER['REQUEST_URI'] ) ) {
|
576 |
$disable = true;
|
578 |
}
|
579 |
}
|
580 |
else {
|
581 |
+
if ( preg_match( '/^' . preg_quote( (string) $path, '/' ) . '$/i', $_SERVER['REQUEST_URI'] ) ) {
|
582 |
$disable = true;
|
583 |
break;
|
584 |
}
|
588 |
return $disable;
|
589 |
}
|
590 |
|
591 |
+
/**
|
592 |
+
* Shortcode.
|
593 |
+
*
|
594 |
+
* @access public
|
595 |
+
*
|
596 |
+
* @param array $atts
|
597 |
+
* @param string $content
|
598 |
+
*
|
599 |
+
* @return string
|
600 |
+
*
|
601 |
+
* @since 1.0.0
|
602 |
+
*/
|
603 |
public function shortcode_display_switcher( $atts, $content = '' ) {
|
604 |
+
$atts = shortcode_atts(
|
605 |
+
array(
|
606 |
+
'device' => '',
|
607 |
+
),
|
608 |
+
$atts
|
609 |
+
);
|
610 |
|
611 |
if ( empty( $atts['device'] ) && ( $this->is_multi_device( $atts['device'] ) || $this->is_pc_switcher() ) ) {
|
612 |
return $content;
|
619 |
}
|
620 |
|
621 |
/**
|
622 |
+
* Add HTTP Vary header.
|
623 |
*
|
624 |
+
* @access public
|
625 |
+
*
|
626 |
+
* @param string $headers
|
627 |
+
*
|
628 |
+
* @return string
|
629 |
*
|
630 |
+
* @since 1.1.1
|
631 |
*/
|
632 |
public function add_header_vary( $headers ) {
|
633 |
+
/**
|
634 |
+
* Filter hook: multi_device_switcher/add_header_vary.
|
635 |
+
*
|
636 |
+
* @param string 'User-Agent' header name.
|
637 |
+
*
|
638 |
+
* @since 1.6.2
|
639 |
+
*/
|
640 |
+
$headers['Vary'] = apply_filters( 'multi_device_switcher/add_header_vary', 'User-Agent' );
|
641 |
return $headers;
|
642 |
}
|
643 |
|
644 |
/**
|
645 |
+
* Enqueue scripts.
|
646 |
*
|
647 |
+
* Hooks to admin_enqueue_scripts.
|
648 |
*
|
649 |
+
* @access public
|
650 |
*
|
651 |
+
* @since 1.0.0
|
652 |
*/
|
653 |
public function admin_enqueue_scripts( $hook_suffix ) {
|
654 |
wp_enqueue_script(
|
660 |
}
|
661 |
|
662 |
/**
|
663 |
+
* Enqueue styles.
|
664 |
*
|
665 |
+
* Hooks to admin_enqueue_styles.
|
666 |
*
|
667 |
+
* @access public
|
668 |
*
|
669 |
+
* @since 1.0.0
|
670 |
*/
|
671 |
public function admin_enqueue_styles( $hook_suffix ) {
|
672 |
wp_enqueue_style(
|
673 |
'multi-device-switcher-options',
|
674 |
plugins_url() . '/multi-device-switcher/multi-device-switcher.css',
|
675 |
+
array(),
|
676 |
'2011-08-22'
|
677 |
);
|
678 |
}
|
679 |
|
680 |
/**
|
681 |
+
* Register the form setting.
|
682 |
+
*
|
683 |
+
* Hooks to admin_init.
|
684 |
*
|
685 |
+
* @access public
|
686 |
*
|
687 |
+
* @return void
|
|
|
|
|
688 |
*
|
689 |
* @since 1.0
|
690 |
*/
|
691 |
+
public function register_settings() {
|
692 |
+
if ( is_null( $this->get_options() ) ) {
|
|
|
693 |
add_option( $this->option_name );
|
694 |
}
|
695 |
|
696 |
register_setting(
|
697 |
$this->option_group,
|
698 |
$this->option_name,
|
699 |
+
array( $this, 'validate_options' )
|
700 |
);
|
701 |
}
|
702 |
|
703 |
/**
|
704 |
+
* Returns capability.
|
705 |
*
|
706 |
+
* @access public
|
|
|
707 |
*
|
708 |
+
* @return string
|
|
|
|
|
709 |
*
|
710 |
+
* @since 1.0.0
|
|
|
711 |
*/
|
712 |
public function option_page_capability() {
|
713 |
return $this->capability;
|
714 |
}
|
715 |
|
716 |
/**
|
717 |
+
* Adds option page.
|
718 |
+
*
|
719 |
+
* @access public
|
720 |
*
|
721 |
+
* @return void
|
722 |
*
|
723 |
+
* @since 1.0.0
|
724 |
*/
|
725 |
public function add_option_page() {
|
|
|
726 |
$page_hook = add_theme_page(
|
727 |
+
__( 'Multi Device Switcher', 'multi-device-switcher' ),
|
728 |
+
__( 'Multi Device Switcher', 'multi-device-switcher' ),
|
729 |
$this->option_page_capability(),
|
730 |
+
'multi-device-switcher',
|
731 |
array( $this, 'render_option_page' )
|
732 |
);
|
733 |
|
735 |
return;
|
736 |
}
|
737 |
|
738 |
+
add_action( 'load-' . $page_hook, array( $this, 'page_hook_suffix' ) );
|
739 |
}
|
740 |
|
741 |
/**
|
742 |
+
* Page Hook Suffix.
|
743 |
+
*
|
744 |
+
* Hooks to load-{$page_hook}.
|
745 |
*
|
746 |
+
* @access public
|
747 |
+
*
|
748 |
+
* @return void
|
749 |
*
|
750 |
* @since 1.2.4
|
751 |
*/
|
770 |
* @since 1.6.0
|
771 |
*/
|
772 |
public function plugin_action_links( $links = array() ) {
|
773 |
+
$settings_link = '<a href="themes.php?page=multi-device-switcher">' . __( 'Settings', 'multi-device-switcher' ) . '</a>';
|
774 |
|
775 |
array_unshift( $links, $settings_link );
|
776 |
|
780 |
/**
|
781 |
* Returns the default options.
|
782 |
*
|
783 |
+
* @access public
|
784 |
+
*
|
785 |
+
* @return array|null
|
786 |
+
*
|
787 |
+
* @since 1.0.0
|
788 |
*/
|
789 |
public function get_default_options() {
|
790 |
+
return $this->default_options;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
791 |
}
|
792 |
|
793 |
/**
|
794 |
+
* Returns the options array or value.
|
795 |
*
|
796 |
+
* @access public
|
797 |
+
*
|
798 |
+
* @param string $option_name Optional. The option name.
|
799 |
+
*
|
800 |
+
* @return array|null
|
801 |
+
*
|
802 |
+
* @since 1.0.0
|
803 |
*/
|
804 |
+
public function get_options( $option_name = null ) {
|
805 |
+
$options = get_option( $this->option_name, $this->default_options );
|
806 |
+
$options = array_merge( $this->default_options, $options );
|
807 |
+
|
808 |
+
if ( is_null( $option_name ) ) {
|
809 |
+
/**
|
810 |
+
* Filter hook: multi_device_switcher/get_options.
|
811 |
+
*
|
812 |
+
* @param array $options The options.
|
813 |
+
*
|
814 |
+
* @since 1.7.0
|
815 |
+
*/
|
816 |
+
return apply_filters( 'multi_device_switcher/get_options', $options );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
817 |
}
|
818 |
|
819 |
+
if ( array_key_exists( $option_name, $options ) ) {
|
820 |
+
/**
|
821 |
+
* Filter hook: multi_device_switcher/get_option.
|
822 |
+
*
|
823 |
+
* @param mixed $option The value of option.
|
824 |
+
* @param string $option_name The option name via argument.
|
825 |
+
*
|
826 |
+
* @since 1.7.0
|
827 |
+
*/
|
828 |
+
return apply_filters( 'multi_device_switcher/get_option', $options[ $option_name ], $option_name );
|
829 |
}
|
830 |
|
831 |
+
return null;
|
832 |
}
|
833 |
|
834 |
/**
|
849 |
}
|
850 |
|
851 |
/**
|
852 |
+
* Display option page.
|
853 |
*
|
854 |
+
* @access public
|
855 |
+
*
|
856 |
+
* @return void
|
857 |
+
*
|
858 |
+
* @since 1.0.0
|
859 |
*/
|
860 |
public function render_option_page() {
|
861 |
?>
|
862 |
+
<div class="wrap">
|
863 |
+
<div id="icon-themes" class="icon32"><br></div>
|
864 |
+
<h2><?php esc_html_e( 'Multi Device Switcher', 'multi-device-switcher' ); ?></h2>
|
865 |
<?php settings_errors(); ?>
|
866 |
|
867 |
+
<form method="post" action="options.php">
|
868 |
+
<?php
|
869 |
+
settings_fields( 'multi_device_switcher' );
|
870 |
+
$options = $this->get_options();
|
871 |
|
872 |
+
$default_theme = wp_get_theme()->get( 'Name' );
|
873 |
+
$themes = wp_get_themes();
|
874 |
+
$theme_names = array();
|
875 |
|
876 |
+
if ( count( $themes ) ) {
|
877 |
+
foreach ( $themes as $t ) {
|
878 |
+
$theme_names[] = $t->get( 'Name' );
|
879 |
+
}
|
880 |
+
natcasesort( $theme_names );
|
881 |
+
}
|
882 |
+
?>
|
883 |
|
884 |
+
<div id="admin-tabs">
|
885 |
+
<fieldset id="Theme" class="options">
|
886 |
+
<h3 class="label"><?php esc_html_e( 'Theme', 'multi-device-switcher' ); ?></h3>
|
887 |
+
<table class="form-table">
|
888 |
+
<tr><th scope="row"><?php esc_html_e( 'Smart Phone Theme', 'multi-device-switcher' ); ?></th>
|
889 |
+
<td>
|
890 |
|
891 |
+
<?php
|
892 |
+
$html = '';
|
893 |
+
if ( count( $theme_names ) ) {
|
894 |
+
$html = '<select name="multi_device_switcher_options[theme_smartphone]">';
|
895 |
|
896 |
+
if ( ( 'None' === $options['theme_smartphone'] ) || ( '' === $options['theme_smartphone'] ) ) {
|
897 |
+
$html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>';
|
898 |
+
}
|
899 |
+
else {
|
900 |
+
$html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>';
|
901 |
+
}
|
902 |
|
903 |
+
foreach ( $theme_names as $theme_name ) {
|
904 |
+
if ( $default_theme === $theme_name ) {
|
905 |
+
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
906 |
}
|
907 |
+
if ( $options['theme_smartphone'] === $theme_name ) {
|
908 |
+
$html .= '<option value="' . esc_attr( $theme_name ) . '" selected="selected">' . esc_html( $theme_name ) . '</option>';
|
909 |
+
}
|
910 |
+
else {
|
911 |
+
$html .= '<option value="' . esc_attr( $theme_name ) . '">' . esc_html( $theme_name ) . '</option>';
|
912 |
+
}
|
913 |
+
}
|
914 |
+
$html .= '</select>';
|
915 |
+
}
|
916 |
+
echo $html;
|
917 |
+
?>
|
918 |
|
919 |
+
</td>
|
920 |
+
</tr>
|
921 |
+
<tr><th scope="row"><?php esc_html_e( 'Tablet PC Theme', 'multi-device-switcher' ); ?></th>
|
922 |
+
<td>
|
923 |
|
924 |
+
<?php
|
925 |
+
if ( count( $theme_names ) ) {
|
926 |
+
$html = '<select name="multi_device_switcher_options[theme_tablet]">';
|
|
|
|
|
|
|
927 |
|
928 |
+
if ( ( 'None' === $options['theme_tablet'] ) || ( '' === $options['theme_tablet'] ) ) {
|
929 |
+
$html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>';
|
930 |
+
}
|
931 |
+
else {
|
932 |
+
$html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>';
|
933 |
+
}
|
934 |
+
|
935 |
+
foreach ( $theme_names as $theme_name ) {
|
936 |
+
if ( $default_theme === $theme_name ) {
|
937 |
+
continue;
|
|
|
|
|
938 |
}
|
939 |
+
if ( $options['theme_tablet'] === $theme_name ) {
|
940 |
+
$html .= '<option value="' . esc_attr( $theme_name ) . '" selected="selected">' . esc_html( $theme_name ) . '</option>';
|
941 |
+
}
|
942 |
+
else {
|
943 |
+
$html .= '<option value="' . esc_attr( $theme_name ) . '">' . esc_html( $theme_name ) . '</option>';
|
944 |
+
}
|
945 |
+
}
|
946 |
+
$html .= '</select>';
|
947 |
+
}
|
948 |
+
echo $html;
|
949 |
+
?>
|
950 |
|
951 |
+
</td>
|
952 |
+
</tr>
|
953 |
+
<tr><th scope="row"><?php esc_html_e( 'Mobile Phone Theme', 'multi-device-switcher' ); ?></th>
|
954 |
+
<td>
|
955 |
|
956 |
+
<?php
|
957 |
+
if ( count( $theme_names ) ) {
|
958 |
+
$html = '<select name="multi_device_switcher_options[theme_mobile]">';
|
|
|
|
|
|
|
959 |
|
960 |
+
if ( ( 'None' === $options['theme_mobile'] ) || ( '' === $options['theme_mobile'] ) ) {
|
961 |
+
$html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>';
|
962 |
+
}
|
963 |
+
else {
|
964 |
+
$html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>';
|
965 |
+
}
|
966 |
+
|
967 |
+
foreach ( $theme_names as $theme_name ) {
|
968 |
+
if ( $default_theme === $theme_name ) {
|
969 |
+
continue;
|
|
|
|
|
970 |
}
|
971 |
+
if ( $options['theme_mobile'] === $theme_name ) {
|
972 |
+
$html .= '<option value="' . esc_attr( $theme_name ) . '" selected="selected">' . esc_html( $theme_name ) . '</option>';
|
973 |
+
}
|
974 |
+
else {
|
975 |
+
$html .= '<option value="' . esc_attr( $theme_name ) . '">' . esc_html( $theme_name ) . '</option>';
|
976 |
+
}
|
977 |
+
}
|
978 |
+
$html .= '</select>';
|
979 |
+
}
|
980 |
+
echo $html;
|
981 |
+
?>
|
982 |
|
983 |
+
</td>
|
984 |
+
</tr>
|
985 |
+
<tr><th scope="row"><?php esc_html_e( 'Game Platforms Theme', 'multi-device-switcher' ); ?></th>
|
986 |
+
<td>
|
987 |
|
988 |
+
<?php
|
989 |
+
if ( count( $theme_names ) ) {
|
990 |
+
$html = '<select name="multi_device_switcher_options[theme_game]">';
|
|
|
|
|
|
|
991 |
|
992 |
+
if ( ( 'None' === $options['theme_game'] ) || ( '' === $options['theme_game'] ) ) {
|
993 |
+
$html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>';
|
994 |
+
}
|
995 |
+
else {
|
996 |
+
$html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>';
|
997 |
+
}
|
998 |
+
|
999 |
+
foreach ( $theme_names as $theme_name ) {
|
1000 |
+
if ( $default_theme === $theme_name ) {
|
1001 |
+
continue;
|
|
|
|
|
1002 |
}
|
1003 |
+
if ( $options['theme_game'] === $theme_name ) {
|
1004 |
+
$html .= '<option value="' . esc_attr( $theme_name ) . '" selected="selected">' . esc_html( $theme_name ) . '</option>';
|
1005 |
+
}
|
1006 |
+
else {
|
1007 |
+
$html .= '<option value="' . esc_attr( $theme_name ) . '">' . esc_html( $theme_name ) . '</option>';
|
1008 |
+
}
|
1009 |
+
}
|
1010 |
+
$html .= '</select>';
|
1011 |
+
}
|
1012 |
+
echo $html;
|
1013 |
+
?>
|
1014 |
|
1015 |
+
</td>
|
1016 |
+
</tr>
|
1017 |
+
</table>
|
1018 |
|
1019 |
+
<h3><?php esc_html_e( 'Custom Switcher Theme', 'multi-device-switcher' ); ?></h3>
|
1020 |
+
<table class="form-table">
|
1021 |
+
|
1022 |
+
<?php
|
1023 |
+
foreach ( (array) $options as $custom_switcher_option => $custom_switcher_theme ) {
|
1024 |
+
if ( ! preg_match( '/^custom_switcher_theme_/', $custom_switcher_option ) ) {
|
1025 |
+
continue;
|
1026 |
+
}
|
1027 |
|
1028 |
+
$custom_switcher_name = preg_replace( '/^custom_switcher_theme_/', '', $custom_switcher_option );
|
1029 |
?>
|
1030 |
|
1031 |
+
<tr><th scope="row"><?php echo esc_html( $custom_switcher_name ); ?></th>
|
1032 |
+
<td>
|
1033 |
|
1034 |
<?php
|
1035 |
+
if ( count( $theme_names ) ) {
|
1036 |
+
$html = '<select name="multi_device_switcher_options[' . $custom_switcher_option . ']">';
|
1037 |
|
1038 |
+
if ( ( 'None' === $custom_switcher_theme ) || ( '' === $custom_switcher_theme ) ) {
|
1039 |
+
$html .= '<option value="None" selected="selected">' . __( 'None', 'multi-device-switcher' ) . '</option>';
|
1040 |
+
}
|
1041 |
+
else {
|
1042 |
+
$html .= '<option value="None">' . __( 'None', 'multi-device-switcher' ) . '</option>';
|
1043 |
+
}
|
1044 |
+
|
1045 |
+
foreach ( $theme_names as $theme_name ) {
|
1046 |
+
if ( $default_theme === $theme_name ) {
|
1047 |
+
continue;
|
1048 |
}
|
1049 |
+
if ( $custom_switcher_theme === $theme_name ) {
|
1050 |
+
$html .= '<option value="' . esc_attr( $theme_name ) . '" selected="selected">' . esc_html( $theme_name ) . '</option>';
|
1051 |
}
|
1052 |
+
else {
|
1053 |
+
$html .= '<option value="' . esc_attr( $theme_name ) . '">' . esc_html( $theme_name ) . '</option>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1054 |
}
|
|
|
|
|
1055 |
}
|
1056 |
+
$html .= '</select>';
|
1057 |
+
$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>';
|
1058 |
+
}
|
1059 |
+
echo $html;
|
1060 |
?>
|
1061 |
+
</td>
|
1062 |
+
</tr>
|
1063 |
|
1064 |
<?php
|
1065 |
+
}
|
1066 |
+
?>
|
1067 |
|
1068 |
+
<tr><th scope="row"><?php esc_html_e( 'Add Custom Switcher', 'multi-device-switcher' ); ?></th>
|
1069 |
+
<td>
|
1070 |
+
<legend class="screen-reader-text"><span><?php esc_html_e( 'Add Custom Switcher', 'multi-device-switcher' ); ?></span></legend>
|
1071 |
+
<input type="text" name="multi_device_switcher_options[custom_switcher]" id="custom-switcher" value="" size="24">
|
1072 |
+
<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>
|
1073 |
+
<?php esc_html_e( '20 characters max, alphanumeric', 'multi-device-switcher' ); ?>
|
1074 |
+
</td>
|
1075 |
+
</tr>
|
1076 |
+
</table>
|
1077 |
+
|
1078 |
+
</fieldset>
|
1079 |
+
|
1080 |
+
<fieldset id="UserAgent" class="options">
|
1081 |
+
<h3 class="label"><?php esc_html_e( 'UserAgent', 'multi-device-switcher' ); ?></h3>
|
1082 |
+
<p><?php esc_html_e( 'Enter Comma-separated values (csv) format.', 'multi-device-switcher' ); ?></p>
|
1083 |
+
|
1084 |
+
<table class="form-table">
|
1085 |
+
<tr><th scope="row"><?php esc_html_e( 'Smart Phone', 'multi-device-switcher' ); ?></th>
|
1086 |
+
<td><textarea name="multi_device_switcher_options[userAgent_smart]" rows="4" cols="42"><?php echo esc_textarea( $options['userAgent_smart'] ); ?></textarea></td>
|
1087 |
+
</tr>
|
1088 |
+
<tr><th scope="row"><?php esc_html_e( 'Tablet PC', 'multi-device-switcher' ); ?></th>
|
1089 |
+
<td><textarea name="multi_device_switcher_options[userAgent_tablet]" rows="4" cols="42"><?php echo esc_textarea( $options['userAgent_tablet'] ); ?></textarea></td>
|
1090 |
+
</tr>
|
1091 |
+
<tr><th scope="row"><?php esc_html_e( 'Mobile Phone', 'multi-device-switcher' ); ?></th>
|
1092 |
+
<td><textarea name="multi_device_switcher_options[userAgent_mobile]" rows="4" cols="42"><?php echo esc_textarea( $options['userAgent_mobile'] ); ?></textarea></td>
|
1093 |
+
</tr>
|
1094 |
+
<tr><th scope="row"><?php esc_html_e( 'Game Platforms', 'multi-device-switcher' ); ?></th>
|
1095 |
+
<td><textarea name="multi_device_switcher_options[userAgent_game]" rows="4" cols="42"><?php echo esc_textarea( $options['userAgent_game'] ); ?></textarea></td>
|
1096 |
+
</tr>
|
1097 |
+
<tr><th></th>
|
1098 |
+
<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>
|
1099 |
+
</tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1100 |
|
1101 |
+
</table>
|
1102 |
+
|
1103 |
+
<h3><?php esc_html_e( 'Custom Switcher UserAgent', 'multi-device-switcher' ); ?></h3>
|
1104 |
+
<table class="form-table">
|
1105 |
+
<?php
|
1106 |
+
foreach ( (array) $options as $custom_switcher_option => $custom_switcher_user_agent ) {
|
1107 |
+
if ( ! preg_match( '/^custom_switcher_userAgent_/', $custom_switcher_option ) ) {
|
1108 |
+
continue;
|
1109 |
+
}
|
1110 |
+
|
1111 |
+
$custom_switcher_name = preg_replace( '/^custom_switcher_userAgent_/', '', $custom_switcher_option );
|
1112 |
?>
|
1113 |
|
1114 |
+
<tr><th scope="row"><?php echo esc_html( $custom_switcher_name ); ?></th>
|
1115 |
+
<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>
|
1116 |
+
</tr>
|
1117 |
<?php
|
1118 |
+
}
|
1119 |
+
?>
|
1120 |
+
|
1121 |
+
</table>
|
1122 |
+
</fieldset>
|
1123 |
+
|
1124 |
+
<fieldset id="PC-Switcher" class="options">
|
1125 |
+
<h3 class="label"><?php esc_html_e( 'PC Switcher', 'multi-device-switcher' ); ?></h3>
|
1126 |
+
|
1127 |
+
<table class="form-table">
|
1128 |
+
<tr><th scope="row"><?php esc_html_e( 'Add PC Switcher', 'multi-device-switcher' ); ?></th>
|
1129 |
+
<td>
|
1130 |
+
<legend class="screen-reader-text"><span><?php esc_html_e( 'Add PC Switcher', 'multi-device-switcher' ); ?></span></legend>
|
1131 |
+
<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>
|
1132 |
+
</td>
|
1133 |
+
</tr>
|
1134 |
+
<tr><th scope="row"><?php esc_html_e( 'Add default CSS', 'multi-device-switcher' ); ?></th>
|
1135 |
+
<td>
|
1136 |
+
<legend class="screen-reader-text"><span><?php esc_html_e( 'Add default CSS', 'multi-device-switcher' ); ?></span></legend>
|
1137 |
+
<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>
|
1138 |
+
</td>
|
1139 |
+
</tr>
|
1140 |
+
</table>
|
1141 |
+
</fieldset>
|
1142 |
+
|
1143 |
+
<fieldset id="Disable-Switcher" class="options">
|
1144 |
+
<h3 class="label"><?php esc_html_e( 'Disable Switcher', 'multi-device-switcher' ); ?></h3>
|
1145 |
+
|
1146 |
+
<table class="form-table">
|
1147 |
+
<tr><th scope="row"><?php esc_html_e( 'Path', 'multi-device-switcher' ); ?></th>
|
1148 |
+
<td>
|
1149 |
+
<legend class="screen-reader-text"><span><?php esc_html_e( 'Path', 'multi-device-switcher' ); ?></span></legend>
|
1150 |
+
<?php echo esc_html( home_url() ); ?><br>
|
1151 |
+
<textarea name="multi_device_switcher_options[disable_path]" rows="16" cols="42" wrap="off"><?php echo esc_textarea( $options['disable_path'] ); ?></textarea>
|
1152 |
+
</td>
|
1153 |
+
</tr>
|
1154 |
+
<tr><th scope="row"><?php esc_html_e( 'Regex mode', 'multi-device-switcher' ); ?></th>
|
1155 |
+
<td>
|
1156 |
+
<legend class="screen-reader-text"><span><?php esc_html_e( 'Regex mode', 'multi-device-switcher' ); ?></span></legend>
|
1157 |
+
<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>
|
1158 |
+
</td>
|
1159 |
+
</tr>
|
1160 |
+
</table>
|
1161 |
+
</fieldset>
|
1162 |
+
|
1163 |
+
</div>
|
1164 |
+
<?php submit_button(); ?>
|
1165 |
+
</form>
|
1166 |
+
</div>
|
1167 |
|
1168 |
+
<div id="donate">
|
1169 |
+
<h2><?php esc_html_e( 'Donationware', 'multi-device-switcher' ); ?></h2>
|
1170 |
+
<p><?php esc_html_e( 'If you like this plugin, please donate to support development and maintenance.', 'multi-device-switcher' ); ?></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1171 |
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
|
1172 |
<input type="hidden" name="cmd" value="_s-xclick">
|
1173 |
<input type="hidden" name="hosted_button_id" value="9L53NELFMHTWW">
|
1189 |
<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!">
|
1190 |
<img alt="" border="0" src="https://www.paypalobjects.com/ja_JP/i/scr/pixel.gif" width="1" height="1">
|
1191 |
</form>
|
1192 |
+
</div>
|
1193 |
+
<?php
|
1194 |
}
|
1195 |
|
1196 |
/**
|
1197 |
+
* Validate options.
|
1198 |
*
|
1199 |
+
* @access public
|
1200 |
*
|
1201 |
+
* @param array $input
|
1202 |
+
*
|
1203 |
+
* @return array
|
1204 |
*/
|
1205 |
+
public function validate_options( $input ) {
|
1206 |
+
$output = $this->default_options;
|
1207 |
|
1208 |
if ( isset( $input['theme_smartphone'] ) ) {
|
1209 |
$output['theme_smartphone'] = $input['theme_smartphone'];
|
1219 |
}
|
1220 |
|
1221 |
if ( isset( $input['restore_UserAgent'] ) ) {
|
1222 |
+
$output['userAgent_smart'] = $this->default_options['userAgent_smart'];
|
1223 |
+
$output['userAgent_tablet'] = $this->default_options['userAgent_tablet'];
|
1224 |
+
$output['userAgent_mobile'] = $this->default_options['userAgent_mobile'];
|
1225 |
+
$output['userAgent_game'] = $this->default_options['userAgent_game'];
|
1226 |
}
|
1227 |
else {
|
1228 |
if ( isset( $input['userAgent_smart'] ) ) {
|
1268 |
if ( isset( $input['add_custom_switcher'] ) && ! empty( $input['custom_switcher'] ) && ! isset( $output[ 'custom_switcher_theme_' . $input['custom_switcher'] ] ) ) {
|
1269 |
if ( ! in_array( $input['custom_switcher'], array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ) )
|
1270 |
&& preg_match( '/^[A-Za-z0-9]{1,20}$/', $input['custom_switcher'] ) ) {
|
1271 |
+
$output[ 'custom_switcher_theme_' . $input['custom_switcher'] ] = 'None';
|
1272 |
$output[ 'custom_switcher_userAgent_' . $input['custom_switcher'] ] = '';
|
1273 |
}
|
1274 |
}
|
1279 |
$output['disable_path'] = isset( $input['disable_path'] ) ? $input['disable_path'] : '';
|
1280 |
$output['enable_regex'] = isset( $input['enable_regex'] ) ? $input['enable_regex'] : 0;
|
1281 |
|
1282 |
+
/**
|
1283 |
+
* Filter hook: multi_device_switcher/validate_options.
|
1284 |
+
*
|
1285 |
+
* @param array $options The options.
|
1286 |
+
* @param array $input The options.
|
1287 |
+
* @param array $default The options.
|
1288 |
+
*
|
1289 |
+
* @since 1.7.0
|
1290 |
+
*/
|
1291 |
+
return apply_filters( 'multi_device_switcher/validate_options', $output, $input, $this->default_options );
|
1292 |
}
|
1293 |
|
1294 |
/**
|
1295 |
+
* Register customize options to Customizer.
|
1296 |
+
*
|
1297 |
+
* @access public
|
1298 |
+
*
|
1299 |
+
* @param object $wp_customize
|
1300 |
*
|
|
|
1301 |
* @return void
|
1302 |
*
|
1303 |
* @since 1.3.1
|
1304 |
*/
|
1305 |
public function customize_register( $wp_customize ) {
|
1306 |
+
$options = $this->get_options();
|
1307 |
+
$default_theme_options = $this->default_options;
|
1308 |
+
$default_theme = wp_get_theme()->get( 'Name' );
|
1309 |
+
$themes = wp_get_themes();
|
1310 |
|
1311 |
$theme_names = array();
|
1312 |
+
$choices = array();
|
1313 |
|
1314 |
if ( count( $themes ) ) {
|
1315 |
foreach ( $themes as $t ) {
|
1317 |
}
|
1318 |
natcasesort( $theme_names );
|
1319 |
|
1320 |
+
$choices['None'] = __( 'None', 'multi-device-switcher' );
|
1321 |
foreach ( $theme_names as $theme_name ) {
|
1322 |
if ( $default_theme === $theme_name ) {
|
1323 |
continue;
|
1327 |
}
|
1328 |
|
1329 |
$switcher = array(
|
1330 |
+
'theme_smartphone' => __( 'Smart Phone Theme', 'multi-device-switcher' ),
|
1331 |
+
'theme_tablet' => __( 'Tablet PC Theme', 'multi-device-switcher' ),
|
1332 |
+
'theme_mobile' => __( 'Mobile Phone Theme', 'multi-device-switcher' ),
|
1333 |
+
'theme_game' => __( 'Game Platforms Theme', 'multi-device-switcher' ),
|
1334 |
);
|
1335 |
|
1336 |
+
$wp_customize->add_section(
|
1337 |
+
'multi_device_switcher',
|
1338 |
+
array(
|
1339 |
+
'title' => __( 'Multi Device Switcher', 'multi-device-switcher' ),
|
1340 |
+
'priority' => 80,
|
1341 |
+
)
|
1342 |
+
);
|
1343 |
|
1344 |
foreach ( $switcher as $name => $label ) {
|
1345 |
+
$wp_customize->add_setting(
|
1346 |
+
'multi_device_switcher_options[' . $name . ']',
|
1347 |
+
array(
|
1348 |
+
'default' => $default_theme_options[ $name ],
|
1349 |
+
'type' => 'option',
|
1350 |
+
'capability' => $this->capability,
|
1351 |
+
)
|
1352 |
+
);
|
1353 |
+
|
1354 |
+
$wp_customize->add_control(
|
1355 |
+
'multi_device_switcher_options[' . $name . ']',
|
1356 |
+
array(
|
1357 |
+
'label' => $label,
|
1358 |
+
'section' => 'multi_device_switcher',
|
1359 |
+
'type' => 'select',
|
1360 |
+
'choices' => $choices,
|
1361 |
+
)
|
1362 |
+
);
|
1363 |
}
|
1364 |
|
1365 |
+
foreach ( (array) $options as $custom_switcher_option => $custom_switcher_theme ) {
|
1366 |
if ( ! preg_match( '/^custom_switcher_theme_/', $custom_switcher_option ) ) {
|
1367 |
continue;
|
1368 |
}
|
1369 |
|
1370 |
$label = preg_replace( '/^custom_switcher_theme_/', '', $custom_switcher_option );
|
1371 |
|
1372 |
+
$wp_customize->add_setting(
|
1373 |
+
'multi_device_switcher_options[' . $custom_switcher_option . ']',
|
1374 |
+
array(
|
1375 |
+
'default' => __( 'None', 'multi-device-switcher' ),
|
1376 |
+
'type' => 'option',
|
1377 |
+
'capability' => $this->capability,
|
1378 |
+
)
|
1379 |
+
);
|
1380 |
+
|
1381 |
+
$wp_customize->add_control(
|
1382 |
+
'multi_device_switcher_options[' . $custom_switcher_option . ']',
|
1383 |
+
array(
|
1384 |
+
'label' => $label,
|
1385 |
+
'section' => 'multi_device_switcher',
|
1386 |
+
'type' => 'select',
|
1387 |
+
'choices' => $choices,
|
1388 |
+
)
|
1389 |
+
);
|
1390 |
|
1391 |
}
|
1392 |
}
|
1393 |
|
1394 |
+
/**
|
1395 |
+
* Load files.
|
1396 |
+
*
|
1397 |
+
* @access public
|
1398 |
+
*
|
1399 |
+
* @since 1.0.0
|
1400 |
+
*/
|
1401 |
public function load_file() {
|
1402 |
/**
|
1403 |
+
* Include PC Switcher Widget.
|
1404 |
*
|
1405 |
* @since 1.2
|
|
|
1406 |
*/
|
1407 |
+
require_once dirname( __MULTI_DEVICE_SWITCHER_FILE__ ) . '/pc-switcher-widget.php';
|
1408 |
|
1409 |
/**
|
1410 |
+
* Include Multi Device Switcher Command
|
1411 |
*
|
1412 |
* @since 1.4
|
|
|
1413 |
*/
|
1414 |
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
1415 |
+
require_once dirname( __MULTI_DEVICE_SWITCHER_FILE__ ) . '/wp-cli.php';
|
1416 |
}
|
1417 |
}
|
1418 |
}
|
1420 |
define( '__MULTI_DEVICE_SWITCHER_FILE__', __FILE__ );
|
1421 |
|
1422 |
if ( class_exists( 'Multi_Device_Switcher' ) ) {
|
1423 |
+
global $multi_device_switcher;
|
1424 |
$multi_device_switcher = new Multi_Device_Switcher();
|
1425 |
};
|
1426 |
|
1428 |
* Add PC Switcher.
|
1429 |
*
|
1430 |
* @since 1.2
|
|
|
1431 |
*/
|
1432 |
function multi_device_switcher_add_pc_switcher() {
|
1433 |
global $multi_device_switcher;
|
1440 |
* Return boolean whether a particular device.
|
1441 |
*
|
1442 |
* @since 1.2.4
|
|
|
1443 |
*/
|
1444 |
if ( ! function_exists( 'is_multi_device' ) ) :
|
1445 |
|
1446 |
+
function is_multi_device( $device = '' ) {
|
1447 |
+
global $multi_device_switcher;
|
1448 |
+
if ( is_object( $multi_device_switcher ) ) {
|
1449 |
+
return $multi_device_switcher->is_multi_device( $device );
|
1450 |
+
}
|
1451 |
}
|
|
|
1452 |
endif;
|
1453 |
|
1454 |
/**
|
1455 |
* Return the state of PC Switcher.
|
1456 |
*
|
1457 |
* @since 1.4.1
|
|
|
1458 |
*/
|
1459 |
if ( ! function_exists( 'is_pc_switcher' ) ) :
|
1460 |
|
1461 |
+
function is_pc_switcher() {
|
1462 |
+
global $multi_device_switcher;
|
1463 |
+
if ( is_object( $multi_device_switcher ) ) {
|
1464 |
+
return $multi_device_switcher->is_pc_switcher();
|
1465 |
+
}
|
1466 |
}
|
|
|
1467 |
endif;
|
1468 |
|
1469 |
/**
|
1470 |
* Return the state of disabled.
|
1471 |
*
|
1472 |
* @since 1.4.1
|
|
|
1473 |
*/
|
1474 |
if ( ! function_exists( 'is_disable_switcher' ) ) :
|
1475 |
|
1476 |
+
function is_disable_switcher() {
|
1477 |
+
global $multi_device_switcher;
|
1478 |
+
if ( is_object( $multi_device_switcher ) ) {
|
1479 |
+
return $multi_device_switcher->is_disable_switcher();
|
1480 |
+
}
|
1481 |
}
|
|
|
1482 |
endif;
|
1483 |
|
1484 |
/**
|
1488 |
*/
|
1489 |
if ( ! function_exists( 'multi_device_switcher_get_default_options' ) ) :
|
1490 |
|
1491 |
+
function multi_device_switcher_get_default_options() {
|
1492 |
+
global $multi_device_switcher;
|
1493 |
+
if ( is_object( $multi_device_switcher ) ) {
|
1494 |
+
return $multi_device_switcher->get_default_options();
|
1495 |
+
}
|
1496 |
}
|
|
|
1497 |
endif;
|
pc-switcher-widget.php
CHANGED
@@ -1,32 +1,17 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Widget Name: PC Switcher Widget
|
4 |
-
* Plugin URI:
|
5 |
* Description: PC Switcher Widget add-on for the Multi Device Switcher. Use this widget to add the PC Switcher to a widget.
|
6 |
-
* Version:
|
7 |
-
* Author:
|
8 |
-
* Author URI:
|
9 |
-
* License:
|
|
|
10 |
* Text Domain: multi-device-switcher
|
11 |
* Domain Path: /languages/
|
12 |
-
*/
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Copyright 2013 thingsym (http://www.thingslabo.com/)
|
16 |
-
*
|
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 |
-
*
|
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.
|
26 |
-
*
|
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 |
*/
|
31 |
|
32 |
/**
|
@@ -42,20 +27,25 @@ function pc_switcher_load_widgets() {
|
|
42 |
register_widget( 'PC_Switcher' );
|
43 |
}
|
44 |
|
|
|
|
|
|
|
|
|
|
|
45 |
class PC_Switcher extends WP_Widget {
|
46 |
|
47 |
-
function __construct() {
|
48 |
load_plugin_textdomain( 'multi-device-switcher', false, dirname( plugin_basename( __MULTI_DEVICE_SWITCHER_FILE__ ) ) . '/languages/' );
|
49 |
|
50 |
$widget_ops = array(
|
51 |
'classname' => 'widget_pc_switcher',
|
52 |
-
'description' => __( 'Add the PC Switcher to a widget.', 'multi-device-switcher' )
|
53 |
);
|
54 |
parent::__construct( 'pc-switcher', __( 'PC Switcher', 'multi-device-switcher' ), $widget_ops );
|
55 |
$this->alt_option_name = 'widget_pc_switcher';
|
56 |
}
|
57 |
|
58 |
-
function widget( $args, $instance ) {
|
59 |
if ( ! function_exists( 'multi_device_switcher_add_pc_switcher' ) ) {
|
60 |
return;
|
61 |
}
|
@@ -70,12 +60,12 @@ class PC_Switcher extends WP_Widget {
|
|
70 |
}
|
71 |
}
|
72 |
|
73 |
-
function update( $new_instance, $old_instance ) {
|
74 |
$instance = $old_instance;
|
75 |
|
76 |
return $instance;
|
77 |
}
|
78 |
|
79 |
-
function form( $instance ) {
|
80 |
}
|
81 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
* Widget Name: PC Switcher Widget
|
4 |
+
* Plugin URI: https://github.com/thingsym/multi-device-switcher
|
5 |
* Description: PC Switcher Widget add-on for the Multi Device Switcher. Use this widget to add the PC Switcher to a widget.
|
6 |
+
* Version: 1.7.0
|
7 |
+
* Author: thingsym
|
8 |
+
* Author URI: http://www.thingslabo.com/
|
9 |
+
* License: GPL2 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 |
*/
|
16 |
|
17 |
/**
|
27 |
register_widget( 'PC_Switcher' );
|
28 |
}
|
29 |
|
30 |
+
/**
|
31 |
+
* Core class PC_Switcher
|
32 |
+
*
|
33 |
+
* @since 1.0.0
|
34 |
+
*/
|
35 |
class PC_Switcher extends WP_Widget {
|
36 |
|
37 |
+
public function __construct() {
|
38 |
load_plugin_textdomain( 'multi-device-switcher', false, dirname( plugin_basename( __MULTI_DEVICE_SWITCHER_FILE__ ) ) . '/languages/' );
|
39 |
|
40 |
$widget_ops = array(
|
41 |
'classname' => 'widget_pc_switcher',
|
42 |
+
'description' => __( 'Add the PC Switcher to a widget.', 'multi-device-switcher' ),
|
43 |
);
|
44 |
parent::__construct( 'pc-switcher', __( 'PC Switcher', 'multi-device-switcher' ), $widget_ops );
|
45 |
$this->alt_option_name = 'widget_pc_switcher';
|
46 |
}
|
47 |
|
48 |
+
public function widget( $args, $instance ) {
|
49 |
if ( ! function_exists( 'multi_device_switcher_add_pc_switcher' ) ) {
|
50 |
return;
|
51 |
}
|
60 |
}
|
61 |
}
|
62 |
|
63 |
+
public function update( $new_instance, $old_instance ) {
|
64 |
$instance = $old_instance;
|
65 |
|
66 |
return $instance;
|
67 |
}
|
68 |
|
69 |
+
public function form( $instance ) {
|
70 |
}
|
71 |
}
|
readme.txt
CHANGED
@@ -6,8 +6,8 @@ Link: https://github.com/thingsym/multi-device-switcher
|
|
6 |
Tags: switcher, theme, ipad, iphone, android, tablet, mobile, game
|
7 |
Requires at least: 3.7
|
8 |
Requires PHP: 5.4
|
9 |
-
Tested up to:
|
10 |
-
Stable tag: 1.
|
11 |
License: GPL2 or later
|
12 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
13 |
|
@@ -19,7 +19,6 @@ This WordPress plugin allows you to set a separate theme for device (Smart Phone
|
|
19 |
This plugin detects if your site is being viewed by UserAgent, and switches to selected theme.
|
20 |
The Custom Switcher can add every device.
|
21 |
|
22 |
-
|
23 |
= Features =
|
24 |
|
25 |
* Set a separate theme for device (Smart Phone, Tablet PC, Mobile Phone, Game), switches to selected theme.
|
@@ -102,7 +101,6 @@ There are three ways how to Using the PC Switcher.
|
|
102 |
* Configure settings. Check the checkbox 'Add a default CSS.' by PC Switcher option. If you want to customize CSS, uncheck the checkbox.
|
103 |
* Have fun!
|
104 |
|
105 |
-
|
106 |
You can design the PC Switcher in the Style Sheet.
|
107 |
|
108 |
**HTML output of the PC Switcher**
|
@@ -315,6 +313,17 @@ None
|
|
315 |
|
316 |
(boolean) Return the state of disabled.
|
317 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
318 |
= Multi Device Switcher Command =
|
319 |
|
320 |
The **Multi Device Switcher Command** is command-line tool.
|
@@ -356,6 +365,28 @@ For more information about the Multi Device Switcher Command, see `wp help multi
|
|
356 |
|
357 |
== Changelog ==
|
358 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
359 |
= 1.6.2 =
|
360 |
* add prefix into hook tag, change tag name from add_header_vary to multi_device_switcher_add_header_vary
|
361 |
* for php5.3, change called function via hook from anonymous function to public function
|
@@ -476,7 +507,7 @@ For more information about the Multi Device Switcher Command, see `wp help multi
|
|
476 |
* fixed: split multi_device_switcher_init() into two functions
|
477 |
|
478 |
= 1.0.0 =
|
479 |
-
* Initial release
|
480 |
|
481 |
== Upgrade Notice ==
|
482 |
|
6 |
Tags: switcher, theme, ipad, iphone, android, tablet, mobile, game
|
7 |
Requires at least: 3.7
|
8 |
Requires PHP: 5.4
|
9 |
+
Tested up to: 5.2.2
|
10 |
+
Stable tag: 1.7.0
|
11 |
License: GPL2 or later
|
12 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
13 |
|
19 |
This plugin detects if your site is being viewed by UserAgent, and switches to selected theme.
|
20 |
The Custom Switcher can add every device.
|
21 |
|
|
|
22 |
= Features =
|
23 |
|
24 |
* Set a separate theme for device (Smart Phone, Tablet PC, Mobile Phone, Game), switches to selected theme.
|
101 |
* Configure settings. Check the checkbox 'Add a default CSS.' by PC Switcher option. If you want to customize CSS, uncheck the checkbox.
|
102 |
* Have fun!
|
103 |
|
|
|
104 |
You can design the PC Switcher in the Style Sheet.
|
105 |
|
106 |
**HTML output of the PC Switcher**
|
313 |
|
314 |
(boolean) Return the state of disabled.
|
315 |
|
316 |
+
= Filter hooks =
|
317 |
+
|
318 |
+
* multi_device_switcher/get_options
|
319 |
+
* multi_device_switcher/get_option
|
320 |
+
* multi_device_switcher/add_header_vary
|
321 |
+
* multi_device_switcher/validate_options
|
322 |
+
|
323 |
+
= Action hooks =
|
324 |
+
|
325 |
+
* multi_device_switcher/detect_device
|
326 |
+
|
327 |
= Multi Device Switcher Command =
|
328 |
|
329 |
The **Multi Device Switcher Command** is command-line tool.
|
365 |
|
366 |
== Changelog ==
|
367 |
|
368 |
+
= 1.7.0 =
|
369 |
+
* add test case for cdn
|
370 |
+
* add multi_device_switcher/detect_device action hook
|
371 |
+
* split switch_theme method into detect_device and switch_theme
|
372 |
+
* fix wp-cli
|
373 |
+
* add bats test case for cli
|
374 |
+
* refactoring with phpstan
|
375 |
+
* fix default options via method
|
376 |
+
* change tag name
|
377 |
+
* change method name
|
378 |
+
* improve get_options method
|
379 |
+
* replace from get_default_options() to class value default_options
|
380 |
+
* fix not valid snake_case format
|
381 |
+
* add public as access modifier keywords
|
382 |
+
* add PHPDoc
|
383 |
+
* add reset-wp-tests.sh, uninstall-wp-tests.sh
|
384 |
+
* fix header
|
385 |
+
* fix textdomain
|
386 |
+
* fix indent and reformat with phpcs and phpcbf
|
387 |
+
* add composer.json for test
|
388 |
+
* add static code analysis config
|
389 |
+
|
390 |
= 1.6.2 =
|
391 |
* add prefix into hook tag, change tag name from add_header_vary to multi_device_switcher_add_header_vary
|
392 |
* for php5.3, change called function via hook from anonymous function to public function
|
507 |
* fixed: split multi_device_switcher_init() into two functions
|
508 |
|
509 |
= 1.0.0 =
|
510 |
+
* Initial release
|
511 |
|
512 |
== Upgrade Notice ==
|
513 |
|
uninstall.php
CHANGED
@@ -1,13 +1,25 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
4 |
exit();
|
5 |
}
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
function multi_device_switcher_delete_plugin() {
|
8 |
delete_option( 'multi_device_switcher_options' );
|
9 |
}
|
10 |
|
11 |
multi_device_switcher_delete_plugin();
|
12 |
-
|
13 |
-
?>
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Uninstall
|
4 |
+
*
|
5 |
+
* @since 1.0.0
|
6 |
+
*
|
7 |
+
* @package Multi_Device_Switcher
|
8 |
+
*/
|
9 |
|
10 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
|
11 |
exit();
|
12 |
}
|
13 |
|
14 |
+
/**
|
15 |
+
* Uninstall.
|
16 |
+
*
|
17 |
+
* @return void
|
18 |
+
*
|
19 |
+
* @since 1.0.0
|
20 |
+
*/
|
21 |
function multi_device_switcher_delete_plugin() {
|
22 |
delete_option( 'multi_device_switcher_options' );
|
23 |
}
|
24 |
|
25 |
multi_device_switcher_delete_plugin();
|
|
|
|
wp-cli.php
CHANGED
@@ -1,51 +1,65 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Multi Device Switcher Command
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
*/
|
5 |
class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
private $options = 'multi_device_switcher_options';
|
8 |
|
9 |
/**
|
10 |
-
*
|
11 |
*
|
12 |
* ## EXAMPLES
|
13 |
*
|
14 |
* wp multi-device status
|
15 |
-
|
16 |
-
*/
|
17 |
public function status( $args, $assoc_args ) {
|
18 |
$options = get_option( $this->options );
|
19 |
-
$rows
|
20 |
|
21 |
$slug_table = array( 'None' => '' );
|
22 |
-
$themes
|
23 |
foreach ( $themes as $theme_slug => $header ) {
|
24 |
$slug_table[ $header->get( 'Name' ) ] = $theme_slug;
|
25 |
}
|
26 |
|
27 |
$rows[] = array(
|
28 |
-
'Device'
|
29 |
-
'Theme'
|
30 |
-
'Slug'
|
31 |
'UserAgent' => $options['userAgent_smart'],
|
32 |
);
|
33 |
$rows[] = array(
|
34 |
-
'Device'
|
35 |
-
'Theme'
|
36 |
-
'Slug'
|
37 |
'UserAgent' => $options['userAgent_tablet'],
|
38 |
);
|
39 |
$rows[] = array(
|
40 |
-
'Device'
|
41 |
-
'Theme'
|
42 |
-
'Slug'
|
43 |
'UserAgent' => $options['userAgent_mobile'],
|
44 |
);
|
45 |
$rows[] = array(
|
46 |
-
'Device'
|
47 |
-
'Theme'
|
48 |
-
'Slug'
|
49 |
'UserAgent' => $options['userAgent_game'],
|
50 |
);
|
51 |
|
@@ -57,21 +71,21 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
57 |
$custom_switcher_name = preg_replace( '/^custom_switcher_theme_/', '', $custom_switcher_option );
|
58 |
|
59 |
$rows[] = array(
|
60 |
-
'Device'
|
61 |
-
'Theme'
|
62 |
-
'Slug'
|
63 |
'UserAgent' => $options[ 'custom_switcher_userAgent_' . $custom_switcher_name ],
|
64 |
);
|
65 |
}
|
66 |
|
67 |
-
$default_theme
|
68 |
$default_theme .= ' | ';
|
69 |
$default_theme .= get_stylesheet();
|
70 |
WP_CLI::line( 'Active Theme: ' . $default_theme );
|
71 |
|
72 |
WP_CLI\Utils\format_items( 'table', $rows, array( 'Device', 'Theme', 'Slug', 'UserAgent' ) );
|
73 |
|
74 |
-
$line
|
75 |
$line .= 'PC Switcher: ';
|
76 |
$line .= $options['pc_switcher'] ? 'on' : 'off';
|
77 |
$line .= "\n";
|
@@ -82,7 +96,7 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
82 |
}
|
83 |
|
84 |
/**
|
85 |
-
*
|
86 |
*
|
87 |
* ## OPTIONS
|
88 |
*
|
@@ -109,10 +123,10 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
109 |
* wp multi-device theme smartphone --theme='Twenty Fifteen'
|
110 |
*
|
111 |
* @synopsis <device> [<slug>] [--theme=<theme>]
|
112 |
-
|
113 |
public function theme( $args, $assoc_args ) {
|
114 |
-
$name
|
115 |
-
$slug
|
116 |
$theme = isset( $assoc_args['theme'] ) ? $assoc_args['theme'] : null;
|
117 |
|
118 |
$options = get_option( $this->options );
|
@@ -124,7 +138,7 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
124 |
}
|
125 |
|
126 |
$slug_table = array( 'None' => '' );
|
127 |
-
$themes
|
128 |
foreach ( $themes as $theme_slug => $header ) {
|
129 |
$slug_table[ $header->get( 'Name' ) ] = $theme_slug;
|
130 |
if ( $slug == $theme_slug ) {
|
@@ -132,6 +146,10 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
132 |
}
|
133 |
}
|
134 |
|
|
|
|
|
|
|
|
|
135 |
if ( isset( $theme ) ) {
|
136 |
$default_theme = wp_get_theme()->get( 'Name' );
|
137 |
if ( $default_theme == $theme ) {
|
@@ -151,7 +169,7 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
151 |
update_option( $this->options, $options );
|
152 |
WP_CLI::success( 'switch ' . $name . ' theme to ' . $theme );
|
153 |
}
|
154 |
-
|
155 |
$options[ 'custom_switcher_theme_' . $name ] = $theme;
|
156 |
|
157 |
update_option( $this->options, $options );
|
@@ -168,7 +186,7 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
168 |
}
|
169 |
WP_CLI::success( $options[ 'theme_' . $name ] . ' | ' . $slug_table[ $options[ 'theme_' . $name ] ] );
|
170 |
}
|
171 |
-
|
172 |
WP_CLI::success( $options[ 'custom_switcher_theme_' . $name ] . ' | ' . $slug_table[ $options[ 'custom_switcher_theme_' . $name ] ] );
|
173 |
}
|
174 |
else {
|
@@ -178,7 +196,7 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
178 |
}
|
179 |
|
180 |
/**
|
181 |
-
*
|
182 |
*
|
183 |
* ## OPTIONS
|
184 |
*
|
@@ -198,9 +216,9 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
198 |
* wp multi-device useragent tablet 'iPad, Kindle, Sony Tablet, Nexus 7'
|
199 |
*
|
200 |
* @synopsis <device> [<UserAgent>]
|
201 |
-
|
202 |
public function useragent( $args, $assoc_args ) {
|
203 |
-
$name
|
204 |
$useragent = isset( $args[1] ) ? $args[1] : null;
|
205 |
|
206 |
$options = get_option( $this->options );
|
@@ -215,7 +233,7 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
215 |
update_option( $this->options, $options );
|
216 |
WP_CLI::success( 'set ' . $name . ' UserAgent to ' . $useragent );
|
217 |
}
|
218 |
-
|
219 |
$options[ 'custom_switcher_userAgent_' . $name ] = $useragent;
|
220 |
|
221 |
update_option( $this->options, $options );
|
@@ -232,7 +250,7 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
232 |
}
|
233 |
WP_CLI::success( $options[ 'userAgent_' . $name ] );
|
234 |
}
|
235 |
-
|
236 |
WP_CLI::success( $options[ 'custom_switcher_userAgent_' . $name ] );
|
237 |
}
|
238 |
else {
|
@@ -242,29 +260,29 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
242 |
}
|
243 |
|
244 |
/**
|
245 |
-
*
|
246 |
*
|
247 |
* ## EXAMPLES
|
248 |
*
|
249 |
* wp multi-device reset
|
250 |
*
|
251 |
* @synopsis
|
252 |
-
|
253 |
public function reset( $args, $assoc_args ) {
|
254 |
-
$options
|
255 |
$default_options = multi_device_switcher_get_default_options();
|
256 |
|
257 |
-
$options['userAgent_smart']
|
258 |
$options['userAgent_tablet'] = $default_options['userAgent_tablet'];
|
259 |
$options['userAgent_mobile'] = $default_options['userAgent_mobile'];
|
260 |
-
$options['userAgent_game']
|
261 |
|
262 |
update_option( $this->options, $options );
|
263 |
WP_CLI::success( 'reset Settings to Default UserAgent' );
|
264 |
}
|
265 |
|
266 |
/**
|
267 |
-
*
|
268 |
*
|
269 |
* ## OPTIONS
|
270 |
*
|
@@ -294,20 +312,19 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
294 |
* wp multi-device add example --theme='Twenty Fifteen'
|
295 |
*
|
296 |
* @synopsis <device> [<slug>] [<UserAgent>] [--theme=<theme>]
|
297 |
-
|
298 |
-
|
299 |
public function add( $args, $assoc_args ) {
|
300 |
-
$name
|
301 |
-
$slug
|
302 |
$useragent = isset( $args[2] ) ? $args[2] : null;
|
303 |
-
$theme
|
304 |
|
305 |
if ( ! preg_match( '/^[A-Za-z0-9]{1,20}$/', $name ) ) {
|
306 |
WP_CLI::error( '20 characters max, alphanumeric' );
|
307 |
}
|
308 |
|
309 |
$slug_table = array( 'None' => '' );
|
310 |
-
$themes
|
311 |
foreach ( $themes as $theme_slug => $header ) {
|
312 |
$slug_table[ $header->get( 'Name' ) ] = $theme_slug;
|
313 |
if ( ! isset( $assoc_args['theme'] ) && $slug == $theme_slug ) {
|
@@ -317,9 +334,9 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
317 |
|
318 |
$options = get_option( $this->options );
|
319 |
if ( in_array( $name, array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ) ) ) {
|
320 |
-
WP_CLI::error( 'can\'t add
|
321 |
}
|
322 |
-
|
323 |
WP_CLI::error( 'Custom Switcher already exists' );
|
324 |
}
|
325 |
else {
|
@@ -333,7 +350,7 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
333 |
$options[ 'custom_switcher_theme_' . $name ] = $theme;
|
334 |
}
|
335 |
else {
|
336 |
-
WP_CLI::error( $
|
337 |
}
|
338 |
}
|
339 |
else {
|
@@ -348,7 +365,7 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
348 |
}
|
349 |
|
350 |
/**
|
351 |
-
*
|
352 |
*
|
353 |
* ## OPTIONS
|
354 |
*
|
@@ -361,7 +378,7 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
361 |
* wp multi-device delete example
|
362 |
*
|
363 |
* @synopsis <device>
|
364 |
-
|
365 |
public function delete( $args, $assoc_args ) {
|
366 |
$name = isset( $args[0] ) ? $args[0] : null;
|
367 |
|
@@ -370,7 +387,7 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
370 |
if ( in_array( $name, array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ) ) ) {
|
371 |
WP_CLI::error( 'Default Switcher can\'t delete' );
|
372 |
}
|
373 |
-
|
374 |
unset( $options[ 'custom_switcher_theme_' . $name ] );
|
375 |
unset( $options[ 'custom_switcher_userAgent_' . $name ] );
|
376 |
|
@@ -383,7 +400,7 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
383 |
}
|
384 |
|
385 |
/**
|
386 |
-
*
|
387 |
*
|
388 |
* ## OPTIONS
|
389 |
*
|
@@ -401,7 +418,7 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
401 |
*
|
402 |
* @synopsis <flag>
|
403 |
* @subcommand pc-switcher
|
404 |
-
|
405 |
public function pc_switcher( $args, $assoc_args ) {
|
406 |
$flag = isset( $args[0] ) ? $args[0] : null;
|
407 |
|
@@ -412,7 +429,7 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
412 |
update_option( $this->options, $options );
|
413 |
WP_CLI::success( 'turn on PC Switcher' );
|
414 |
}
|
415 |
-
|
416 |
$options['pc_switcher'] = 0;
|
417 |
update_option( $this->options, $options );
|
418 |
WP_CLI::success( 'turn off PC Switcher' );
|
@@ -423,7 +440,7 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
423 |
}
|
424 |
|
425 |
/**
|
426 |
-
*
|
427 |
*
|
428 |
* ## OPTIONS
|
429 |
*
|
@@ -440,7 +457,7 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
440 |
* wp multi-device css off
|
441 |
*
|
442 |
* @synopsis <flag>
|
443 |
-
|
444 |
public function css( $args, $assoc_args ) {
|
445 |
$flag = isset( $args[0] ) ? $args[0] : null;
|
446 |
|
@@ -451,7 +468,7 @@ class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
|
451 |
update_option( $this->options, $options );
|
452 |
WP_CLI::success( 'turn on default CSS' );
|
453 |
}
|
454 |
-
|
455 |
$options['default_css'] = 0;
|
456 |
update_option( $this->options, $options );
|
457 |
WP_CLI::success( 'turn off default CSS' );
|
1 |
<?php
|
2 |
/**
|
3 |
* Multi Device Switcher Command
|
4 |
+
*
|
5 |
+
* @package Multi_Device_Switcher
|
6 |
+
*/
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Core class Multi_Device_Switcher_Command
|
10 |
+
*
|
11 |
+
* @since 1.0.0
|
12 |
*/
|
13 |
class Multi_Device_Switcher_Command extends WP_CLI_Command {
|
14 |
|
15 |
+
/**
|
16 |
+
* Protected value.
|
17 |
+
*
|
18 |
+
* @access protected
|
19 |
+
*
|
20 |
+
* @var string $options The option name
|
21 |
+
*/
|
22 |
private $options = 'multi_device_switcher_options';
|
23 |
|
24 |
/**
|
25 |
+
* Get status of settings
|
26 |
*
|
27 |
* ## EXAMPLES
|
28 |
*
|
29 |
* wp multi-device status
|
30 |
+
*/
|
|
|
31 |
public function status( $args, $assoc_args ) {
|
32 |
$options = get_option( $this->options );
|
33 |
+
$rows = array();
|
34 |
|
35 |
$slug_table = array( 'None' => '' );
|
36 |
+
$themes = wp_get_themes();
|
37 |
foreach ( $themes as $theme_slug => $header ) {
|
38 |
$slug_table[ $header->get( 'Name' ) ] = $theme_slug;
|
39 |
}
|
40 |
|
41 |
$rows[] = array(
|
42 |
+
'Device' => 'smartphone (Smart Phone)',
|
43 |
+
'Theme' => $options['theme_smartphone'],
|
44 |
+
'Slug' => $slug_table[ $options['theme_smartphone'] ],
|
45 |
'UserAgent' => $options['userAgent_smart'],
|
46 |
);
|
47 |
$rows[] = array(
|
48 |
+
'Device' => 'tablet (Tablet PC)',
|
49 |
+
'Theme' => $options['theme_tablet'],
|
50 |
+
'Slug' => $slug_table[ $options['theme_tablet'] ],
|
51 |
'UserAgent' => $options['userAgent_tablet'],
|
52 |
);
|
53 |
$rows[] = array(
|
54 |
+
'Device' => 'mobile (Mobile Phone)',
|
55 |
+
'Theme' => $options['theme_mobile'],
|
56 |
+
'Slug' => $slug_table[ $options['theme_mobile'] ],
|
57 |
'UserAgent' => $options['userAgent_mobile'],
|
58 |
);
|
59 |
$rows[] = array(
|
60 |
+
'Device' => 'game (Game Platforms)',
|
61 |
+
'Theme' => $options['theme_game'],
|
62 |
+
'Slug' => $slug_table[ $options['theme_game'] ],
|
63 |
'UserAgent' => $options['userAgent_game'],
|
64 |
);
|
65 |
|
71 |
$custom_switcher_name = preg_replace( '/^custom_switcher_theme_/', '', $custom_switcher_option );
|
72 |
|
73 |
$rows[] = array(
|
74 |
+
'Device' => $custom_switcher_name,
|
75 |
+
'Theme' => $options[ 'custom_switcher_theme_' . $custom_switcher_name ],
|
76 |
+
'Slug' => $slug_table[ $options[ 'custom_switcher_theme_' . $custom_switcher_name ] ],
|
77 |
'UserAgent' => $options[ 'custom_switcher_userAgent_' . $custom_switcher_name ],
|
78 |
);
|
79 |
}
|
80 |
|
81 |
+
$default_theme = wp_get_theme()->get( 'Name' );
|
82 |
$default_theme .= ' | ';
|
83 |
$default_theme .= get_stylesheet();
|
84 |
WP_CLI::line( 'Active Theme: ' . $default_theme );
|
85 |
|
86 |
WP_CLI\Utils\format_items( 'table', $rows, array( 'Device', 'Theme', 'Slug', 'UserAgent' ) );
|
87 |
|
88 |
+
$line = '';
|
89 |
$line .= 'PC Switcher: ';
|
90 |
$line .= $options['pc_switcher'] ? 'on' : 'off';
|
91 |
$line .= "\n";
|
96 |
}
|
97 |
|
98 |
/**
|
99 |
+
* Get or Switch a theme
|
100 |
*
|
101 |
* ## OPTIONS
|
102 |
*
|
123 |
* wp multi-device theme smartphone --theme='Twenty Fifteen'
|
124 |
*
|
125 |
* @synopsis <device> [<slug>] [--theme=<theme>]
|
126 |
+
*/
|
127 |
public function theme( $args, $assoc_args ) {
|
128 |
+
$name = isset( $args[0] ) ? $args[0] : null;
|
129 |
+
$slug = isset( $args[1] ) ? $args[1] : null;
|
130 |
$theme = isset( $assoc_args['theme'] ) ? $assoc_args['theme'] : null;
|
131 |
|
132 |
$options = get_option( $this->options );
|
138 |
}
|
139 |
|
140 |
$slug_table = array( 'None' => '' );
|
141 |
+
$themes = wp_get_themes();
|
142 |
foreach ( $themes as $theme_slug => $header ) {
|
143 |
$slug_table[ $header->get( 'Name' ) ] = $theme_slug;
|
144 |
if ( $slug == $theme_slug ) {
|
146 |
}
|
147 |
}
|
148 |
|
149 |
+
if ( isset( $slug ) && is_null( $theme ) ) {
|
150 |
+
WP_CLI::error( $slug . ' theme is not installed' );
|
151 |
+
}
|
152 |
+
|
153 |
if ( isset( $theme ) ) {
|
154 |
$default_theme = wp_get_theme()->get( 'Name' );
|
155 |
if ( $default_theme == $theme ) {
|
169 |
update_option( $this->options, $options );
|
170 |
WP_CLI::success( 'switch ' . $name . ' theme to ' . $theme );
|
171 |
}
|
172 |
+
elseif ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) {
|
173 |
$options[ 'custom_switcher_theme_' . $name ] = $theme;
|
174 |
|
175 |
update_option( $this->options, $options );
|
186 |
}
|
187 |
WP_CLI::success( $options[ 'theme_' . $name ] . ' | ' . $slug_table[ $options[ 'theme_' . $name ] ] );
|
188 |
}
|
189 |
+
elseif ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) {
|
190 |
WP_CLI::success( $options[ 'custom_switcher_theme_' . $name ] . ' | ' . $slug_table[ $options[ 'custom_switcher_theme_' . $name ] ] );
|
191 |
}
|
192 |
else {
|
196 |
}
|
197 |
|
198 |
/**
|
199 |
+
* Get or Set UserAgent
|
200 |
*
|
201 |
* ## OPTIONS
|
202 |
*
|
216 |
* wp multi-device useragent tablet 'iPad, Kindle, Sony Tablet, Nexus 7'
|
217 |
*
|
218 |
* @synopsis <device> [<UserAgent>]
|
219 |
+
*/
|
220 |
public function useragent( $args, $assoc_args ) {
|
221 |
+
$name = isset( $args[0] ) ? $args[0] : null;
|
222 |
$useragent = isset( $args[1] ) ? $args[1] : null;
|
223 |
|
224 |
$options = get_option( $this->options );
|
233 |
update_option( $this->options, $options );
|
234 |
WP_CLI::success( 'set ' . $name . ' UserAgent to ' . $useragent );
|
235 |
}
|
236 |
+
elseif ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) {
|
237 |
$options[ 'custom_switcher_userAgent_' . $name ] = $useragent;
|
238 |
|
239 |
update_option( $this->options, $options );
|
250 |
}
|
251 |
WP_CLI::success( $options[ 'userAgent_' . $name ] );
|
252 |
}
|
253 |
+
elseif ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) {
|
254 |
WP_CLI::success( $options[ 'custom_switcher_userAgent_' . $name ] );
|
255 |
}
|
256 |
else {
|
260 |
}
|
261 |
|
262 |
/**
|
263 |
+
* Reset Settings to Default UserAgent
|
264 |
*
|
265 |
* ## EXAMPLES
|
266 |
*
|
267 |
* wp multi-device reset
|
268 |
*
|
269 |
* @synopsis
|
270 |
+
*/
|
271 |
public function reset( $args, $assoc_args ) {
|
272 |
+
$options = get_option( $this->options );
|
273 |
$default_options = multi_device_switcher_get_default_options();
|
274 |
|
275 |
+
$options['userAgent_smart'] = $default_options['userAgent_smart'];
|
276 |
$options['userAgent_tablet'] = $default_options['userAgent_tablet'];
|
277 |
$options['userAgent_mobile'] = $default_options['userAgent_mobile'];
|
278 |
+
$options['userAgent_game'] = $default_options['userAgent_game'];
|
279 |
|
280 |
update_option( $this->options, $options );
|
281 |
WP_CLI::success( 'reset Settings to Default UserAgent' );
|
282 |
}
|
283 |
|
284 |
/**
|
285 |
+
* Add Custom Switcher
|
286 |
*
|
287 |
* ## OPTIONS
|
288 |
*
|
312 |
* wp multi-device add example --theme='Twenty Fifteen'
|
313 |
*
|
314 |
* @synopsis <device> [<slug>] [<UserAgent>] [--theme=<theme>]
|
315 |
+
*/
|
|
|
316 |
public function add( $args, $assoc_args ) {
|
317 |
+
$name = isset( $args[0] ) ? $args[0] : null;
|
318 |
+
$slug = isset( $args[1] ) ? $args[1] : null;
|
319 |
$useragent = isset( $args[2] ) ? $args[2] : null;
|
320 |
+
$theme = isset( $assoc_args['theme'] ) ? $assoc_args['theme'] : null;
|
321 |
|
322 |
if ( ! preg_match( '/^[A-Za-z0-9]{1,20}$/', $name ) ) {
|
323 |
WP_CLI::error( '20 characters max, alphanumeric' );
|
324 |
}
|
325 |
|
326 |
$slug_table = array( 'None' => '' );
|
327 |
+
$themes = wp_get_themes();
|
328 |
foreach ( $themes as $theme_slug => $header ) {
|
329 |
$slug_table[ $header->get( 'Name' ) ] = $theme_slug;
|
330 |
if ( ! isset( $assoc_args['theme'] ) && $slug == $theme_slug ) {
|
334 |
|
335 |
$options = get_option( $this->options );
|
336 |
if ( in_array( $name, array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ) ) ) {
|
337 |
+
WP_CLI::error( 'Default Switcher can\'t add' );
|
338 |
}
|
339 |
+
elseif ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) {
|
340 |
WP_CLI::error( 'Custom Switcher already exists' );
|
341 |
}
|
342 |
else {
|
350 |
$options[ 'custom_switcher_theme_' . $name ] = $theme;
|
351 |
}
|
352 |
else {
|
353 |
+
WP_CLI::error( $slug . ' theme is not installed' );
|
354 |
}
|
355 |
}
|
356 |
else {
|
365 |
}
|
366 |
|
367 |
/**
|
368 |
+
* Delete Custom Switcher
|
369 |
*
|
370 |
* ## OPTIONS
|
371 |
*
|
378 |
* wp multi-device delete example
|
379 |
*
|
380 |
* @synopsis <device>
|
381 |
+
*/
|
382 |
public function delete( $args, $assoc_args ) {
|
383 |
$name = isset( $args[0] ) ? $args[0] : null;
|
384 |
|
387 |
if ( in_array( $name, array( 'smartphone', 'smart', 'tablet', 'mobile', 'game' ) ) ) {
|
388 |
WP_CLI::error( 'Default Switcher can\'t delete' );
|
389 |
}
|
390 |
+
elseif ( isset( $options[ 'custom_switcher_theme_' . $name ] ) ) {
|
391 |
unset( $options[ 'custom_switcher_theme_' . $name ] );
|
392 |
unset( $options[ 'custom_switcher_userAgent_' . $name ] );
|
393 |
|
400 |
}
|
401 |
|
402 |
/**
|
403 |
+
* Turn on/off PC Switcher
|
404 |
*
|
405 |
* ## OPTIONS
|
406 |
*
|
418 |
*
|
419 |
* @synopsis <flag>
|
420 |
* @subcommand pc-switcher
|
421 |
+
*/
|
422 |
public function pc_switcher( $args, $assoc_args ) {
|
423 |
$flag = isset( $args[0] ) ? $args[0] : null;
|
424 |
|
429 |
update_option( $this->options, $options );
|
430 |
WP_CLI::success( 'turn on PC Switcher' );
|
431 |
}
|
432 |
+
elseif ( 'off' == $flag ) {
|
433 |
$options['pc_switcher'] = 0;
|
434 |
update_option( $this->options, $options );
|
435 |
WP_CLI::success( 'turn off PC Switcher' );
|
440 |
}
|
441 |
|
442 |
/**
|
443 |
+
* Turn on/off default CSS
|
444 |
*
|
445 |
* ## OPTIONS
|
446 |
*
|
457 |
* wp multi-device css off
|
458 |
*
|
459 |
* @synopsis <flag>
|
460 |
+
*/
|
461 |
public function css( $args, $assoc_args ) {
|
462 |
$flag = isset( $args[0] ) ? $args[0] : null;
|
463 |
|
468 |
update_option( $this->options, $options );
|
469 |
WP_CLI::success( 'turn on default CSS' );
|
470 |
}
|
471 |
+
elseif ( 'off' == $flag ) {
|
472 |
$options['default_css'] = 0;
|
473 |
update_option( $this->options, $options );
|
474 |
WP_CLI::success( 'turn off default CSS' );
|