Multiple Themes - Version 4.1

Version Description

  • Support for non-alphanumeric characters in URLs, e.g. - languages using characters not in the English alphabet
  • Support for Live Search feature of KnowHow Theme
  • Display errors, not settings, on plugin's Admin page for activated BuddyPress or Theme Test Drive plugins, or old versions of WordPress
  • Add error checking/messages and diagnostic information to plugin's Admin page
Download this release

Release Info

Developer dgewirtz
Plugin Icon 128x128 Multiple Themes
Version 4.1
Comparing to
See all releases

Version 4.1

includes/admin-other.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ add_action( 'all_admin_notices', 'jr_mt_all_admin_notice' );
4
+ // Runs after admin_menu hook
5
+
6
+ function jr_mt_all_admin_notice() {
7
+ if (
8
+ in_array(
9
+ get_current_user_id(),
10
+ get_users(
11
+ array(
12
+ 'role' => 'administrator',
13
+ 'fields' => 'ID'
14
+ )
15
+ )
16
+ )
17
+ )
18
+ {
19
+ // Administrators only see this:
20
+ // echo '<div class="error">Should Show on Every Admin Page</div>';
21
+ }
22
+ }
23
+
24
+ // Add Link to the plugin's entry on the Admin "Plugins" Page, for easy access
25
+ add_filter( 'plugin_action_links_' . jr_mt_plugin_basename(), 'jr_mt_plugin_action_links', 10, 1 );
26
+
27
+ /**
28
+ * Creates Settings entry right on the Plugins Page entry.
29
+ *
30
+ * Helps the user understand where to go immediately upon Activation of the Plugin
31
+ * by creating entries on the Plugins page, right beside Deactivate and Edit.
32
+ *
33
+ * @param array $links Existing links for our Plugin, supplied by WordPress
34
+ * @param string $file Name of Plugin currently being processed
35
+ * @return string $links Updated set of links for our Plugin
36
+ */
37
+ function jr_mt_plugin_action_links( $links ) {
38
+ // The "page=" query string value must be equal to the slug
39
+ // of the Settings admin page.
40
+ array_push( $links, '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=jr_mt_settings' . '">Settings</a>' );
41
+ return $links;
42
+ }
43
+
44
+ ?>
includes/admin.php ADDED
@@ -0,0 +1,588 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // Admin Page
4
+
5
+ require_once( jr_mt_path() . 'includes/admin-other.php' );
6
+
7
+ add_action( 'admin_menu', 'jr_mt_admin_hook' );
8
+ // Runs just after admin_init (below)
9
+
10
+ /**
11
+ * Add Admin Menu item for plugin
12
+ *
13
+ * Plugin needs its own Page in the Settings section of the Admin menu.
14
+ *
15
+ */
16
+ function jr_mt_admin_hook() {
17
+ // Add Settings Page for this Plugin
18
+ global $jr_mt_plugin_data;
19
+ $jr_mt_plugin_data = array_merge( $jr_mt_plugin_data, jr_readme() );
20
+ add_theme_page( $jr_mt_plugin_data['Name'], 'Multiple Themes plugin', 'manage_options', 'jr_mt_settings', 'jr_mt_settings_page' );
21
+ add_options_page( $jr_mt_plugin_data['Name'], 'Multiple Themes plugin', 'manage_options', 'jr_mt_settings', 'jr_mt_settings_page' );
22
+ }
23
+
24
+ /**
25
+ * Settings page for plugin
26
+ *
27
+ * Display and Process Settings page for this plugin.
28
+ *
29
+ */
30
+ function jr_mt_settings_page() {
31
+ global $jr_mt_plugin_data;
32
+ global $jr_mt_themes_cache;
33
+ $jr_mt_themes_cache = wp_get_themes();
34
+ global $jr_mt_plugins_cache;
35
+ $jr_mt_plugins_cache = get_plugins();
36
+ add_thickbox();
37
+ echo '<div class="wrap">';
38
+ screen_icon( 'plugins' );
39
+ echo '<h2>' . $jr_mt_plugin_data['Name'] . '</h2>';
40
+
41
+ // Required because it is only called automatically for Admin Pages in the Settings section
42
+ settings_errors( 'jr_mt_settings' );
43
+
44
+ $theme = wp_get_theme()->Name;
45
+ global $jr_mt_options_cache;
46
+
47
+ $current_wp_version = get_bloginfo( 'version' );
48
+ if ( version_compare( $current_wp_version, $jr_mt_plugin_data['Requires at least'], '<' ) ) {
49
+ // Plugin requires newer version of WordPress
50
+ echo '<h3>Error</h3><p>Here is the problem:<ul><li> &raquo; This Plugin (' . $jr_mt_plugin_data['Name']
51
+ . ') does not support versions of WordPress before WordPress Version '
52
+ . $jr_mt_plugin_data['Requires at least'] . '.</li><li> &raquo; You are running WordPress Version ' . $current_wp_version
53
+ . '.</li><li> &raquo; This Plugin uses the wp_get_themes() function which became available in Version '
54
+ . '3.4.0 of WordPress.</li></ul></p>';
55
+ } else {
56
+ if ( version_compare( $current_wp_version, $jr_mt_plugin_data['Tested up to'], '>' ) ) {
57
+ /* WordPress version is too new:
58
+ When currently-installed version of Plugin was installed,
59
+ it did not support currently-installed version of WordPress.
60
+ So, check if a newer version of plugin is available. */
61
+ $current = FALSE;
62
+ // Check if latest version of the plugin supports this version of WordPress
63
+ if ( !function_exists( 'plugins_api' ) ) {
64
+ require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
65
+ }
66
+ $directory = plugins_api( 'plugin_information', array( 'slug' => $jr_mt_plugin_data['slug'],
67
+ 'fields' => array( 'download_link' => TRUE,
68
+ 'tested' => TRUE,
69
+ 'version' => TRUE,
70
+ 'error_data' => TRUE,
71
+ 'tags' => FALSE,
72
+ 'compatibility' => FALSE,
73
+ 'sections' => FALSE
74
+ )
75
+ ) );
76
+ if ( property_exists( $directory, 'errors' ) && ( $directory->error_data->plugins_api_failed == 'N;' ) ) {
77
+ // Plugin not found in WordPress Directory
78
+ echo '<h3>Warnings</h3><p>Here is the problem:<ul><li> &raquo; This Plugin (' . $jr_mt_plugin_data['Name']
79
+ . ') has not been tested with the version of WordPress you are currently running: ' . $current_wp_version
80
+ . '.</li><li> &raquo; This Plugin could not be found in the WordPress Plugin Directory. '
81
+ . 'If you are sure it should be there, the WordPress Plugin Directory may be currently unavailable or inaccessible from your web server.</li></ul></p>'
82
+ . '<p>The plugin will probably still work with your newer version of WordPress, but you need to be aware of the issue.</p>';
83
+ } else {
84
+ if ( version_compare( $current_wp_version, $directory->tested, '>' ) ) {
85
+ // Latest version of readme.txt for latest version of Plugin indicates that Plugin has not yet been tested for this version of WordPress
86
+ echo '<h3>Warning</h3><p>Here is the problem:<ul><li> &raquo; This Plugin (' . $jr_mt_plugin_data['Name']
87
+ . ') has not been tested with the version of WordPress you are currently running: ' . $current_wp_version
88
+ . '.</li></ul></p>'
89
+ . '<p>The plugin will probably still work with your newer version of WordPress, but you need to be aware of the issue.</p>';
90
+ } else {
91
+ if ( version_compare( $jr_mt_plugin_data['Version'], $directory->version, '=' ) ) {
92
+ /* The latest version of the Plugin has been installed,
93
+ but the readme.txt has been updated in the WordPress Plugin Directory
94
+ to indicate that it now supports the installed version of WordPress.
95
+
96
+ Latest version of Plugin has already been installed, but readme.txt is out of date,
97
+ so update readme.txt. */
98
+
99
+ $errmsg_before = '<h3>Warning</h3><p>Here is the problem:<ul><li> &raquo; This version (' . $jr_mt_plugin_data['Version']
100
+ . ') of this Plugin (' . $jr_mt_plugin_data['Name']
101
+ . ') has been tested with the version of WordPress you are currently running (' . $current_wp_version
102
+ . '), but</li><li> &raquo; The currently installed readme.txt file for this plugin is out of date,'
103
+ . '</li><li> &raquo; The attempt to update the readme.txt from the WordPress Plugin Repository failed, and'
104
+ . '</li><li> &raquo; The specific error is: ';
105
+ $errmsg_after = '</li></ul></p>'
106
+ . '<p>Another attempt will be made to update readme.txt each time this Settings page is displayed.'
107
+ . ' Nonetheless, this plugin should work properly even if readme.txt is out of date.</p>';
108
+
109
+ if ( is_wp_error( $file_name = download_url( $directory->download_link ) ) ) {
110
+ // Error
111
+ echo $errmsg_before . 'The plugin failed to completely download from the WordPress Repository with 300 seconds' . $errmsg_after;
112
+ } else {
113
+ if ( is_int( $resource_handle = zip_open( $file_name ) ) ) {
114
+ // Error
115
+ echo $errmsg_before
116
+ . "php function zip_open error number $resource_handle while attempting to open the plugin's"
117
+ . 'compressed .zip file successfully downloaded from the WordPress Plugin Repository'
118
+ . $errmsg_after;
119
+ } else {
120
+ $find_readme = TRUE;
121
+ while ( $find_readme && ( FALSE !== $dir_ent = zip_read( $resource_handle ) ) ) {
122
+ if ( is_int( $dir_ent ) ) {
123
+ // Error code
124
+ echo $errmsg_before
125
+ . "php function zip_read error number $dir_ent while attempting to read the plugin's"
126
+ . ' compressed .zip file successfully downloaded from the WordPress Plugin Repository'
127
+ . $errmsg_after;
128
+ // Get out of While loop
129
+ $find_readme = FALSE;
130
+ } else {
131
+ // Wait until the While loop gets to the readme.txt entry in the Plugin's Zip file
132
+ if ( zip_entry_name( $dir_ent ) == $jr_mt_plugin_data['slug'] . '/readme.txt' ) {
133
+ if ( FALSE === zip_entry_open( $resource_handle, $dir_ent, 'rb' ) ) {
134
+ // Error
135
+ echo $errmsg_before
136
+ . 'php function zip_entry_open failed to open readme.txt file compressed within plugin .zip file in WordPress Repository'
137
+ . $errmsg_after;
138
+ } else {
139
+ $filesize = zip_entry_filesize( $dir_ent );
140
+ if ( !is_int( $filesize ) || ( $filesize < 100 ) ) {
141
+ // Error
142
+ echo $errmsg_before
143
+ . 'Size, in bytes, of readme.txt file is being incorrectly reported by php function zip_entry_filesize as '
144
+ . var_export( $filesize, TRUE )
145
+ . $errmsg_after;
146
+ } else {
147
+ $readme_content = zip_entry_read( $dir_ent, $filesize );
148
+ if ( ( $readme_content === FALSE ) || ( $readme_content === '' ) ) {
149
+ // Error
150
+ echo $errmsg_before
151
+ . 'php function zip_entry_read failed to read readme.txt file compressed within plugin .zip file in WordPress Repository'
152
+ . $errmsg_after;
153
+ } else {
154
+ if ( FALSE === zip_entry_close( $dir_ent ) ) {
155
+ // Error
156
+ echo $errmsg_before
157
+ . 'php function zip_entry_close failed to close readme.txt file compressed within plugin .zip file in WordPress Repository'
158
+ . $errmsg_after;
159
+ } else {
160
+ // Alternate: file_put_contents( jr_mt_path() . 'readme.txt', $readme_content );
161
+ $write_return = jr_filesystem_text_write( $readme_content, 'readme.txt', jr_mt_path() );
162
+ if ( is_wp_error( $write_return ) || ( FALSE === $write_return ) ) {
163
+ // Error
164
+ echo $errmsg_before
165
+ . 'WP_filesystem failed to store readme.txt file as part of download/update process from WordPress Repository'
166
+ . $errmsg_after;
167
+ }
168
+ }
169
+ }
170
+ }
171
+ }
172
+ // Get out of While loop because we have found and processed readme.txt
173
+ $find_readme = FALSE;
174
+ }
175
+ }
176
+ }
177
+ zip_close( $resource_handle );
178
+ }
179
+ // Delete temporary download file
180
+ if ( !unlink( $file_name ) ) {
181
+ echo $errmsg_before
182
+ . "php unlink function failed to delete downloaded readme.txt in temporary download file $file_name"
183
+ . $errmsg_after;
184
+ }
185
+ }
186
+ $current = TRUE;
187
+ } else {
188
+ // Recommend updating Plugin to latest version which supports the version of WordPress being run,
189
+ // but the currently-installed version of the Plugin does not.
190
+ echo '<h3>Warning</h3><p>This plugin is out of date and should be updated for performance and reliability reasons.'
191
+ . ' Plugin updates are shown on the Plugins-Installed Plugins page and the Dashboard-Updates page here in the Admin panels.</p>';
192
+ }
193
+ }
194
+ }
195
+ } else {
196
+ // Currently-installed version of Plugin supports currently-installed version of WordPress
197
+ $current = TRUE;
198
+ }
199
+
200
+ global $jr_mt_plugins_cache;
201
+
202
+ $compatible = TRUE;
203
+
204
+ // Check for incompatible plugins that have been activated: BuddyPress and Theme Test Drive
205
+ global $jr_mt_incompat_plugins;
206
+ foreach ( $jr_mt_plugins_cache as $rel_path => $plugin_data ) {
207
+ if ( in_array( $plugin_data['Name'], $jr_mt_incompat_plugins ) && is_plugin_active( $rel_path ) ) {
208
+ if ( $compatible ) {
209
+ echo '<h3>Plugin Conflict Error Detected</h3>';
210
+ $compatible = FALSE;
211
+ }
212
+ echo '<p>This Plugin (' . $jr_mt_plugin_data['Name'] . ') cannot be used when the <b>' . $plugin_data['Name']
213
+ . '</b> plugin is Activated. If you wish to use the ' . $jr_mt_plugin_data['Name']
214
+ . ' plugin, please deactivate the ' . $plugin_data['Name']
215
+ . ' plugin (not just when using this Settings page, but whenever the '
216
+ . $jr_mt_plugin_data['Name'] . ' plugin is activated).</p>';
217
+ }
218
+ }
219
+
220
+ if ( $compatible ) {
221
+ ?>
222
+ <h3>Overview</h3>
223
+ <p>This Plugin allows you to selectively change the Theme you have selected as your <b>Current Theme</b> in <b>Appearance-Themes</b> on the Admin panels.
224
+ You can choose from any of the <b>Available Themes</b> listed on the Appearance-Themes Admin panel for:
225
+ <ul>
226
+ <li> &raquo; All Pages</li>
227
+ <li> &raquo; All Posts</li>
228
+ <li> &raquo; The Site Home</li>
229
+ <li> &raquo; A Specific Page</li>
230
+ <li> &raquo; A Specific Post</li>
231
+ <li> &raquo; Any other non-Admin page that has its own Permalink; for example, a specific Archive or Category page</li>
232
+ </ul>
233
+ </p>
234
+ <h3>Important Notes</h3>
235
+ <?php
236
+ if ( function_exists('is_multisite') && is_multisite() ) {
237
+ echo "In a WordPress Network (AKA Multisite), Themes must be <b>Network Enabled</b> before they will appear as Available Themes on individual sites' Appearance-Themes panel.";
238
+ }
239
+ echo '<p>';
240
+ echo "The Current Theme is <b>$theme</b>. You will not normally need to specify it in any of the Settings on this page. The only exception would be if you specify a different Theme for All Pages or All Posts and wish to use the Current Theme for a specific Page, Post or other non-Admin page.";
241
+ echo '</p>';
242
+ if ( $current ) {
243
+ echo '<p>This Plugin (' . $jr_mt_plugin_data['Name'] . ') has been tested with the version of WordPress you are currently running: '
244
+ . $current_wp_version . '</p>';
245
+ }
246
+ if ( jr_mt_plugin_update_available() ) {
247
+ echo '<p>A new version of this Plugin (' . $jr_mt_plugin_data['Name'] . ') is available from the WordPress Repository.'
248
+ . ' We strongly recommend updating ASAP because new versions fix problems that users like yourself have reported to us.'
249
+ . ' <a class="thickbox" title="' . $jr_mt_plugin_data['Name'] . '" href="' . network_admin_url()
250
+ . 'plugin-install.php?tab=plugin-information&plugin=' . $jr_mt_plugin_data['slug']
251
+ . '&section=changelog&TB_iframe=true&width=640&height=768">Click here</a> for more details.</p>';
252
+ }
253
+ echo '<form action="options.php" method="POST">';
254
+
255
+ // Plugin Settings are displayed and entered here:
256
+ settings_fields( 'jr_mt_settings' );
257
+ do_settings_sections( 'jr_mt_settings_page' );
258
+ echo '<p><input name="save" type="submit" value="Save Changes" class="button-primary" /></p></form>';
259
+ }
260
+ }
261
+ echo '<hr /><h3>System Information</h3><p>You are currently running:<ul>';
262
+ echo "<li> &raquo; The {$jr_mt_plugin_data['Name']} plugin Version {$jr_mt_plugin_data['Version']}</li>";
263
+ echo "<li> &nbsp; &raquo;&raquo; The Path to the plugin's directory is " . rtrim( jr_mt_path(), '/' ) . '<li>';
264
+ echo "<li> &nbsp; &raquo;&raquo; The URL to the plugin's directory is " . plugins_url() . "/{$jr_mt_plugin_data['slug']}</li>";
265
+ echo "<li> &raquo; WordPress Version $current_wp_version</li>";
266
+ echo '<li> &nbsp; &raquo;&raquo; WordPress language is set to ' , get_bloginfo( 'language' ) . '</li>';
267
+ echo '<li> &raquo; ' . php_uname( 's' ) . ' operating system, Release/Version ' . php_uname( 'r' ) . ' / ' . php_uname( 'v' ) . '</li>';
268
+ echo '<li> &raquo; ' . php_uname( 'm' ) . ' computer hardware</li>';
269
+ echo '<li> &raquo; Host name ' . php_uname( 'n' ) . '</li>';
270
+ echo '<li> &raquo; php Version ' . phpversion() . '</li>';
271
+ echo '<li> &nbsp; &raquo;&raquo; php memory_limit ' . ini_get('memory_limit') . '</li>';
272
+ echo '<li> &raquo; Zend engine Version ' . zend_version() . '</li>';
273
+ echo '<li> &raquo; Web Server software is ' . getenv( 'SERVER_SOFTWARE' ) . '</li>';
274
+ if ( function_exists( 'apache_get_version' ) && ( FALSE !== $apache = apache_get_version() ) ) {
275
+ echo "<li> &nbsp; &raquo;&raquo; Apache Version $apache</li>";
276
+ }
277
+ global $wpdb;
278
+ echo '<li> &raquo; MySQL Version ' . $wpdb->get_var( 'SELECT VERSION();', 0, 0 ) . '</li>';
279
+
280
+ echo '</ul></p>';
281
+ }
282
+
283
+ add_action( 'admin_init', 'jr_mt_admin_init' );
284
+
285
+ /**
286
+ * Register and define the settings
287
+ *
288
+ * Everything to be stored and/or can be set by the user
289
+ *
290
+ */
291
+ function jr_mt_admin_init() {
292
+ register_setting( 'jr_mt_settings', 'jr_mt_settings', 'jr_mt_validate_settings' );
293
+ add_settings_section( 'jr_mt_all_settings_section',
294
+ 'For All Pages, All Posts and/or Site Home',
295
+ 'jr_mt_all_settings_expl',
296
+ 'jr_mt_settings_page'
297
+ );
298
+ $suffix = array(
299
+ 'Pages' => '<br />(Pages created with Add Page)',
300
+ 'Posts' => ''
301
+ );
302
+ foreach ( array( 'Pages', 'Posts' ) as $thing ) {
303
+ add_settings_field( 'all_' . strtolower( $thing ), "Select Theme for All $thing" . $suffix[$thing], 'jr_mt_echo_all_things', 'jr_mt_settings_page', 'jr_mt_all_settings_section',
304
+ array( 'thing' => $thing ) );
305
+ }
306
+ add_settings_field( 'site_home',
307
+ 'Select Theme for Site Home<br />(' . get_home_url() . ')',
308
+ 'jr_mt_echo_site_home',
309
+ 'jr_mt_settings_page',
310
+ 'jr_mt_all_settings_section'
311
+ );
312
+ $settings = get_option( 'jr_mt_settings' );
313
+ $ids = $settings['ids'];
314
+ if ( !empty( $ids) ) {
315
+ add_settings_section( 'jr_mt_delete_settings_section',
316
+ 'To Display or Delete Theme Selections for Individual Pages or Posts',
317
+ 'jr_mt_delete_settings_expl',
318
+ 'jr_mt_settings_page'
319
+ );
320
+ add_settings_field( 'del_entry', 'Entries:', 'jr_mt_echo_delete_entry', 'jr_mt_settings_page', 'jr_mt_delete_settings_section' );
321
+ }
322
+ add_settings_section( 'jr_mt_single_settings_section',
323
+ 'For An Individual Page, Post or other non-Admin page;<br />or a group of pages, specified by URL Prefix',
324
+ 'jr_mt_single_settings_expl',
325
+ 'jr_mt_settings_page'
326
+ );
327
+ add_settings_field( 'add_theme', 'Theme', 'jr_mt_echo_add_theme', 'jr_mt_settings_page', 'jr_mt_single_settings_section' );
328
+ add_settings_field( 'add_path_id', 'URL of Page, Post, Prefix or other', 'jr_mt_echo_add_path_id', 'jr_mt_settings_page', 'jr_mt_single_settings_section' );
329
+ add_settings_field( 'add_is_prefix', 'Select here if URL is a Prefix', 'jr_mt_echo_add_is_prefix', 'jr_mt_settings_page', 'jr_mt_single_settings_section' );
330
+ }
331
+
332
+ /**
333
+ * Section text for Section1
334
+ *
335
+ * Display an explanation of this Section
336
+ *
337
+ */
338
+ function jr_mt_all_settings_expl() {
339
+ ?>
340
+ <p>
341
+ In this section, you can select a different Theme for All Pages, All Posts and/or Site Home.
342
+ To remove a previously selected Theme, select the blank entry from the drop-down list.
343
+ </p>
344
+ <p>
345
+ In the <i>next</i> section, you will be able to select a Theme, including the Current Theme, to override any choice you make here, for individual Pages, Posts or
346
+ any other non-Admin pages that have their own Permalink; for example, specific Archive or Category pages.
347
+ </p>
348
+ <?php
349
+ }
350
+
351
+ function jr_mt_echo_all_things( $thing ) {
352
+ $settings = get_option( 'jr_mt_settings' );
353
+ $field = 'all_' . strtolower( $thing['thing'] );
354
+ jr_mt_themes_field( $field, $settings[$field], 'jr_mt_settings', TRUE );
355
+ }
356
+
357
+ function jr_mt_echo_site_home() {
358
+ $settings = get_option( 'jr_mt_settings' );
359
+ jr_mt_themes_field( 'site_home', $settings['site_home'], 'jr_mt_settings', FALSE );
360
+ }
361
+
362
+ /**
363
+ * Section text for Section2
364
+ *
365
+ * Display an explanation of this Section
366
+ *
367
+ */
368
+ function jr_mt_delete_settings_expl() {
369
+ ?>
370
+ <p>
371
+ In this section, all entries are displayed for Themes selected for individual Pages, Posts
372
+ and any other non-Admin pages that have their own Permalink; for example, specific Archive or Category pages.
373
+ </p>
374
+ <p>
375
+ You can delete any of these entries by filling in the check box beside each one.
376
+ To change the Theme for an entry, add the same entry with a different Theme in the section below this one.</p>
377
+ <?php
378
+ }
379
+
380
+ function jr_mt_echo_delete_entry() {
381
+ $entry_num = 0;
382
+ $settings = get_option( 'jr_mt_settings' );
383
+ foreach ( $settings['ids'] as $path_id => $opt_array ) {
384
+ ++$entry_num;
385
+ echo "Delete <input type='checkbox' id='del_entry' name='jr_mt_settings[del_entry][]' value='$path_id' /> &nbsp; Theme="
386
+ . wp_get_theme( $opt_array['theme'] )->Name . '; ';
387
+ if ( $path_id == '' ) {
388
+ echo 'Site=<a href="' . get_home_url() . '" target="_blank">Home</a>';
389
+ } else {
390
+ if ( $opt_array['type'] == 'prefix' ) {
391
+ echo 'Prefix=<a href="' . get_home_url() . "/$path_id" . '" target="_blank">' . "$path_id</a>";
392
+ } else {
393
+ if ( $opt_array['type'] == 'cat' ) {
394
+ echo 'Category=<a href="' . get_home_url() . '/?cat=' . $opt_array['id'] . '" target="_blank">' . get_cat_name( $opt_array['id'] ) . '</a>';
395
+ } else {
396
+ if ( $opt_array['type'] == 'archive' ) {
397
+ echo 'Archive=<a href="' . get_home_url() . '/?m=' . $opt_array['id'] . '" target="_blank">' . $opt_array['id'] . '</a>';
398
+ } else {
399
+ $p_array = get_posts( array( 'post_type' => 'any', 'include' => array( $path_id ) ) );
400
+ if ( empty( $p_array ) ) {
401
+ if ( $opt_array['type'] == 'admin' ) {
402
+ echo 'Admin=<a href="' . get_home_url() . '/' . $opt_array['rel_url'] . '" target="_blank">' . "$path_id</a>";
403
+ } else {
404
+ echo 'Path=<a href="' . get_home_url() . "/$path_id" . '" target="_blank">' . "$path_id</a>";
405
+ }
406
+ } else {
407
+ echo ucfirst( $p_array[0]->post_type ) . '=<a href="' . get_permalink( $path_id ) . '" target="_blank">' . $p_array[0]->post_title . '</a>';
408
+ }
409
+ }
410
+ }
411
+ }
412
+ }
413
+ echo '<br />';
414
+ }
415
+ }
416
+
417
+ /**
418
+ * Section text for Section3
419
+ *
420
+ * Display an explanation of this Section
421
+ *
422
+ */
423
+ function jr_mt_single_settings_expl() {
424
+ ?>
425
+ <p>
426
+ Select a Theme for an individual Page, Post or
427
+ any other non-Admin page that has its own Permalink; for example, a specific Archive or Category page.
428
+ Or for a group of pages which have URLs that all begin with the same characters ("Prefix").
429
+ </p>
430
+ <p>
431
+ Then cut and paste the URL of the desired Page, Post, Prefix or other non-Admin page.
432
+ And click the <b>Save Changes</b> button to add the entry.
433
+ </p>
434
+ <?php
435
+ }
436
+
437
+ function jr_mt_echo_add_theme() {
438
+ jr_mt_themes_field( 'add_theme', '', 'jr_mt_settings', FALSE );
439
+ }
440
+
441
+ function jr_mt_echo_add_path_id() {
442
+ ?>
443
+ <input id="add_path_id" name="jr_mt_settings[add_path_id]" type="text" size="100" maxlength="256" value="" />
444
+ <br />
445
+ (cut and paste URL here of Page, Post, Prefix or other)
446
+ <br />
447
+ URL must begin with
448
+ <?php
449
+ echo trim( get_home_url(), '\ /' ) . '/';
450
+ }
451
+
452
+ function jr_mt_echo_add_is_prefix() {
453
+ ?>
454
+ <input type="checkbox" id="add_is_prefix" name="jr_mt_settings[add_is_prefix]" value="true" /> Anything that begins with this URL will use this Theme
455
+ <?php
456
+ }
457
+
458
+ function jr_mt_validate_settings( $input ) {
459
+ $valid = array();
460
+ foreach ( array( 'all_pages', 'all_posts', 'site_home' ) as $thing ) {
461
+ $valid[$thing] = $input[$thing];
462
+ }
463
+
464
+ $settings = get_option( 'jr_mt_settings' );
465
+ $ids = $settings['ids'];
466
+ if ( isset ( $input['del_entry'] ) ) {
467
+ foreach ( $input['del_entry'] as $del_entry ) {
468
+ unset( $ids[$del_entry] );
469
+ }
470
+ }
471
+
472
+ $url = rawurldecode( trim( $input['add_path_id'] ) );
473
+ if ( ( empty( $input['add_theme'] ) && !empty( $url ) ) || ( !empty( $input['add_theme'] ) && empty( $url ) ) ) {
474
+ add_settings_error(
475
+ 'jr_mt_settings',
476
+ 'jr_mt_emptyerror',
477
+ 'Both URL and Theme must be specified to add an Individual entry',
478
+ 'error'
479
+ );
480
+ } else {
481
+ if ( !empty( $url ) ) {
482
+ $validate_url = jr_mt_site_url( $url );
483
+ if ( $validate_url === TRUE ) {
484
+ extract( jr_mt_url_to_id( $url ) );
485
+ if ( isset ( $input['add_is_prefix'] ) && ( $input['add_is_prefix'] == "true" ) ) {
486
+ if ( parse_url( $url, PHP_URL_QUERY ) === NULL ) {
487
+ $ids[$rel_url] = array(
488
+ 'theme' => $input['add_theme'],
489
+ 'type' => 'prefix',
490
+ 'id' => $id,
491
+ 'page_url' => $page_url,
492
+ 'rel_url' => $rel_url,
493
+ 'url' => $url
494
+ );
495
+ } else {
496
+ add_settings_error(
497
+ 'jr_mt_settings',
498
+ 'jr_mt_queryerror',
499
+ '?key=val&key=val Queries are not supported in a URL Prefix',
500
+ 'error'
501
+ );
502
+
503
+ }
504
+ } else {
505
+ if ( $home ) {
506
+ add_settings_error(
507
+ 'jr_mt_settings',
508
+ 'jr_mt_homeerror',
509
+ 'Please use "Select Theme for Site Home" field instead of specifying Site Home URL as an individual entry.',
510
+ 'error'
511
+ );
512
+ } else {
513
+ if ( $type == 'admin' ) {
514
+ add_settings_error(
515
+ 'jr_mt_settings',
516
+ 'jr_mt_adminerror',
517
+ 'Admin Page URLs are not allowed because no known Themes alter the appearance of Admin pages.',
518
+ 'error'
519
+ );
520
+ } else {
521
+ if ( $id === FALSE ) {
522
+ $key = $page_url;
523
+ } else {
524
+ $key = $id;
525
+ }
526
+ $ids[$key] = array(
527
+ 'theme' => $input['add_theme'],
528
+ 'type' => $type,
529
+ 'id' => $id,
530
+ 'page_url' => $page_url,
531
+ 'rel_url' => $rel_url,
532
+ 'url' => $url
533
+ );
534
+ }
535
+ }
536
+ }
537
+ } else {
538
+ add_settings_error(
539
+ 'jr_mt_settings',
540
+ 'jr_mt_urlerror',
541
+ "Invalid URL specified for Individual page/post: '$url'. $validate_url",
542
+ 'error'
543
+ );
544
+ }
545
+ }
546
+ }
547
+ $errors = get_settings_errors();
548
+ if ( empty( $errors ) ) {
549
+ add_settings_error(
550
+ 'jr_mt_settings',
551
+ 'jr_mt_saved',
552
+ 'Settings Saved',
553
+ 'updated'
554
+ );
555
+ }
556
+ $valid['ids'] = $ids;
557
+ return $valid;
558
+ }
559
+
560
+ // $theme_name is the name of the Theme's folder within the Theme directory
561
+ function jr_mt_themes_field( $field_name, $theme_name, $setting, $excl_current_theme ) {
562
+ echo "<select id='$field_name' name='$setting" . "[$field_name]' size='1'>";
563
+ if ( empty( $theme_name ) ) {
564
+ $selected = 'selected="selected"';
565
+ } else {
566
+ $selected = '';
567
+ }
568
+ echo "<option value='' $selected></option>";
569
+ global $jr_mt_themes_cache;
570
+ foreach ( $jr_mt_themes_cache as $folder => $theme_obj ) {
571
+ if ( $excl_current_theme ) {
572
+ if ( ( jr_mt_current_theme( 'stylesheet' ) == $theme_obj['stylesheet'] ) && ( jr_mt_current_theme( 'template' ) == $theme_obj['template'] ) ) {
573
+ // Skip the Current Theme
574
+ continue;
575
+ }
576
+ }
577
+ if ( $theme_name == $folder ) {
578
+ $selected = 'selected="selected"';
579
+ } else {
580
+ $selected = '';
581
+ }
582
+ $name = $theme_obj->Name;
583
+ echo "<option value='$folder' $selected>$name</option>";
584
+ }
585
+ echo '</select>' . PHP_EOL;
586
+ }
587
+
588
+ ?>
includes/debug/debug.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* require_once( jr_mt_path() . 'includes/debug/debug.php' );
3
+ jr_dump( 'jr_mt_validate_settings $input', $input );
4
+ */
5
+
6
+ function jr_dump( $comment, $dump_var ) {
7
+ $file_name = 'jonradio-dump.txt';
8
+
9
+ $header = '***' . current_time('mysql') . ': ' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
10
+ ob_start();;
11
+ echo "$comment: ";
12
+ var_dump( $dump_var );
13
+ $output = ob_get_clean() . jr_dump_env();
14
+ if ( function_exists('is_multisite') && is_multisite() ) {
15
+ global $site_id, $blog_id;
16
+ $file_name = $site_id . '-' . $blog_id . '-' . $file_name;
17
+ }
18
+ $file = fopen( plugin_dir_path( __FILE__ ) . $file_name, 'at' );
19
+ fwrite( $file, $header . PHP_EOL . $output );
20
+ fclose( $file );
21
+
22
+ return;
23
+ }
24
+
25
+ function jr_dump_env() {
26
+ global $jr_dump_env_first;
27
+ if ( isset( $jr_dump_env_first ) ) {
28
+ $output = '';
29
+ } else {
30
+ $jr_dump_env_first = FALSE;
31
+ $output = PHP_EOL;
32
+
33
+ }
34
+ return $output;
35
+ }
36
+ ?>
includes/functions.php ADDED
@@ -0,0 +1,350 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Return WordPress Current Theme, as defined in Appearance Admin panels
4
+ *
5
+ * Obtains Folder Name of Current Theme, from 'template' option of wp_load_alloptions().
6
+ *
7
+ * @param string $option parameter to select current template or stylesheet
8
+ * @return string type Folder Name of Current Theme
9
+ */
10
+ function jr_mt_current_theme( $option ) {
11
+ global $jr_mt_options_cache;
12
+ return $jr_mt_options_cache[$option];
13
+ }
14
+
15
+ /**
16
+ * Given URL, return post or page ID, if possible, and relative path if not
17
+ *
18
+ * Calls jr_mt_query_keywords.
19
+ *
20
+ * @param string $url full URL of WordPress page, post, admin, etc.
21
+ * @return array array with keys of "type", "id" and "page_url":
22
+ * string type "pages", "posts" or "admin"
23
+ * string id Page ID or Post ID or FALSE
24
+ * string page_url relative URL WordPress page, post, admin, etc. or FALSE
25
+ * string rel_url URL relative to WordPress home
26
+ * bool home is URL Site Home?
27
+ */
28
+ function jr_mt_url_to_id( $url_orig ) {
29
+ // Some hosts, likely only IIS, insert an erroneous "/index.php" into the middle of the Permalink in $_SERVER['REQUEST_URI']
30
+ $url = str_replace( '/index.php', '', $url_orig );
31
+
32
+ $trim = '\ /'; // remove leading and trailing backslashes, blanks and forward slashes
33
+
34
+ $is_home = FALSE;
35
+
36
+ // get_home_url() returns "https://subdomain.domain.com/wp" - the full URL of the home page of the site
37
+ $home = trim( parse_url( get_home_url(), PHP_URL_PATH ), $trim ); // "wp"
38
+
39
+ $admin_home = trim( parse_url( admin_url(), PHP_URL_PATH ), $trim );
40
+ $page_url = trim( parse_url( $url, PHP_URL_PATH ), $trim ); // "wp/fruit/apples"
41
+ $is_admin = ( $admin_home == substr( $page_url, 0, strlen( $admin_home ) ) );
42
+ if ( !empty( $home ) ) { // Only if WordPress is installed in a subfolder, NOT in the Root
43
+ $page_url = trim( substr( $page_url, stripos( $page_url, $home ) + strlen( $home ) ), $trim ); // "fruit/apples"
44
+ }
45
+ $rel_url = $page_url;
46
+
47
+ $type = FALSE;
48
+
49
+ $id = jr_mt_query_keywords( parse_url( $url, PHP_URL_QUERY ) );
50
+ if ( $id === NULL ) {
51
+ if ( $is_admin ) {
52
+ $id = FALSE;
53
+ $type = 'admin';
54
+ } else {
55
+ // Check for home page (url_to_postid() does not work for home page)
56
+ if ( empty( $page_url ) ) {
57
+ $is_home = TRUE;
58
+ $id = get_option('page_on_front');
59
+ if ( $id == 0 ) {
60
+ // There is no home Page; posts are displayed instead on the home page
61
+ $page_url = '';
62
+ $id = FALSE;
63
+ } else {
64
+ $type = 'pages';
65
+ }
66
+ } else {
67
+ global $wp_rewrite;
68
+ if ( is_null( $wp_rewrite ) ) {
69
+ $GLOBALS['wp_rewrite'] = new WP_Rewrite();
70
+ }
71
+ global $wp;
72
+ if ( is_null( $wp ) ) {
73
+ $GLOBALS['jr_mt_cache'] = FALSE;
74
+ $wp = (object) array( 'public_query_vars' => array() );
75
+ } else {
76
+ if ( !isset( $wp->public_query_vars ) ) {
77
+ $GLOBALS['jr_mt_cache'] = FALSE;
78
+ $wp->public_query_vars = array();
79
+ }
80
+ }
81
+ $id = url_to_postid( $url );
82
+ if ( $id == 0 ) {
83
+ $id = FALSE;
84
+ } else {
85
+ $post_obj = get_post( $id );
86
+ if ( $post_obj->post_type == 'page' ) {
87
+ $type = 'pages';
88
+ } else {
89
+ if ( $post_obj->post_type == 'post' ) {
90
+ $type = 'posts';
91
+ }
92
+ }
93
+ }
94
+ }
95
+ }
96
+ } else {
97
+ // id in query of URL (?keyword=value&keyword=value)
98
+ $type = key( $id );
99
+ $id = $id[$type];
100
+ $page_url = FALSE;
101
+ }
102
+ return array(
103
+ 'type' => $type,
104
+ 'id' => $id,
105
+ 'page_url' => $page_url,
106
+ 'rel_url' => $rel_url,
107
+ 'home' => $is_home
108
+ );
109
+ }
110
+
111
+ /**
112
+ * Return page_id= or p= (post ID) or page= (admin page) value from a URL
113
+ *
114
+ * Calls parse_str function in its own variable space because it could create virtually any variable name!
115
+ * Only looks at page_id=, p= and page= now, but could be expanded to other query keywords.
116
+ *
117
+ * @param string $url_query Query portion (after the ?) in a URL
118
+ * @return var array with key of "pages", "posts" or "admin" and value of page_id=, p= or page=, respectively; or NULL if none are present
119
+ */
120
+ function jr_mt_query_keywords( $url_query ) {
121
+ if ( $url_query === NULL ) {
122
+ return NULL;
123
+ } else {
124
+ parse_str( $url_query );
125
+ if ( isset( $page_id ) ) {
126
+ return array( 'pages' => $page_id );
127
+ } else {
128
+ if ( isset( $p ) ) {
129
+ return array( 'posts' => $p );
130
+ } else {
131
+ if ( isset( $page ) ) {
132
+ return array( 'admin' => $page );
133
+ } else {
134
+ if ( isset( $cat ) ) {
135
+ return array( 'cat' => $cat );
136
+ } else {
137
+ if ( isset( $m ) ) {
138
+ return array( 'archive' => $m );
139
+ } else {
140
+ if ( isset( $s ) ) {
141
+ return array( 'livesearch' => $s );
142
+ } else {
143
+ return NULL;
144
+ }
145
+ }
146
+ }
147
+ }
148
+ }
149
+ }
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Is the URL on the current WordPress web site?
155
+ *
156
+ * Checks if URL begins with Site Home URL.
157
+ *
158
+ * @param string $url URL to be checked to be sure it is "on" the current WordPress web site
159
+ * @return var bool TRUE if URL on current WordPress web site; string error message otherwise
160
+ */
161
+ function jr_mt_site_url( $url ) {
162
+ $check_url = trim( $url );
163
+ if ( strcasecmp( 'http', substr( $check_url, 0, 4 ) ) != 0 ) {
164
+ return 'URL does not begin with http://';
165
+ }
166
+ $site_home = get_home_url();
167
+ if ( strcasecmp( $site_home, substr( $check_url, 0, strlen( $site_home ) ) ) != 0 ) {
168
+ return "URL specified is not part of current WordPress web site. URL must begin with '$site_home'";
169
+ }
170
+ return TRUE;
171
+ }
172
+
173
+ function jr_readme() {
174
+ $readme = array();
175
+ $file_array = jr_filesystem_text_read('readme.txt', jr_mt_path());
176
+ // Get first non-blank line
177
+ $results = jr_nextline( $file_array, 0 );
178
+ if ( '===' === substr( $results['line'], 0, 3) ) {
179
+ $readme['name'] = trim( $results['line'], ' =' );
180
+ do {
181
+ $results = jr_nextline( $file_array, $results['index'] );
182
+ if ( '==' === substr( $results['line'], 0, 2) ) {
183
+ break;
184
+ } else {
185
+ $colon = strpos( $results['line'], ":", 4 );
186
+ if ( $colon !== FALSE ) {
187
+ $key = preg_replace( '/\s+/', ' ', trim( substr( $results['line'], 0, $colon ) ) );
188
+ $readme[$key] = trim( substr( $results['line'], $colon + 1 ) );
189
+ }
190
+ }
191
+ } while ( $results['line'] != "" );
192
+ }
193
+ return $readme;
194
+ }
195
+ function jr_nextline( $file_array, $index ) {
196
+ $line = "";
197
+ while ( ( $index < count( $file_array ) ) && ( $line === "" ) ) {
198
+ $line = trim( $file_array[$index++] );
199
+ };
200
+ return array( 'line' => $line, 'index' => $index );
201
+ // ['line'] of "" indicates End of File
202
+ // ['index'] is the next line to be read
203
+ }
204
+
205
+ /**
206
+ * Initialize Filesystem object
207
+ *
208
+ * @param str $form_url - URL of the page to display request form
209
+ * @param str $method - connection method
210
+ * @param str $context - destination folder
211
+ * @param array $fields - fileds of $_POST array that should be preserved between screens
212
+ * @return bool/str - false on failure, stored text on success
213
+ **/
214
+ function jr_filesystem_init( $form_url, $method, $context, $fields = null ) {
215
+ global $wp_filesystem;
216
+
217
+ /* first attempt to get credentials */
218
+ if (false === ($creds = request_filesystem_credentials($form_url, $method, false, $context, $fields))) {
219
+
220
+ /**
221
+ * if we comes here - we don't have credentials
222
+ * so the request for them is displaying
223
+ * no need for further processing
224
+ **/
225
+ return false;
226
+ }
227
+
228
+ /* now we got some credentials - try to use them*/
229
+ if ( !WP_Filesystem( $creds ) ) {
230
+
231
+ /* incorrect connection data - ask for credentials again, now with error message */
232
+ request_filesystem_credentials($form_url, $method, true, $context);
233
+ return false;
234
+ }
235
+
236
+ return true; //filesystem object successfully initiated
237
+ }
238
+
239
+ /**
240
+ * Read text from file
241
+ *
242
+ * @param str $form_url - URL of the page where request form will be displayed
243
+ * @return bool/str - false on failure, stored text on success
244
+ **/
245
+ function jr_filesystem_text_read($file_name, $context){
246
+ global $wp_filesystem;
247
+
248
+ $text = '';
249
+
250
+ $form_url = wp_nonce_url('themes.php?page=jr_mt_settings', 'filesystem_dummy_screen');
251
+ $method = ''; //leave this empty to perform test for 'direct' writing
252
+
253
+ if(!jr_filesystem_init($form_url, $method, $context))
254
+ return false; //stop further processing when request forms displaying
255
+
256
+ /*
257
+ * now $wp_filesystem could be used
258
+ * get correct target file first
259
+ **/
260
+ $target_dir = $wp_filesystem->find_folder($context);
261
+ $target_file = trailingslashit($target_dir).$file_name;
262
+
263
+ /* read the file */
264
+ if($wp_filesystem->exists($target_file)){ //check for existence
265
+
266
+ $text = $wp_filesystem->get_contents_array($target_file);
267
+ if(!$text)
268
+ return new WP_Error('reading_error', 'Error when reading file'); //return error object
269
+
270
+ }
271
+
272
+ return $text;
273
+ }
274
+
275
+ /**
276
+ * Perform writing into file
277
+ *
278
+ * @param str $form_url - URL of the page to display request form
279
+ * @return bool/str - false on failure, stored text on success
280
+ **/
281
+ function jr_filesystem_text_write( $content, $file_name, $context ) {
282
+ global $wp_filesystem;
283
+
284
+ $method = ''; //leave this empty to perform test for 'direct' writing
285
+ $form_url = wp_nonce_url('themes.php?page=jr_mt_settings', 'filesystem_dummy_screen');
286
+
287
+ if(!jr_filesystem_init($form_url, $method, $context))
288
+ return false; //stop further processing when request form is displaying
289
+
290
+ /*
291
+ * now $wp_filesystem could be used
292
+ * get correct target file first
293
+ **/
294
+ $target_dir = $wp_filesystem->find_folder($context);
295
+ $target_file = trailingslashit($target_dir) . $file_name;
296
+
297
+ /* write into file */
298
+ if(!$wp_filesystem->put_contents($target_file, $content, FS_CHMOD_FILE))
299
+ return new WP_Error('writing_error', 'Error when writing file'); //return error object
300
+
301
+ return $content;
302
+ }
303
+
304
+ /**
305
+ * Update available for Plugin?
306
+ *
307
+ * @return bool - TRUE if an update is available in the WordPress Repository,
308
+ * FALSE if no update is available or if the update_plugins transient is not available
309
+ * (which also results in an error message).
310
+ **/
311
+ function jr_mt_plugin_update_available() {
312
+ global $jr_mt_update_plugins;
313
+ if ( !isset( $jr_mt_update_plugins ) ) {
314
+ $transient = get_site_transient( 'update_plugins' );
315
+ if ( FALSE === $transient ) {
316
+ // Error
317
+ return FALSE;
318
+ } else {
319
+ $jr_mt_update_plugins = $transient;
320
+ }
321
+ }
322
+ if ( empty( $jr_mt_update_plugins->response ) ) {
323
+ return FALSE;
324
+ }
325
+ return array_key_exists( jr_mt_plugin_basename(), $jr_mt_update_plugins->response );
326
+ }
327
+
328
+ /**
329
+ * What Themes are defined to Plugin?
330
+ *
331
+ * @return arr - a list of Themes (folder names) defined in Settings of Plugin
332
+ **/
333
+ function jr_mt_themes_defined() {
334
+ $themes = array();
335
+ $settings = get_option( 'jr_mt_settings' );
336
+ foreach ( $settings as $key => $value ) {
337
+ if ( 'ids' == $key ) {
338
+ foreach ( $value as $id => $arr ) {
339
+ $themes[] = $arr['theme'];
340
+ }
341
+ } else {
342
+ if ( !empty( $value ) ) {
343
+ $themes[] = $value;
344
+ }
345
+ }
346
+ }
347
+ return array_unique( $themes );
348
+ }
349
+
350
+ ?>
includes/select-theme.php ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Select the relevant Theme
3
+
4
+ add_filter( 'pre_option_stylesheet', 'jr_mt_stylesheet' );
5
+ add_filter( 'pre_option_template', 'jr_mt_template' );
6
+
7
+ function jr_mt_stylesheet() {
8
+ return jr_mt_theme( 'stylesheet' );
9
+ }
10
+
11
+ function jr_mt_template() {
12
+ return jr_mt_theme( 'template' );
13
+ }
14
+
15
+ function jr_mt_theme( $option ) {
16
+ /* The hooks that (indirectly) call this function are called repeatedly by WordPress,
17
+ so do the checking once and store the values in a global array.
18
+ $jt_mt_theme['stylesheet'] - Stylesheet Name of Theme chosen
19
+ $jt_mt_theme['template'] - Template Name of Theme chosen
20
+
21
+ Very important note:
22
+ - get_option( 'jr_mt_settings' ) ['ids']['theme'] is the Theme Subdirectory Name,
23
+ as opposed to the Template or Stylesheet Name for the Theme.
24
+ - likewise, the variable local variable $theme
25
+ These three different values for each Theme must be clearly separated, as all three usually
26
+ match, but do not have to, e.g. - Child Themes.
27
+ */
28
+ $GLOBALS['jr_mt_cache'] = TRUE;
29
+ global $jr_mt_theme;
30
+ if ( !isset( $jr_mt_theme ) ) {
31
+ $jr_mt_theme = array();
32
+ }
33
+ if ( !isset( $jr_mt_theme[$option] ) ) {
34
+ $theme = jr_mt_chosen();
35
+ if ( $theme === FALSE ) {
36
+ // Get both at once, to save a repeat of this logic later:
37
+ $jr_mt_theme['stylesheet'] = jr_mt_current_theme( 'stylesheet' );
38
+ $jr_mt_theme['template'] = jr_mt_current_theme( 'template' );
39
+ } else {
40
+ $themes = wp_get_themes();
41
+ $jr_mt_theme['stylesheet'] = $themes[$theme]->stylesheet;
42
+ $jr_mt_theme['template'] = $themes[$theme]->template;
43
+ }
44
+ }
45
+ $theme = $jr_mt_theme[$option];
46
+ global $jr_mt_cache;
47
+ if ( $jr_mt_cache === FALSE ) {
48
+ unset( $jr_mt_theme[$option] );
49
+ }
50
+ return $theme;
51
+ }
52
+
53
+ // Returns FALSE for Current Theme
54
+ function jr_mt_chosen() {
55
+ if ( is_admin() ) {
56
+ // Admin panel
57
+ // return P2 theme if p2ajax= is present; current theme otherwise
58
+ parse_str( $_SERVER['QUERY_STRING'], $keywords );
59
+ if ( isset( $keywords['p2ajax'] ) && array_key_exists( 'p2', wp_get_themes() ) ) {
60
+ $theme = 'p2';
61
+ } else {
62
+ $theme = FALSE; // Current Theme
63
+ }
64
+ } else {
65
+ // Non-Admin page, i.e. - Public Site, etc.
66
+ extract( jr_mt_url_to_id( rawurldecode( 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] ) ) );
67
+ if ( ( 'livesearch' === $type ) && ( FALSE !== $livesearch_theme = jr_mt_livesearch_theme() ) ) {
68
+ return $livesearch_theme;
69
+ }
70
+ $settings = get_option( 'jr_mt_settings' );
71
+ if ( $home ) {
72
+ if ( trim( $settings['site_home'] ) != '' ) {
73
+ return $settings['site_home'];
74
+ }
75
+ }
76
+ $ids = $settings['ids'];
77
+ if ( $id === FALSE ) {
78
+ if ( isset( $ids[$page_url] ) ) {
79
+ $theme = $ids[$page_url]['theme'];
80
+ } else {
81
+ $theme = jr_mt_check_all( $type, $rel_url, $ids );
82
+ }
83
+ } else {
84
+ if ( isset( $ids[$id] ) ) {
85
+ $theme = $ids[$id]['theme'];
86
+ } else {
87
+ $theme = jr_mt_check_all( $type, $rel_url, $ids );
88
+ }
89
+ }
90
+ }
91
+ return $theme;
92
+ }
93
+
94
+ // Returns FALSE for Current Theme
95
+ function jr_mt_check_all( $type, $rel_url, $ids ) {
96
+ // Check Prefix entries first, because we already know there is no specific entry for this URL.
97
+ $theme = '';
98
+ $match_length = 0;
99
+ foreach ( $ids as $key => $array ) {
100
+ if ( $array['type'] == 'prefix' ) {
101
+ $this_length = strlen( $array['rel_url'] );
102
+ if ( $array['rel_url'] == substr( $rel_url, 0, $this_length ) ) {
103
+ // Need to find longest match if there are multiple prefix matches.
104
+ if ( $this_length > $match_length ) {
105
+ $theme = $array['theme'];
106
+ $match_length = $this_length;
107
+ }
108
+ }
109
+ }
110
+ }
111
+ // See if a Prefix entry was found
112
+ if ( $match_length == 0 ) {
113
+ if ( $type === FALSE ) {
114
+ $theme = FALSE; // Current Theme
115
+ } else {
116
+ $settings = get_option( 'jr_mt_settings' );
117
+ if ( isset( $settings["all_$type"] ) ) {
118
+ $theme = $settings["all_$type"];
119
+ } else {
120
+ $theme = '';
121
+ }
122
+ if ( empty( $theme ) ) {
123
+ $theme = FALSE; // Current Theme
124
+ }
125
+ }
126
+ }
127
+ return $theme;
128
+ }
129
+
130
+ function jr_mt_livesearch_theme() {
131
+ $livesearch_themes = array( 'knowhow' );
132
+ if ( in_array( jr_mt_current_theme( 'stylesheet' ), $livesearch_themes ) ) {
133
+ return jr_mt_current_theme( 'stylesheet' );
134
+ } else {
135
+ if ( in_array( jr_mt_current_theme( 'template' ), $livesearch_themes ) ) {
136
+ return jr_mt_current_theme( 'template' );
137
+ } else {
138
+ // Go through all the Themes defined in the Plugin's settings
139
+ foreach ( jr_mt_themes_defined() as $theme ) {
140
+ if ( in_array( $theme, $livesearch_themes ) ) {
141
+ return $theme;
142
+ }
143
+ }
144
+ }
145
+ }
146
+ return FALSE;
147
+ }
148
+
149
+ ?>
jonradio-multiple-themes.php ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: jonradio Multiple Themes
4
+ Plugin URI: http://zatzlabs.com/plugins/
5
+ Description: Select different Themes for one or more, or all WordPress Pages, Posts or other non-Admin pages. Or Site Home.
6
+ Version: 4.1
7
+ Author: David Gewirtz
8
+ Author URI: http://zatzlabs.com/plugins/
9
+ License: GPLv2
10
+ */
11
+
12
+ /* Copyright 2013 jonradio (email : info@zatz.com)
13
+
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License as published by
16
+ the Free Software Foundation; either version 2 of the License, or
17
+ (at your option) any later version.
18
+
19
+ This program is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ GNU General Public License for more details.
23
+
24
+ You should have received a copy of the GNU General Public License
25
+ along with this program; if not, write to the Free Software
26
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
+ */
28
+
29
+ global $jr_mt_incompat_plugins;
30
+ $jr_mt_incompat_plugins = array( 'Theme Test Drive', 'BuddyPress' );
31
+
32
+ global $jr_mt_path;
33
+ $jr_mt_path = plugin_dir_path( __FILE__ );
34
+ /**
35
+ * Return Plugin's full directory path with trailing slash
36
+ *
37
+ * Local XAMPP install might return:
38
+ * C:\xampp\htdocs\wpbeta\wp-content\plugins\jonradio-multiple-themes/
39
+ *
40
+ */
41
+ function jr_mt_path() {
42
+ global $jr_mt_path;
43
+ return $jr_mt_path;
44
+ }
45
+
46
+ global $jr_mt_plugin_basename;
47
+ $jr_mt_plugin_basename = plugin_basename( __FILE__ );
48
+ /**
49
+ * Return Plugin's Basename
50
+ *
51
+ * For this plugin, it would be:
52
+ * jonradio-multiple-themes/jonradio-multiple-themes.php
53
+ *
54
+ */
55
+ function jr_mt_plugin_basename() {
56
+ global $jr_mt_plugin_basename;
57
+ return $jr_mt_plugin_basename;
58
+ }
59
+
60
+ if ( !function_exists( 'get_plugin_data' ) ) {
61
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
62
+ }
63
+
64
+ global $jr_mt_plugin_data;
65
+ $jr_mt_plugin_data = get_plugin_data( __FILE__ );
66
+ $jr_mt_plugin_data['slug'] = basename( dirname( __FILE__ ) );
67
+
68
+ global $jr_mt_options_cache;
69
+ $all_options = wp_load_alloptions();
70
+ $jr_mt_options_cache['stylesheet'] = $all_options['stylesheet'];
71
+ $jr_mt_options_cache['template'] = $all_options['template'];
72
+
73
+
74
+ register_activation_hook( __FILE__, 'jr_mt_activate' );
75
+ register_deactivation_hook( __FILE__, 'jr_mt_deactivate' );
76
+
77
+ function jr_mt_activate( $network_wide ) {
78
+ if ( $network_wide ) {
79
+ global $wpdb, $site_id;
80
+ $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = $site_id" );
81
+ foreach ( $blogs as $blog_obj ) {
82
+ if ( switch_to_blog( $blog_obj->blog_id ) ) {
83
+ // We know the Site actually exists
84
+ jr_mt_activate1();
85
+ }
86
+ }
87
+ restore_current_blog();
88
+ } else {
89
+ jr_mt_activate1();
90
+ }
91
+ }
92
+
93
+ function jr_mt_activate1() {
94
+ $settings = array(
95
+ 'all_pages' => '',
96
+ 'all_posts' => '',
97
+ 'site_home' => '',
98
+ 'ids' => array()
99
+ );
100
+ // Nothing happens if Settings already exist
101
+ add_option( 'jr_mt_settings', $settings );
102
+
103
+ global $jr_mt_plugin_data;
104
+ $internal_settings = array(
105
+ 'version' => $jr_mt_plugin_data['Version']
106
+ ); // Only records you version when plugin installed, not current version
107
+ add_option( 'jr_mt_internal_settings', $internal_settings ); // Nothing happens if Settings already exist
108
+ }
109
+
110
+ add_action( 'wpmu_new_blog', 'jr_mt_new_site', 10, 6 );
111
+
112
+ function jr_mt_new_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
113
+ if ( is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
114
+ switch_to_blog( $blog_id );
115
+ jr_mt_activate1();
116
+ restore_current_blog();
117
+ }
118
+ }
119
+
120
+ function jr_mt_deactivate() {
121
+ // Nothing (yet)
122
+ }
123
+
124
+ jr_mt_version_check();
125
+
126
+ function jr_mt_version_check() {
127
+ // Check for Plugin Version update (Deactivate and Activate Hooks not fired)
128
+ $internal_settings = get_option( 'jr_mt_internal_settings' );
129
+ if ( $internal_settings ) { // Just in case Activation has not occurred yet
130
+ global $jr_mt_plugin_data;
131
+ if ( version_compare( $internal_settings['version'], $jr_mt_plugin_data['Version'], '<' ) ) {
132
+ $settings = get_option( 'jr_mt_settings' );
133
+ if ( isset( $settings['ids'] ) ) {
134
+ $ids = $settings['ids'];
135
+ } else {
136
+ $ids = array();
137
+ }
138
+ if ( version_compare( $internal_settings['version'], '2.1', '<' ) ) {
139
+ unset( $settings['all_admin'] );
140
+ // Check for Site Home entry, remove it and set Site Home field
141
+ // And remove all Admin entries (no longer supported)
142
+ if ( isset( $ids[''] ) ) {
143
+ $settings['site_home'] = $ids['']['theme'];
144
+ unset( $ids[''] );
145
+ } else {
146
+ $settings['site_home'] = '';
147
+ }
148
+ foreach ( $ids as $key => $arr ) {
149
+ if ( $arr['type'] == 'admin' ) {
150
+ unset( $ids[$key] );
151
+ }
152
+ }
153
+ }
154
+ if ( version_compare( $internal_settings['version'], '3.0', '<' ) ) {
155
+ foreach ( $ids as $key => $arr ) {
156
+ if ( strcasecmp( 'http', substr( $arr['rel_url'], 0, 4 ) ) == 0 ) {
157
+ unset( $ids[$key] );
158
+ }
159
+ }
160
+ }
161
+ if ( version_compare( $internal_settings['version'], '4.1', '<' ) ) {
162
+ // Replace %hex with real character to support languages like Chinese
163
+ foreach ( $ids as $key => $arr ) {
164
+ $newkey = rawurldecode( $key );
165
+ $newarr = $arr;
166
+ unset( $ids[$key] );
167
+ $newarr['page_url'] = rawurldecode( $newarr['page_url'] );
168
+ $newarr['rel_url'] = rawurldecode( $newarr['rel_url'] );
169
+ $newarr['url'] = rawurldecode( $newarr['url'] );
170
+ $ids[$newkey] = $newarr;
171
+ }
172
+ }
173
+ $settings['ids'] = $ids;
174
+ update_option( 'jr_mt_settings', $settings );
175
+ $internal_settings['version'] = $jr_mt_plugin_data['Version'];
176
+ update_option( 'jr_mt_internal_settings', $internal_settings );
177
+ }
178
+ }
179
+ }
180
+
181
+ require_once( jr_mt_path() . 'includes/functions.php' );
182
+ require_once( jr_mt_path() . 'includes/select-theme.php' );
183
+
184
+ if ( is_admin() ) {
185
+ // Admin panel
186
+ require_once( jr_mt_path() . 'includes/admin.php' );
187
+ }
188
+
189
+ /* Settings structure:
190
+ code - get_option( 'jr_mt_settings' )
191
+ ['all_pages'] => zero length string or folder in Themes directory containing theme to use for All Pages
192
+ ['all_posts'] => zero length string or folder in Themes directory containing theme to use for All Posts
193
+ ['site_home'] => zero length string or folder in Themes directory containing theme to use for Home Page
194
+ ['ids']
195
+ [id] - zero length string or WordPress ID of Page, Post, etc.
196
+ ['type'] => 'page' or 'post' or 'admin' or 'cat' or 'archive' or 'prefix' or other
197
+ ['theme'] => folder in Themes directory containing theme to use
198
+ ['id'] => FALSE or WordPress ID of Page, Post, etc.
199
+ ['page_url'] => relative URL WordPress page, post, admin, etc. or FALSE
200
+ ['rel_url'] => URL relative to WordPress home
201
+ ['url'] => original full URL, from Settings page entry by user
202
+ */
203
+
204
+ /*
205
+ Research Notes:
206
+ The first time one of these Filter Hooks fires, pre_option_stylesheet and pre_option_template, only the following functions can be used to help determine "where" you are in the site:
207
+ - is_admin()
208
+ - is_user_logged_in()
209
+ - get_option("page_on_front") - ID of home page; zero if Reading Settings NOT set to a Static Page of a WordPress Page
210
+ */
211
+
212
+ ?>
readme.txt ADDED
@@ -0,0 +1,284 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === jonradio Multiple Themes ===
2
+ Contributors: dgewirtz
3
+ Donate link: http://zatzlabs.com/plugins/
4
+ Tags: themes, theme, sections, style, template, stylesheet, accessibility
5
+ Requires at least: 3.4
6
+ Tested up to: 3.6
7
+ Stable tag: 4.1
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ Select different Themes for one or more, or all WordPress Pages, Posts or other non-Admin pages. Or Site Home.
12
+
13
+ == Description ==
14
+
15
+ Allows the Administrator to specify which Theme will be used on specific Pages, Posts, other non-Admin pages (such as Category or Archive pages) or Site Home; a Prefix feature allows a Theme to be selected based on the initial characters of its URL ("Prefix URL"). Also allows a Theme to be specified for All Pages or All Posts. In turn, even when a Theme is specified for All Pages or All Posts, a different Theme can still be specified for specific Pages or Posts.
16
+
17
+ Think what you could do if you could easily use more than one Theme on your WordPress web site or blog:
18
+
19
+ * Divide your site into Sections, each with its own unique look
20
+ * Style individual Pages, Posts, or other elements (Site Home, Category main page, Archive main page) with a different Theme
21
+ * Select a unique Theme for all Pages, Posts, Attachments, Category pages or Archive pages
22
+ * Make slight variations to a Theme, using Child Themes, for one or more Pages, Posts or other elements (Site Home, Category main page, Archive main page)
23
+ * Supports Multiple Stylesheets for Accessibility and other purposes (create one Child Theme for each Stylesheet)
24
+ * Test a new Theme on one or more Pages or Posts
25
+ * Convert to a new Theme a Page or Post at a time
26
+ * Host multiple mini-web sites on your WordPress site, each with a different Theme
27
+ * When a larger version of an image attachment is displayed, for example, when clicking on a gallery image thumbnail, use a different theme to display it, for one or all images attached to a Page or Post
28
+
29
+ **Use with other Plugins**: **BuddyPress** and Theme Test Drive plugins must both be Deactivated when jonradio Multiple Themes is Activated
30
+
31
+ **Changing Theme Options (Widgets, Sidebars, Menus, Templates, Background, Header, etc.)?**: See the FAQ (Frequently-Asked Questions) tab for important information on changing Options on Themes other than the Current Theme.
32
+
33
+ To select all Pages, Posts, Archives, Categories, etc. that begin with the same partial URL, a "Prefix URL" can be specified by selecting the Prefix checkbox when creating an entry on the Settings page for the jonradio Multiple Themes plugin. Restriction: the Prefix URL cannot contain all or part of a Query, which is the portion of a URL that begins with a question mark ("?"). Although the Prefix cannot contain a Query, URLs containing a Query will be matched by the Prefix.
34
+
35
+ If a Theme is not specified for a Page, Post, Site Home or other WordPress-displayed web page, such as Category or Archive display, the **Current Theme** specified in **Appearance-Themes** on the Admin panels will be used.
36
+
37
+ When selecting a Theme for Site Home or all or specific Pages, Posts or other non-Admin pages, the Theme must be shown in the list of Available Themes on the Appearance-Themes Admin panel. If necessary, install the Theme. In a WordPress Network (AKA Multisite), Themes must be **Network Enabled** before they will appear as Available Themes on individual sites' Appearance-Themes panel.
38
+
39
+ I hesitate to use the term **Theme Switcher** to describe this plugin, because the term has so many meanings. The jonradio Multiple Themes plugin does **not** alter the standard WordPress options that define what Theme is used on your WordPress site. Instead, it dynamically (and selectively) overrides that choice. Technical details aside, what this means is that deactivating or deleting the jonradio Multiple Themes plugin will instantly revert to the WordPress Current Theme that you have defined through the standard WordPress Appearance-Themes Admin panel.
40
+
41
+ == Installation ==
42
+
43
+ This section describes how to install the jonradio Multiple Themes plugin and get it working.
44
+
45
+ 1. Use "Add Plugin" within the WordPress Admin panel to download and install this jonradio Multiple Themes plugin from the WordPress.org plugin repository (preferred method). Or download and unzip this plugin, then upload the `/jonradio-multiple-themes/` directory to your WordPress web site's `/wp-content/plugins/` directory.
46
+ 1. Activate the jonradio Multiple Themes plugin through the 'Plugins' menu in WordPress. If you have a WordPress Network ("Multisite"), you can either Network Activate this plugin, or Activate it individually on the sites where you wish to use it. Activating on individual sites within a Network avoids some of the confusion created by WordPress' hiding of Network Activated plugins on the Plugin menu of individual sites.
47
+ 1. Be sure that all Themes you plan to use have been installed and are listed under Available Themes on the WordPress Appearance-Themes Admin panel. In a WordPress Network (AKA Multisite), Themes must be **Network Enabled** before they will appear as Available Themes on individual sites' Appearance-Themes panel.
48
+ 1. Select Themes to be used on the Plugin's "Multiple Themes plugin" page in the WordPress Admin panels, which is found in both the **Appearance** and **Settings** sections. You can also get to this page by clicking on the **Settings** link for this plugin on the **Installed Plugins** page.
49
+ 1. If you need to change Theme Options (Widgets, Sidebars, Menus, Templates, Background, Header, etc.) for any Theme other than the Current Theme, see the FAQ (Frequently-Asked Questions) tab for important information.
50
+
51
+ == Frequently Asked Questions ==
52
+
53
+ = Will this plugin work with Paid Themes? =
54
+
55
+ Yes, in most cases. But we have only tested the few Paid Themes whose authors have provided us with permission to use, without charge, their themes for test purposes. Elegant, for example, allows us to accept copies of its Themes provided by its customers who require assistance with the jonradio Multiple Themes plugin. On the other hand, some other Paid Theme authors have simply ignored our requests, despite our stated willingness to sign a non-disclosure agreement.
56
+
57
+ We do encourage you to contact us if you run into problems when using the jonradio Multiple Themes plugin with a Paid Theme, as the problem may not be unique to the Paid Theme.
58
+
59
+ To state the obvious, the cost of purchasing a license for all Paid Themes for testing purposes is prohibitive for an Open Source plugin such as this one.
60
+
61
+ = How do I change the Theme Options (Widgets, Sidebars, Menus, Background, Header, etc.) used for each Theme? =
62
+
63
+ **NOTE**: See the next FAQ for information on Templates.
64
+
65
+ For the Current Theme, nothing changes when using the jonradio Multiple Themes plugin. Options for the Current Theme, including Widgets, Sidebars, Menus, Background, Header and other Customizations supported by the Theme, can be modified in the Admin panel using the Appearance menu items on the left sidebar and the Customize link displayed beside the Current Theme on the Manage Themes tab of Appearance-Themes.
66
+
67
+ It is more difficult to modify Options for Active Themes that are *not* the Current Theme. We hope to build this functionality into the jonradio Multiple Themes plugin in a future Version, but it is not clear just how practical that is, so the best that can be said is: Maybe.
68
+
69
+ For now, there are two approaches. Except for Widgets, the first approach is the most likely to give you success. Menus, on the other hand, really work well with the first approach, and are severely restricted with the second method.
70
+
71
+ **WARNING**: So far, we have not received any reports of, nor have we tested, using both Method #1 and #2 on the same WordPress site. Use Caution if you plan to do so, as we cannot predict the results.
72
+
73
+ **Method #1:**
74
+
75
+ Set the Theme Options with Live Preview.
76
+
77
+ Note: Widgets cannot be placed using this Method.
78
+
79
+ 1. Go to Appearance-Themes-Live Preview in the Admin panels.
80
+ 1. Use the right sidebar to modify the Theme Options. Note that "Navigation" will not appear until a Custom Menu has been defined in Appearance-Menus. Navigation-Primary Navigation is where you would set the custom menu to be used for the Theme you are currently previewing.
81
+ 1. Click the Save & Activate button.
82
+ 1. Go immediately to Appearance-Themes to reactivate the Current Theme.
83
+
84
+ **Method #2:**
85
+
86
+ Use the Theme Test Drive plugin.
87
+
88
+ Note: this approach only allows Menus to be set for one Theme. Using this method to assign one or more menus to a Theme will unassign menus for all other Themes.
89
+
90
+ The jonradio Multiple Themes plugin (i.e. - this plugin) must be Deactivated, and the Theme Test Drive plugin installed and activated, so that each Theme can be selected with the Theme Test Drive plugin, allowing the Theme's Options to be set "as if" it were the Current Theme.
91
+
92
+ 1. Deactivate jonradio Multiple Themes
93
+ 1. Install the Theme Test Drive plugin found at http://wordpress.org/extend/plugins/theme-test-drive/
94
+ 1. Activate the Theme Test Drive plugin
95
+ 1. Go to Appearance-Theme Test Drive
96
+ 1. In the Usage section, select an alternate Theme you will be using with jonradio Multiple Themes
97
+ 1. Push the Enable Theme Drive button at the bottom
98
+ 1. Go to the WordPress Admin panel's Appearance menu (left sidebar)
99
+ 1. Make your changes to the Theme Options, including Widgets, Sidebars, Menus (see note above about Menus), Background, Header and other Customizations for this alternate Theme (which will appear as if it were the Current Theme)
100
+ 1. If you have more than one alternate Theme with Options you wish to change, repeat Steps 4-8 for each alternate Theme
101
+ 1. Deactivate the Theme Test Drive plugin
102
+ 1. Activate jonradio Multiple Themes
103
+ 1. Changes to the Options for the Current Theme can now be made normally, just as you would without either plugin
104
+ 1. Both the alternate and Current Themes should now display all Theme options properly when selected through the jonradio Multiple Themes plugin
105
+
106
+ = How do I change the Template for a specific Page or Post? =
107
+
108
+ For the Current Theme, nothing changes when using the jonradio Multiple Themes plugin. Select an alternate Template from the drop-down list in the Template field of the Page Attributes section of the Add New Page, Edit Page, Add New Post or Edit Post page of the Admin panels. Or the Template field in Quick Edit.
109
+
110
+ It is more difficult to change Templates for Pages or Posts defined with the jonradio Multiple Themes plugin to use Active Themes that are *not* the Current Theme. We hope to build this functionality into the jonradio Multiple Themes plugin in a future Version.
111
+
112
+ Use the Theme Test Drive plugin. The jonradio Multiple Themes plugin (i.e. - this plugin) must be Deactivated, and the Theme Test Drive plugin installed and activated, so that each Theme can be selected with the Theme Test Drive plugin, allowing the Theme's Template to be set for each Page or Post using that Theme "as if" it were the Current Theme.
113
+
114
+ 1. Deactivate jonradio Multiple Themes
115
+ 1. Install the Theme Test Drive plugin found at http://wordpress.org/extend/plugins/theme-test-drive/
116
+ 1. Activate the Theme Test Drive plugin
117
+ 1. Go to Appearance-Theme Test Drive
118
+ 1. In the Usage section, select an alternate Theme you will be using with jonradio Multiple Themes
119
+ 1. Push the Enable Theme Drive button at the bottom
120
+ 1. Go to the WordPress Admin panel's Page or Post menu (left sidebar)
121
+ 1. Make your changes to the Template field of each Page and/or Post that has been selected for this alternate Theme AND requires a non-default Template
122
+ 1. If you have more than one alternate Theme with Templates you wish to change, repeat Steps 4-8 for each alternate Theme
123
+ 1. Deactivate the Theme Test Drive plugin
124
+ 1. Activate jonradio Multiple Themes
125
+ 1. Changes to the Templates for Pages and Posts using the Current Theme can now be made normally, just as you would without either plugin
126
+ 1. Both the alternate and Current Themes should now display all Templates properly when selected through the jonradio Multiple Themes plugin
127
+
128
+ = How do I select a Theme for a Category of Posts? =
129
+
130
+ That functionality, to directly specify a Theme for a Category on the Settings page, is being investigated for a future version of the jonradio Multiple Themes plugin. But there is already a solution based on Permalinks:
131
+
132
+ 1. In the WordPress Admin panels, go to Settings-Permalinks
133
+ 1. Specify a Permalinks structure that begins with /%category%/
134
+ 1. Push the Save Changes button
135
+ 1. Go to Settings-Multiple Themes plugin
136
+ 1. In the Section "For An Individual Page, Post or other non-Admin page", select the Theme for the Category of Posts
137
+ 1. Enter the URL of the Categories page, e.g. - http://domain.com/news/
138
+ 1. Click the checkbox "Select here if URL is a Prefix"
139
+ 1. Push the Save Changes button
140
+
141
+ = How do I Edit a Theme? =
142
+
143
+ WordPress includes a built-in Theme Editor. Select Editor in the Admin panel's Appearance menu items on the left sidebar.
144
+
145
+ By default, the style.css file of the Current Theme is displayed. You can edit other Themes by selecting them in the "Select theme to edit" field and clicking the Select button.
146
+
147
+ Alternatively, you can edit any Theme on your own computer. If your computer runs Windows, NotePad++ and FileZilla run very well together, using FileZilla's View/Edit feature to provide a Theme Editor with syntax highlighting and other advanced features.
148
+
149
+ If one or more of the Active Themes have their own Theme Editor or other type of Theme Options panels, such as Elegant's epanel, please read the next FAQ.
150
+
151
+ = How do I use Elegant's epanel? =
152
+
153
+ Nothing changes for the Current Theme. epanel can be accessed just as it would be without the jonradio Multiple Themes plugin, simply by selecting the WordPress Admin panel's Appearance submenu item titled Theme Options preceded by the name of your Elegant Theme.
154
+
155
+ To make changes to other Active Themes that you will be specifying with the jonradio Multiple Themes plugin:
156
+
157
+ 1. Deactivate jonradio Multiple Themes
158
+ 1. Install the Theme Test Drive plugin found at http://wordpress.org/extend/plugins/theme-test-drive/
159
+ 1. Activate the Theme Test Drive plugin
160
+ 1. Go to Appearance-Theme Test Drive
161
+ 1. In the Usage section, select an alternate Theme you will be using with jonradio Multiple Themes
162
+ 1. Push the Enable Theme Drive button at the bottom
163
+ 1. Click on the Appearance menu item on the left sidebar of the WordPress Admin panel to refresh the submenu
164
+ 1. Click on the submenu item titled with your Elegant theme's name followed by "Theme Options"
165
+ 1. Elegant's epanel will now appear
166
+ 1. Make all the changes for this Theme, being sure to push the Save button
167
+ 1. If you have more than one alternate Theme with Options you wish to change, repeat Steps 4-10 for each alternate Theme
168
+ 1. Deactivate the Theme Test Drive plugin
169
+ 1. Activate jonradio Multiple Themes
170
+ 1. Changes to the Options for the Current Theme can now be made normally, just as you would without either plugin
171
+ 1. Both the alternate and Current Themes should now display all Theme options properly when selected through the jonradio Multiple Themes plugin
172
+
173
+ Thanks to Elegant for allowing us to test copies of any of their Themes provided by their customers.
174
+
175
+ = What happens when I change Permalinks? =
176
+
177
+ For entries you have created for individual Pages and Posts with the jonradio Multiple Themes plugin, you can subsequently change your Permalink structure or you can change the Permalink of a Page or Post, without having to change the plugin's entry. However, for other pages, such as Categories or Archives, you will have to delete your old entries and create new ones with the jonradio Multiple Themes plugin.
178
+
179
+ = I added a new entry but why doesn't it appear in the list of entries? =
180
+
181
+ If you add an entry that already exists, it merely replaces the previous entry.
182
+
183
+ = How can I change the Theme for an entry? =
184
+
185
+ Simply add the entry again, with the new Theme. It will replace the previous entry.
186
+
187
+ == Screenshots ==
188
+
189
+ 1. Plugin's Admin Page when first installed
190
+ 2. Plugin's Admin Page, adding entries
191
+
192
+ == Changelog ==
193
+
194
+ = 4.1 =
195
+ * Support for non-alphanumeric characters in URLs, e.g. - languages using characters not in the English alphabet
196
+ * Support for Live Search feature of KnowHow Theme
197
+ * Display errors, not settings, on plugin's Admin page for activated BuddyPress or Theme Test Drive plugins, or old versions of WordPress
198
+ * Add error checking/messages and diagnostic information to plugin's Admin page
199
+
200
+ = 4.0.2 =
201
+ * Prevent Warning and Notice by initializing global $wp
202
+
203
+ = 4.0.1 =
204
+ * Prevent Fatal Error by initializing global $wp_rewrite
205
+
206
+ = 4 =
207
+ * Discovered url_to_postid() function, to address situations where Slug differed from Permalink, such as Posts with Year/Month folders
208
+
209
+ = 3.3.1 =
210
+ * Fix White Screen of Death on a Page selected by plugin
211
+
212
+ = 3.3 =
213
+ * Support Child Themes and any other situation where stylesheet and template names are not the same
214
+
215
+ = 3.2 =
216
+ * Correct Problem with P2 Theme, and its logged on verification at wp-admin/admin-ajax.php?p2ajax=true&action=logged_in_out&_loggedin={nonce}
217
+ * Add "Settings Saved" message to Admin page
218
+ * Tested with WordPress Version 3.5 beta
219
+
220
+ = 3.1 =
221
+ * Add Support for Prefixes, where all URLs beginning with the specified characters ("Prefix") can be assigned to a specified Theme
222
+
223
+ = 3.0 =
224
+ * Add Support for Categories and Archives when no Permalinks exist (support already existed Categories and Archives with Permalinks)
225
+ * Resolve several minor bugs
226
+
227
+ = 2.9 =
228
+ * Rewrite much of the Settings page and Plugin Directory documentation
229
+ * Add Support for IIS which returns incorrect values in $_SERVER['REQUEST_URI']
230
+ * Make it easier to select the Theme for the Site Home by providing a new Settings field
231
+ * Remove ability to set Theme for Admin pages since no known Theme provides Admin templates, and because the previous implementation sometimes displayed the incorrect Current Theme in Admin; this feature may be re-added in a future release, and could even be used to change Settings of Themes that are not currently the Current Theme
232
+ * Add version upgrade detection to add, remove and update Settings fields
233
+ * Move Settings link on Plugins page from beginning to end of links
234
+
235
+ = 2.0 =
236
+ * Address pecularities of wp_make_link_relative() related to root-based WordPress sites using Permalinks
237
+
238
+ = 1.1 =
239
+ * Fix foreach failing on some systems, based on PHP warning level
240
+
241
+ = 1.0 =
242
+ * Make plugin conform to WordPress plugin repository standards.
243
+ * Beta testing completed.
244
+
245
+ == Upgrade Notice ==
246
+
247
+ = 4.1 =
248
+ Support non-English alphabet in URLs and Live Search feature in KnowHow Theme
249
+
250
+ = 4.0.2 =
251
+ Fix "Warning: in_array() expects parameter 2 to be array, null given in domain.com/wp-includes/rewrite.php on line 364"
252
+
253
+ = 4.0.1 =
254
+ Fix "Fatal error: Call to a member function wp_rewrite_rules() on a non-object in domain.com/wp-includes/rewrite.php on line 294"
255
+
256
+ = 4 =
257
+ Fix Posts not working in some Permalink setups, most notably Year/Month
258
+
259
+ = 3.3.1 =
260
+ Fix White Screen of Death on a Page, Post or other element selected by plugin
261
+
262
+ = 3.3 =
263
+ Remove Restriction that Stylesheet Name must match Template Name, which it does not with Child Themes
264
+
265
+ = 3.2 =
266
+ Add Support for P2 Theme and provide "Settings Saved" message
267
+
268
+ = 3.1 =
269
+ Allow Prefix URLs to be used to specify where a Theme will be displayed
270
+
271
+ = 3.0 =
272
+ Improve support for Categories and Archives, and eliminate all known bugs.
273
+
274
+ = 2.9 =
275
+ Improve Settings fields, correct display of wrong Current Theme in Appearance-Themes Admin panel, and add IIS Support.
276
+
277
+ = 2.0 =
278
+ Selecting Individual Pages and Posts on a WordPress site installed in the root and using Permalinks now works correctly.
279
+
280
+ = 1.1 =
281
+ Eliminate possibility of foreach error message if PHP warning level is set at a high level
282
+
283
+ = 1.0 =
284
+ Beta version 0.9 had not been tested when installed from the WordPress Plugin Repository
uninstall.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Ensure call comes from WordPress, not a hacker.
3
+ if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
4
+ exit ();
5
+
6
+ /* Remove any tables, options, and such created by this Plugin */
7
+ if ( function_exists('is_multisite') && is_multisite() ) {
8
+ global $wpdb, $site_id;
9
+ $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = $site_id" );
10
+ foreach ($blogs as $blog_obj) {
11
+ delete_blog_option( $blog_obj->blog_id, 'jr_mt_settings' );
12
+ delete_blog_option( $blog_obj->blog_id, 'jr_mt_internal_settings' );
13
+ }
14
+ } else {
15
+ delete_option( 'jr_mt_settings' );
16
+ delete_option( 'jr_mt_internal_settings' );
17
+ }
18
+ ?>