Multi Device Switcher - Version 1.0.4

Version Description

  • fixed: fix the object model PHP5, _construct() to replace MultiDevice_Switcher
  • fixed: wp_get_themes(), and wp_get_theme() to replace get_themes(), get_theme()
Download this release

Release Info

Developer thingsym
Plugin Icon wp plugin Multi Device Switcher
Version 1.0.4
Comparing to
See all releases

Code changes from version 1.0.3 to 1.0.4

Files changed (3) hide show
  1. multi-device-switcher.php +48 -37
  2. readme.md +3 -0
  3. readme.txt +7 -2
multi-device-switcher.php CHANGED
@@ -3,7 +3,7 @@
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).
6
- Version: 1.0.3
7
  Author: thingsym
8
  Author URI: http://www.thingslabo.com/
9
  License: GPL2
@@ -29,7 +29,7 @@ License: GPL2
29
 
30
  class Multi_Device_Switcher {
31
 
32
- function Multi_Device_Switcher() {
33
 
34
  $userAgent = $this->get_options_userAgent();
35
 
@@ -55,7 +55,7 @@ class Multi_Device_Switcher {
55
  }
56
  }
57
 
58
- function get_options_userAgent() {
59
  $options = get_option('multi_device_switcher_options');
60
  $default_options = multi_device_switcher_get_default_options();
61
 
@@ -80,41 +80,53 @@ class Multi_Device_Switcher {
80
  return $userAgent;
81
  }
82
 
83
- function get_stylesheet($stylesheet = '') {
84
  $name = $this->get_device_theme();
85
 
86
  if ( empty($name) )
87
  return $stylesheet;
88
 
89
- $theme = get_theme($name);
 
 
 
 
 
 
90
 
91
  if ( empty($theme) )
92
  return $stylesheet;
93
 
94
- if ( isset($theme['Status']) && $theme['Status'] != 'publish' )
95
  return $stylesheet;
96
 
97
  return $theme['Stylesheet'];
98
  }
99
 
100
- function get_template($template = '') {
101
  $name = $this->get_device_theme();
102
 
103
  if ( empty($name) )
104
  return $template;
105
 
106
- $theme = get_theme($name);
107
-
 
 
 
 
 
 
108
  if ( empty( $theme ) )
109
  return $template;
110
 
111
- if ( isset($theme['Status']) && $theme['Status'] != 'publish' )
112
  return $template;
113
 
114
  return $theme['Template'];
115
  }
116
 
117
- function get_device_theme() {
118
  $options = get_option('multi_device_switcher_options');
119
 
120
  if ($this->device == 'smart') {
@@ -135,7 +147,7 @@ class Multi_Device_Switcher {
135
  }
136
 
137
  if ( ! is_admin() )
138
- $multi_device_switcher = new Multi_Device_Switcher;
139
 
140
  /**
141
  * Properly enqueue scripts for our multi_device_switcher options page.
@@ -296,13 +308,24 @@ function multi_device_switcher_render_page() {
296
  ?>
297
  <div class="wrap" style="width: 60%; float: left;">
298
  <div id="icon-themes" class="icon32"><br></div>
299
- <h2><?php printf( __( 'Multi Device Switcher', 'multi-device-switcher' ), get_current_theme() ); ?></h2>
300
  <?php settings_errors(); ?>
301
 
302
  <form method="post" action="options.php">
303
  <?php
304
  settings_fields( 'multi_device_switcher' );
305
  $options = multi_device_switcher_get_options();
 
 
 
 
 
 
 
 
 
 
 
306
  ?>
307
 
308
  <div id="admin-tabs">
@@ -313,12 +336,7 @@ function multi_device_switcher_render_page() {
313
  <td>
314
 
315
  <?php
316
- $themes = get_themes();
317
- $default_theme = get_current_theme();
318
-
319
- if (count($themes) > 1) {
320
- $theme_names = array_keys($themes);
321
- natcasesort($theme_names);
322
  $html = '<select name="multi_device_switcher_options[theme_smartphone]">';
323
 
324
  if (($options['theme_smartphone'] == 'None') || ($options['theme_smartphone'] == '')) {
@@ -329,6 +347,8 @@ function multi_device_switcher_render_page() {
329
  }
330
 
331
  foreach ($theme_names as $theme_name) {
 
 
332
  if ($options['theme_smartphone'] == $theme_name) {
333
  $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
334
  }
@@ -346,12 +366,7 @@ function multi_device_switcher_render_page() {
346
  <td>
347
 
348
  <?php
349
- $themes = get_themes();
350
- $default_theme = get_current_theme();
351
-
352
- if (count($themes) > 1) {
353
- $theme_names = array_keys($themes);
354
- natcasesort($theme_names);
355
  $html = '<select name="multi_device_switcher_options[theme_tablet]">';
356
 
357
  if (($options['theme_tablet'] == 'None') || ($options['theme_tablet'] == '')) {
@@ -362,6 +377,8 @@ function multi_device_switcher_render_page() {
362
  }
363
 
364
  foreach ($theme_names as $theme_name) {
 
 
365
  if ($options['theme_tablet'] == $theme_name) {
366
  $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
367
  }
@@ -379,12 +396,7 @@ function multi_device_switcher_render_page() {
379
  <td>
380
 
381
  <?php
382
- $themes = get_themes();
383
- $default_theme = get_current_theme();
384
-
385
- if (count($themes) > 1) {
386
- $theme_names = array_keys($themes);
387
- natcasesort($theme_names);
388
  $html = '<select name="multi_device_switcher_options[theme_mobile]">';
389
 
390
  if (($options['theme_mobile'] == 'None') || ($options['theme_mobile'] == '')) {
@@ -395,6 +407,8 @@ function multi_device_switcher_render_page() {
395
  }
396
 
397
  foreach ($theme_names as $theme_name) {
 
 
398
  if ($options['theme_mobile'] == $theme_name) {
399
  $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
400
  }
@@ -412,12 +426,7 @@ function multi_device_switcher_render_page() {
412
  <td>
413
 
414
  <?php
415
- $themes = get_themes();
416
- $default_theme = get_current_theme();
417
-
418
- if (count($themes) > 1) {
419
- $theme_names = array_keys($themes);
420
- natcasesort($theme_names);
421
  $html = '<select name="multi_device_switcher_options[theme_game]">';
422
 
423
  if (($options['theme_game'] == 'None') || ($options['theme_game'] == '')) {
@@ -428,6 +437,8 @@ function multi_device_switcher_render_page() {
428
  }
429
 
430
  foreach ($theme_names as $theme_name) {
 
 
431
  if ($options['theme_game'] == $theme_name) {
432
  $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
433
  }
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).
6
+ Version: 1.0.4
7
  Author: thingsym
8
  Author URI: http://www.thingslabo.com/
9
  License: GPL2
29
 
30
  class Multi_Device_Switcher {
31
 
32
+ public function __construct() {
33
 
34
  $userAgent = $this->get_options_userAgent();
35
 
55
  }
56
  }
57
 
58
+ public function get_options_userAgent() {
59
  $options = get_option('multi_device_switcher_options');
60
  $default_options = multi_device_switcher_get_default_options();
61
 
80
  return $userAgent;
81
  }
82
 
83
+ public function get_stylesheet($stylesheet = '') {
84
  $name = $this->get_device_theme();
85
 
86
  if ( empty($name) )
87
  return $stylesheet;
88
 
89
+ $themes = wp_get_themes();
90
+ foreach ( $themes as $t ) {
91
+ if ($name == $t->get('Name')) {
92
+ $theme = $t;
93
+ break;
94
+ }
95
+ }
96
 
97
  if ( empty($theme) )
98
  return $stylesheet;
99
 
100
+ if ( $theme->get('Status') != 'publish' )
101
  return $stylesheet;
102
 
103
  return $theme['Stylesheet'];
104
  }
105
 
106
+ public function get_template($template = '') {
107
  $name = $this->get_device_theme();
108
 
109
  if ( empty($name) )
110
  return $template;
111
 
112
+ $themes = wp_get_themes();
113
+ foreach ( $themes as $t ) {
114
+ if ($name == $t->get('Name')) {
115
+ $theme = $t;
116
+ break;
117
+ }
118
+ }
119
+
120
  if ( empty( $theme ) )
121
  return $template;
122
 
123
+ if ( $theme->get('Status') != 'publish' )
124
  return $template;
125
 
126
  return $theme['Template'];
127
  }
128
 
129
+ public function get_device_theme() {
130
  $options = get_option('multi_device_switcher_options');
131
 
132
  if ($this->device == 'smart') {
147
  }
148
 
149
  if ( ! is_admin() )
150
+ $multi_device_switcher = new Multi_Device_Switcher();
151
 
152
  /**
153
  * Properly enqueue scripts for our multi_device_switcher options page.
308
  ?>
309
  <div class="wrap" style="width: 60%; float: left;">
310
  <div id="icon-themes" class="icon32"><br></div>
311
+ <h2><?php printf( __( 'Multi Device Switcher', 'multi-device-switcher' ), wp_get_theme()->get('Name') ); ?></h2>
312
  <?php settings_errors(); ?>
313
 
314
  <form method="post" action="options.php">
315
  <?php
316
  settings_fields( 'multi_device_switcher' );
317
  $options = multi_device_switcher_get_options();
318
+
319
+ $default_theme = wp_get_theme()->get('Name');
320
+ $themes = wp_get_themes();
321
+ $theme_names = array();
322
+
323
+ if (count($themes)) {
324
+ foreach ( $themes as $t ) {
325
+ $theme_names[] = $t->get('Name');
326
+ }
327
+ natcasesort($theme_names);
328
+ }
329
  ?>
330
 
331
  <div id="admin-tabs">
336
  <td>
337
 
338
  <?php
339
+ if (count($theme_names)) {
 
 
 
 
 
340
  $html = '<select name="multi_device_switcher_options[theme_smartphone]">';
341
 
342
  if (($options['theme_smartphone'] == 'None') || ($options['theme_smartphone'] == '')) {
347
  }
348
 
349
  foreach ($theme_names as $theme_name) {
350
+ if ($default_theme == $theme_name)
351
+ continue;
352
  if ($options['theme_smartphone'] == $theme_name) {
353
  $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
354
  }
366
  <td>
367
 
368
  <?php
369
+ if (count($theme_names)) {
 
 
 
 
 
370
  $html = '<select name="multi_device_switcher_options[theme_tablet]">';
371
 
372
  if (($options['theme_tablet'] == 'None') || ($options['theme_tablet'] == '')) {
377
  }
378
 
379
  foreach ($theme_names as $theme_name) {
380
+ if ($default_theme == $theme_name)
381
+ continue;
382
  if ($options['theme_tablet'] == $theme_name) {
383
  $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
384
  }
396
  <td>
397
 
398
  <?php
399
+ if (count($theme_names)) {
 
 
 
 
 
400
  $html = '<select name="multi_device_switcher_options[theme_mobile]">';
401
 
402
  if (($options['theme_mobile'] == 'None') || ($options['theme_mobile'] == '')) {
407
  }
408
 
409
  foreach ($theme_names as $theme_name) {
410
+ if ($default_theme == $theme_name)
411
+ continue;
412
  if ($options['theme_mobile'] == $theme_name) {
413
  $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
414
  }
426
  <td>
427
 
428
  <?php
429
+ if (count($theme_names)) {
 
 
 
 
 
430
  $html = '<select name="multi_device_switcher_options[theme_game]">';
431
 
432
  if (($options['theme_game'] == 'None') || ($options['theme_game'] == '')) {
437
  }
438
 
439
  foreach ($theme_names as $theme_name) {
440
+ if ($default_theme == $theme_name)
441
+ continue;
442
  if ($options['theme_game'] == $theme_name) {
443
  $html .= '<option value="' . $theme_name . '" selected="selected">' . htmlspecialchars($theme_name) . '</option>';
444
  }
readme.md CHANGED
@@ -15,6 +15,9 @@ This plugin detects if your site is being viewed by UserAgent and switches to se
15
 
16
  ## Changelog
17
 
 
 
 
18
  * Version 1.0.3
19
  * updated: update screenshots
20
  * fixed: fix reset button
15
 
16
  ## Changelog
17
 
18
+ * Version 1.0.4
19
+ * fixed: fix the object model PHP5, __construct() to replace Multi_Device_Switcher
20
+ * fixed: wp_get_themes(), and wp_get_theme() to replace get_themes(), get_theme()
21
  * Version 1.0.3
22
  * updated: update screenshots
23
  * fixed: fix reset button
readme.txt CHANGED
@@ -5,8 +5,10 @@ Donate link: http://blog.thingslabo.com/archives/000251.html
5
  Link: https://github.com/thingsym/multi-device-switcher
6
  Tags: switcher, theme, ipad, iphone, android, tablet, mobile, game
7
  Requires at least: 3.2.1
8
- Tested up to: 3.3.1
9
- Stable tag: 1.0.3
 
 
10
 
11
  This WordPress plugin allows you to set a separate theme for device (Smart Phone, Tablet PC, Mobile Phone, Game).
12
 
@@ -32,6 +34,9 @@ This plugin detects if your site is being viewed by UserAgent and switches to se
32
 
33
  == Changelog ==
34
 
 
 
 
35
  = 1.0.3 =
36
  * updated: update screenshots
37
  * fixed: fix reset button
5
  Link: https://github.com/thingsym/multi-device-switcher
6
  Tags: switcher, theme, ipad, iphone, android, tablet, mobile, game
7
  Requires at least: 3.2.1
8
+ Tested up to: 3.4.1
9
+ Stable tag: 1.0.4
10
+ License: GPL2 or later
11
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
13
  This WordPress plugin allows you to set a separate theme for device (Smart Phone, Tablet PC, Mobile Phone, Game).
14
 
34
 
35
  == Changelog ==
36
 
37
+ = 1.0.4 =
38
+ * fixed: fix the object model PHP5, __construct() to replace Multi_Device_Switcher
39
+ * fixed: wp_get_themes(), and wp_get_theme() to replace get_themes(), get_theme()
40
  = 1.0.3 =
41
  * updated: update screenshots
42
  * fixed: fix reset button