Multiple Themes - Version 4.0.2

Version Description

  • Prevent Warning and Notice by initializing global $wp
Download this release

Release Info

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

Version 4.0.2

includes/admin.php ADDED
@@ -0,0 +1,385 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Admin Page
3
+
4
+ add_action( 'admin_menu', 'jr_mt_admin_hook' );
5
+
6
+ /**
7
+ * Add Admin Menu item for plugin
8
+ *
9
+ * Plugin needs its own Page in the Settings section of the Admin menu.
10
+ *
11
+ */
12
+ function jr_mt_admin_hook() {
13
+ // Add Settings Page for this Plugin
14
+ add_theme_page( 'jonradio Multiple Themes', 'Multiple Themes plugin', 'manage_options', 'jr_mt_settings', 'jr_mt_settings_page' );
15
+ add_options_page( 'jonradio Multiple Themes', 'Multiple Themes plugin', 'manage_options', 'jr_mt_settings', 'jr_mt_settings_page' );
16
+ }
17
+
18
+ /**
19
+ * Settings page for plugin
20
+ *
21
+ * Display and Process Settings page for this plugin.
22
+ *
23
+ */
24
+ function jr_mt_settings_page() {
25
+ echo '<div class="wrap">';
26
+ screen_icon( 'plugins' );
27
+ echo '<h2>jonradio Multiple Themes</h2>';
28
+
29
+ // Required because it is only called automatically for Admin Pages in the Settings section
30
+ settings_errors( 'jr_mt_settings' );
31
+
32
+ $theme = wp_get_theme()->Name;
33
+ global $jr_mt_options_cache;
34
+ ?>
35
+ <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.
36
+ You can choose from any of the <b>Available Themes</b> listed on the Appearance-Themes Admin panel for:
37
+ <ul>
38
+ <li> &raquo; All Pages</li>
39
+ <li> &raquo; All Posts</li>
40
+ <li> &raquo; The Site Home</li>
41
+ <li> &raquo; A Specific Page</li>
42
+ <li> &raquo; A Specific Post</li>
43
+ <li> &raquo; Any other non-Admin page that has its own Permalink; for example, a specific Archive or Category page</li>
44
+ </ul>
45
+ <?php
46
+ if ( function_exists('is_multisite') && is_multisite() ) {
47
+ 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.";
48
+ }
49
+ echo '</p>';
50
+ echo '<p>';
51
+ 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.";
52
+ echo '</p>';
53
+ echo '<form action="options.php" method="POST">';
54
+
55
+ // Plugin Settings are displayed and entered here:
56
+ settings_fields( 'jr_mt_settings' );
57
+ do_settings_sections( 'jr_mt_settings_page' );
58
+ echo '<p><input name="save" type="submit" value="Save Changes" class="button-primary" /></p></form>';
59
+ }
60
+
61
+ add_action( 'admin_init', 'jr_mt_admin_init' );
62
+
63
+ /**
64
+ * Register and define the settings
65
+ *
66
+ * Everything to be stored and/or can be set by the user
67
+ *
68
+ */
69
+ function jr_mt_admin_init() {
70
+ register_setting( 'jr_mt_settings', 'jr_mt_settings', 'jr_mt_validate_settings' );
71
+ add_settings_section( 'jr_mt_all_settings_section',
72
+ 'For All Pages, All Posts and/or Site Home',
73
+ 'jr_mt_all_settings_expl',
74
+ 'jr_mt_settings_page'
75
+ );
76
+ $suffix = array(
77
+ 'Pages' => '<br />(Pages created with Add Page)',
78
+ 'Posts' => ''
79
+ );
80
+ foreach ( array( 'Pages', 'Posts' ) as $thing ) {
81
+ 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',
82
+ array( 'thing' => $thing ) );
83
+ }
84
+ add_settings_field( 'site_home',
85
+ 'Select Theme for Site Home<br />(' . get_home_url() . ')',
86
+ 'jr_mt_echo_site_home',
87
+ 'jr_mt_settings_page',
88
+ 'jr_mt_all_settings_section'
89
+ );
90
+ $settings = get_option( 'jr_mt_settings' );
91
+ $ids = $settings['ids'];
92
+ if ( !empty( $ids) ) {
93
+ add_settings_section( 'jr_mt_delete_settings_section',
94
+ 'To Display or Delete Theme Selections for Individual Pages or Posts',
95
+ 'jr_mt_delete_settings_expl',
96
+ 'jr_mt_settings_page'
97
+ );
98
+ add_settings_field( 'del_entry', 'Entries:', 'jr_mt_echo_delete_entry', 'jr_mt_settings_page', 'jr_mt_delete_settings_section' );
99
+ }
100
+ add_settings_section( 'jr_mt_single_settings_section',
101
+ 'For An Individual Page, Post or other non-Admin page',
102
+ 'jr_mt_single_settings_expl',
103
+ 'jr_mt_settings_page'
104
+ );
105
+ add_settings_field( 'add_theme', 'Theme', 'jr_mt_echo_add_theme', 'jr_mt_settings_page', 'jr_mt_single_settings_section' );
106
+ 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' );
107
+ 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' );
108
+ }
109
+
110
+ /**
111
+ * Section text for Section1
112
+ *
113
+ * Display an explanation of this Section
114
+ *
115
+ */
116
+ function jr_mt_all_settings_expl() {
117
+ ?>
118
+ <p>
119
+ In this section, you can select a different Theme for All Pages, All Posts and/or Site Home.
120
+ To remove a previously selected Theme, select the blank entry from the drop-down list.
121
+ </p>
122
+ <p>
123
+ 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
124
+ any other non-Admin pages that have their own Permalink; for example, specific Archive or Category pages.
125
+ </p>
126
+ <?php
127
+ }
128
+
129
+ function jr_mt_echo_all_things( $thing ) {
130
+ $settings = get_option( 'jr_mt_settings' );
131
+ $field = 'all_' . strtolower( $thing['thing'] );
132
+ jr_mt_themes_field( $field, $settings[$field], 'jr_mt_settings', TRUE );
133
+ }
134
+
135
+ function jr_mt_echo_site_home() {
136
+ $settings = get_option( 'jr_mt_settings' );
137
+ jr_mt_themes_field( 'site_home', $settings['site_home'], 'jr_mt_settings', FALSE );
138
+ }
139
+
140
+ /**
141
+ * Section text for Section2
142
+ *
143
+ * Display an explanation of this Section
144
+ *
145
+ */
146
+ function jr_mt_delete_settings_expl() {
147
+ ?>
148
+ <p>
149
+ In this section, all entries are displayed for Themes selected for individual Pages, Posts
150
+ and any other non-Admin pages that have their own Permalink; for example, specific Archive or Category pages.
151
+ </p>
152
+ <p>
153
+ You can delete any of these entries by filling in the check box beside each one.
154
+ To change the Theme for an entry, add the same entry with a different Theme in the section below this one.</p>
155
+ <?php
156
+ }
157
+
158
+ function jr_mt_echo_delete_entry() {
159
+ $entry_num = 0;
160
+ $settings = get_option( 'jr_mt_settings' );
161
+ foreach ( $settings['ids'] as $path_id => $opt_array ) {
162
+ ++$entry_num;
163
+ echo "Delete <input type='checkbox' id='del_entry' name='jr_mt_settings[del_entry][]' value='$path_id' /> &nbsp; Theme="
164
+ . wp_get_theme( $opt_array['theme'] )->Name . '; ';
165
+ if ( $path_id == '' ) {
166
+ echo 'Site=<a href="' . get_home_url() . '" target="_blank">Home</a>';
167
+ } else {
168
+ if ( $opt_array['type'] == 'prefix' ) {
169
+ echo 'Prefix=<a href="' . get_home_url() . "/$path_id" . '" target="_blank">' . "$path_id</a>";
170
+ } else {
171
+ if ( $opt_array['type'] == 'cat' ) {
172
+ echo 'Category=<a href="' . get_home_url() . '/?cat=' . $opt_array['id'] . '" target="_blank">' . get_cat_name( $opt_array['id'] ) . '</a>';
173
+ } else {
174
+ if ( $opt_array['type'] == 'archive' ) {
175
+ echo 'Archive=<a href="' . get_home_url() . '/?m=' . $opt_array['id'] . '" target="_blank">' . $opt_array['id'] . '</a>';
176
+ } else {
177
+ $p_array = get_posts( array( 'post_type' => 'any', 'include' => array( $path_id ) ) );
178
+ if ( empty( $p_array ) ) {
179
+ if ( $opt_array['type'] == 'admin' ) {
180
+ echo 'Admin=<a href="' . get_home_url() . '/' . $opt_array['rel_url'] . '" target="_blank">' . "$path_id</a>";
181
+ } else {
182
+ echo 'Path=<a href="' . get_home_url() . "/$path_id" . '" target="_blank">' . "$path_id</a>";
183
+ }
184
+ } else {
185
+ echo ucfirst( $p_array[0]->post_type ) . '=<a href="' . get_permalink( $path_id ) . '" target="_blank">' . $p_array[0]->post_title . '</a>';
186
+ }
187
+ }
188
+ }
189
+ }
190
+ }
191
+ echo '<br />';
192
+ }
193
+ }
194
+
195
+ /**
196
+ * Section text for Section3
197
+ *
198
+ * Display an explanation of this Section
199
+ *
200
+ */
201
+ function jr_mt_single_settings_expl() {
202
+ ?>
203
+ <p>
204
+ Select a Theme for an individual Page, Post or
205
+ any other non-Admin pages that has its own Permalink; for example, a specific Archive or Category page.
206
+ <p>
207
+ </p>
208
+ Then cut and paste the URL of the desired Page, Post or other non-Admin page.
209
+ And click the <b>Save Changes</b> button to add the entry.
210
+ </p>
211
+ <?php
212
+ }
213
+
214
+ function jr_mt_echo_add_theme() {
215
+ jr_mt_themes_field( 'add_theme', '', 'jr_mt_settings', FALSE );
216
+ }
217
+
218
+ function jr_mt_echo_add_path_id() {
219
+ ?>
220
+ <input id="add_path_id" name="jr_mt_settings[add_path_id]" type="text" size="100" maxlength="256" value="" />
221
+ <br />
222
+ (cut and paste URL here of Page, Post, Prefix or other)
223
+ <br />
224
+ URL must begin with
225
+ <?php
226
+ echo trim( get_home_url(), '\ /' ) . '/';
227
+ }
228
+
229
+ function jr_mt_echo_add_is_prefix() {
230
+ ?>
231
+ <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
232
+ <?php
233
+ }
234
+
235
+ function jr_mt_validate_settings( $input ) {
236
+ $valid = array();
237
+ foreach ( array( 'all_pages', 'all_posts', 'site_home' ) as $thing ) {
238
+ $valid[$thing] = $input[$thing];
239
+ }
240
+
241
+ $settings = get_option( 'jr_mt_settings' );
242
+ $ids = $settings['ids'];
243
+ if ( isset ( $input['del_entry'] ) ) {
244
+ foreach ( $input['del_entry'] as $del_entry ) {
245
+ unset( $ids[$del_entry] );
246
+ }
247
+ }
248
+
249
+ $url = trim( $input['add_path_id'] );
250
+ if ( ( empty( $input['add_theme'] ) && !empty( $url ) ) || ( !empty( $input['add_theme'] ) && empty( $url ) ) ) {
251
+ add_settings_error(
252
+ 'jr_mt_settings',
253
+ 'jr_mt_emptyerror',
254
+ 'Both URL and Theme must be specified to add an Individual entry',
255
+ 'error'
256
+ );
257
+ } else {
258
+ if ( !empty( $url ) ) {
259
+ $validate_url = jr_mt_site_url( $url );
260
+ if ( $validate_url === TRUE ) {
261
+ extract( jr_mt_url_to_id( $url ) );
262
+ if ( isset ( $input['add_is_prefix'] ) && ( $input['add_is_prefix'] == "true" ) ) {
263
+ if ( parse_url( $url, PHP_URL_QUERY ) === NULL ) {
264
+ $ids[$rel_url] = array(
265
+ 'theme' => $input['add_theme'],
266
+ 'type' => 'prefix',
267
+ 'id' => $id,
268
+ 'page_url' => $page_url,
269
+ 'rel_url' => $rel_url,
270
+ 'url' => $url
271
+ );
272
+ } else {
273
+ add_settings_error(
274
+ 'jr_mt_settings',
275
+ 'jr_mt_queryerror',
276
+ '?key=val&key=val Queries are not supported in a URL Prefix',
277
+ 'error'
278
+ );
279
+
280
+ }
281
+ } else {
282
+ if ( $home ) {
283
+ add_settings_error(
284
+ 'jr_mt_settings',
285
+ 'jr_mt_homeerror',
286
+ 'Please use "Select Theme for Site Home" field instead of specifying Site Home URL as an individual entry.',
287
+ 'error'
288
+ );
289
+ } else {
290
+ if ( $type == 'admin' ) {
291
+ add_settings_error(
292
+ 'jr_mt_settings',
293
+ 'jr_mt_adminerror',
294
+ 'Admin Page URLs are not allowed because no known Themes alter the appearance of Admin pages.',
295
+ 'error'
296
+ );
297
+ } else {
298
+ if ( $id === FALSE ) {
299
+ $key = $page_url;
300
+ } else {
301
+ $key = $id;
302
+ }
303
+ $ids[$key] = array(
304
+ 'theme' => $input['add_theme'],
305
+ 'type' => $type,
306
+ 'id' => $id,
307
+ 'page_url' => $page_url,
308
+ 'rel_url' => $rel_url,
309
+ 'url' => $url
310
+ );
311
+ }
312
+ }
313
+ }
314
+ } else {
315
+ add_settings_error(
316
+ 'jr_mt_settings',
317
+ 'jr_mt_urlerror',
318
+ "Invalid URL specified for Individual page/post: '$url'. $validate_url",
319
+ 'error'
320
+ );
321
+ }
322
+ }
323
+ }
324
+ $errors = get_settings_errors();
325
+ if ( empty( $errors ) ) {
326
+ add_settings_error(
327
+ 'jr_mt_settings',
328
+ 'jr_mt_saved',
329
+ 'Settings Saved',
330
+ 'updated'
331
+ );
332
+ }
333
+ $valid['ids'] = $ids;
334
+ return $valid;
335
+ }
336
+
337
+ // Add Link to the plugin's entry on the Admin "Plugins" Page, for easy access
338
+ global $jr_mt_plugin_basename;
339
+ add_filter( "plugin_action_links_$jr_mt_plugin_basename", 'jr_mt_plugin_action_links', 10, 1 );
340
+
341
+ /**
342
+ * Creates Settings entry right on the Plugins Page entry.
343
+ *
344
+ * Helps the user understand where to go immediately upon Activation of the Plugin
345
+ * by creating entries on the Plugins page, right beside Deactivate and Edit.
346
+ *
347
+ * @param array $links Existing links for our Plugin, supplied by WordPress
348
+ * @param string $file Name of Plugin currently being processed
349
+ * @return string $links Updated set of links for our Plugin
350
+ */
351
+ function jr_mt_plugin_action_links( $links ) {
352
+ // The "page=" query string value must be equal to the slug
353
+ // of the Settings admin page.
354
+ array_push( $links, '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=jr_mt_settings' . '">Settings</a>' );
355
+ return $links;
356
+ }
357
+
358
+ // $theme_name is the name of the Theme's folder within the Theme directory
359
+ function jr_mt_themes_field( $field_name, $theme_name, $setting, $excl_current_theme ) {
360
+ echo "<select id='$field_name' name='$setting" . "[$field_name]' size='1'>";
361
+ if ( empty( $theme_name ) ) {
362
+ $selected = 'selected="selected"';
363
+ } else {
364
+ $selected = '';
365
+ }
366
+ echo "<option value='' $selected></option>";
367
+ foreach ( wp_get_themes() as $folder => $theme_obj ) {
368
+ if ( $excl_current_theme ) {
369
+ if ( ( jr_mt_current_theme( 'stylesheet' ) == $theme_obj['stylesheet'] ) && ( jr_mt_current_theme( 'template' ) == $theme_obj['template'] ) ) {
370
+ // Skip the Current Theme
371
+ continue;
372
+ }
373
+ }
374
+ if ( $theme_name == $folder ) {
375
+ $selected = 'selected="selected"';
376
+ } else {
377
+ $selected = '';
378
+ }
379
+ $name = $theme_obj->Name;
380
+ echo "<option value='$folder' $selected>$name</option>";
381
+ }
382
+ echo '</select>' . PHP_EOL;
383
+ }
384
+
385
+ ?>
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,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ return NULL;
141
+ }
142
+ }
143
+ }
144
+ }
145
+ }
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Is the URL on the current WordPress web site?
151
+ *
152
+ * Checks if URL begins with Site Home URL.
153
+ *
154
+ * @param string $url URL to be checked to be sure it is "on" the current WordPress web site
155
+ * @return var bool TRUE if URL on current WordPress web site; string error message otherwise
156
+ */
157
+ function jr_mt_site_url( $url ) {
158
+ $check_url = trim( $url );
159
+ if ( strcasecmp( 'http', substr( $check_url, 0, 4 ) ) != 0 ) {
160
+ return 'URL does not begin with http://';
161
+ }
162
+ $site_home = get_home_url();
163
+ if ( strcasecmp( $site_home, substr( $check_url, 0, strlen( $site_home ) ) ) != 0 ) {
164
+ return "URL specified is not part of current WordPress web site. URL must begin with '$site_home'";
165
+ }
166
+ return TRUE;
167
+ }
168
+ ?>
includes/select-theme.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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( 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] ) );
67
+ $settings = get_option( 'jr_mt_settings' );
68
+ if ( $home ) {
69
+ if ( trim( $settings['site_home'] ) != '' ) {
70
+ return $settings['site_home'];
71
+ }
72
+ }
73
+ $ids = $settings['ids'];
74
+ if ( $id === FALSE ) {
75
+ if ( isset( $ids[$page_url] ) ) {
76
+ $theme = $ids[$page_url]['theme'];
77
+ } else {
78
+ $theme = jr_mt_check_all( $type, $rel_url, $ids );
79
+ }
80
+ } else {
81
+ if ( isset( $ids[$id] ) ) {
82
+ $theme = $ids[$id]['theme'];
83
+ } else {
84
+ $theme = jr_mt_check_all( $type, $rel_url, $ids );
85
+ }
86
+ }
87
+ }
88
+ return $theme;
89
+ }
90
+
91
+ // Returns FALSE for Current Theme
92
+ function jr_mt_check_all( $type, $rel_url, $ids ) {
93
+ // Check Prefix entries first, because we already know there is no specific entry for this URL.
94
+ $theme = '';
95
+ $match_length = 0;
96
+ foreach ( $ids as $key => $array ) {
97
+ if ( $array['type'] == 'prefix' ) {
98
+ $this_length = strlen( $array['rel_url'] );
99
+ if ( $array['rel_url'] == substr( $rel_url, 0, $this_length ) ) {
100
+ // Need to find longest match if there are multiple prefix matches.
101
+ if ( $this_length > $match_length ) {
102
+ $theme = $array['theme'];
103
+ $match_length = $this_length;
104
+ }
105
+ }
106
+ }
107
+ }
108
+ // See if a Prefix entry was found
109
+ if ( $match_length == 0 ) {
110
+ if ( $type === FALSE ) {
111
+ $theme = FALSE; // Current Theme
112
+ } else {
113
+ $settings = get_option( 'jr_mt_settings' );
114
+ if ( isset( $settings["all_$type"] ) ) {
115
+ $theme = $settings["all_$type"];
116
+ } else {
117
+ $theme = '';
118
+ }
119
+ if ( empty( $theme ) ) {
120
+ $theme = FALSE; // Current Theme
121
+ }
122
+ }
123
+ }
124
+ return $theme;
125
+ }
126
+
127
+ ?>
jonradio-multiple-themes.php ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.0.2
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_plugin_folder;
30
+ $jr_mt_plugin_folder = basename( dirname( __FILE__ ) );
31
+
32
+ function jr_mt_plugin_folder() {
33
+ global $jr_mt_plugin_folder;
34
+ return $jr_mt_plugin_folder;
35
+ }
36
+
37
+ global $jr_mt_path;
38
+ $jr_mt_path = plugin_dir_path( __FILE__ );
39
+ function jr_mt_path() {
40
+ global $jr_mt_path;
41
+ return $jr_mt_path;
42
+ }
43
+
44
+ global $jr_mt_plugin_basename;
45
+ $jr_mt_plugin_basename = plugin_basename( __FILE__ );
46
+
47
+ if ( !function_exists( 'get_plugin_data' ) ) {
48
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
49
+ }
50
+
51
+ global $jr_mt_plugin_data;
52
+ $jr_mt_plugin_data = get_plugin_data( __FILE__ );
53
+
54
+ global $jr_mt_options_cache;
55
+ $all_options = wp_load_alloptions();
56
+ $jr_mt_options_cache['stylesheet'] = $all_options['stylesheet'];
57
+ $jr_mt_options_cache['template'] = $all_options['template'];
58
+
59
+ register_activation_hook( __FILE__, 'jr_mt_activate' );
60
+ register_deactivation_hook( __FILE__, 'jr_mt_deactivate' );
61
+
62
+ function jr_mt_activate( $network_wide ) {
63
+ if ( $network_wide ) {
64
+ global $wpdb, $site_id;
65
+ $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = $site_id" );
66
+ foreach ( $blogs as $blog_obj ) {
67
+ if ( switch_to_blog( $blog_obj->blog_id ) ) {
68
+ // We know the Site actually exists
69
+ jr_mt_activate1();
70
+ }
71
+ }
72
+ restore_current_blog();
73
+ } else {
74
+ jr_mt_activate1();
75
+ }
76
+ }
77
+
78
+ function jr_mt_activate1() {
79
+ $settings = array(
80
+ 'all_pages' => '',
81
+ 'all_posts' => '',
82
+ 'site_home' => '',
83
+ 'ids' => array()
84
+ );
85
+ // Nothing happens if Settings already exist
86
+ add_option( 'jr_mt_settings', $settings );
87
+
88
+ global $jr_mt_plugin_data;
89
+ $internal_settings = array(
90
+ 'version' => $jr_mt_plugin_data['Version']
91
+ ); // Only records you version when plugin installed, not current version
92
+ add_option( 'jr_mt_internal_settings', $internal_settings ); // Nothing happens if Settings already exist
93
+ }
94
+
95
+ add_action( 'wpmu_new_blog', 'jr_mt_new_site', 10, 6 );
96
+
97
+ function jr_mt_new_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
98
+ if ( is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
99
+ switch_to_blog( $blog_id );
100
+ jr_mt_activate1();
101
+ restore_current_blog();
102
+ }
103
+ }
104
+
105
+ function jr_mt_deactivate() {
106
+ // Nothing (yet)
107
+ }
108
+
109
+ jr_mt_version_check();
110
+
111
+ function jr_mt_version_check() {
112
+ // Check for Plugin Version update (Deactivate and Activate Hooks not fired)
113
+ $internal_settings = get_option( 'jr_mt_internal_settings' );
114
+ if ( $internal_settings ) { // Just in case Activation has not occurred yet
115
+ global $jr_mt_plugin_data;
116
+ if ( version_compare( $internal_settings['version'], $jr_mt_plugin_data['Version'], '<' ) ) {
117
+ $settings = get_option( 'jr_mt_settings' );
118
+ if ( isset( $settings['ids'] ) ) {
119
+ $ids = $settings['ids'];
120
+ } else {
121
+ $ids = array();
122
+ }
123
+ if ( version_compare( $internal_settings['version'], '2.1', '<' ) ) {
124
+ unset( $settings['all_admin'] );
125
+ // Check for Site Home entry, remove it and set Site Home field
126
+ // And remove all Admin entries (no longer supported)
127
+ if ( isset( $ids[''] ) ) {
128
+ $settings['site_home'] = $ids['']['theme'];
129
+ unset( $ids[''] );
130
+ } else {
131
+ $settings['site_home'] = '';
132
+ }
133
+ foreach ( $ids as $key => $arr ) {
134
+ if ( $arr['type'] == 'admin' ) {
135
+ unset( $ids[$key] );
136
+ }
137
+ }
138
+ }
139
+ if ( version_compare( $internal_settings['version'], '3.0', '<' ) ) {
140
+ foreach ( $ids as $key => $arr ) {
141
+ if ( strcasecmp( 'http', substr( $arr['rel_url'], 0, 4 ) ) == 0 ) {
142
+ unset( $ids[$key] );
143
+ }
144
+ }
145
+ }
146
+ $settings['ids'] = $ids;
147
+ update_option( 'jr_mt_settings', $settings );
148
+ $internal_settings['version'] = $jr_mt_plugin_data['Version'];
149
+ update_option( 'jr_mt_internal_settings', $internal_settings );
150
+ }
151
+ }
152
+ }
153
+
154
+ require_once( jr_mt_path() . 'includes/functions.php' );
155
+ require_once( jr_mt_path() . 'includes/select-theme.php' );
156
+
157
+ if ( is_admin() ) {
158
+ // Admin panel
159
+ require_once( jr_mt_path() . 'includes/admin.php' );
160
+ }
161
+
162
+ /*
163
+ Research Notes:
164
+ 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:
165
+ - is_admin()
166
+ - is_user_logged_in()
167
+ - get_option("page_on_front") - ID of home page; zero if Reading Settings NOT set to a Static Page of a WordPress Page
168
+ */
169
+
170
+ ?>
readme.txt ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.1
6
+ Tested up to: 3.6
7
+ Stable tag: 4.0.2
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. 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 and warnings 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 and warnings.
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
+ **WARNING**: It is not currently possible to have separate Widgets **AND** Menus for multiple Themes using the current version of this Plugin. The only known solution to this problem is to have multiple WordPress sites, either as a separate WordPress installation or as part of a WordPress Network using its Multisite feature. This can be done on the same domain name using either folders/subdirectories or subdomains. Each site would then have just one Theme, and you would not require this Plugin.
66
+
67
+ 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.
68
+
69
+ 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.
70
+
71
+ 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.
72
+
73
+ **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.
74
+
75
+ **Method #1:**
76
+
77
+ Set the Theme Options with Live Preview.
78
+
79
+ Note: Widgets cannot be placed using this Method.
80
+
81
+ 1. Go to Appearance-Themes-Live Preview in the Admin panels.
82
+ 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.
83
+ 1. Click the Save & Activate button.
84
+ 1. Go immediately to Appearance-Themes to reactivate the Current Theme.
85
+
86
+ **Method #2:**
87
+
88
+ Use the Theme Test Drive plugin.
89
+
90
+ 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.
91
+
92
+ 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.
93
+
94
+ 1. Deactivate jonradio Multiple Themes
95
+ 1. Install the Theme Test Drive plugin found at http://wordpress.org/extend/plugins/theme-test-drive/
96
+ 1. Activate the Theme Test Drive plugin
97
+ 1. Go to Appearance-Theme Test Drive
98
+ 1. In the Usage section, select an alternate Theme you will be using with jonradio Multiple Themes
99
+ 1. Push the Enable Theme Drive button at the bottom
100
+ 1. Go to the WordPress Admin panel's Appearance menu (left sidebar)
101
+ 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)
102
+ 1. If you have more than one alternate Theme with Options you wish to change, repeat Steps 4-8 for each alternate Theme
103
+ 1. Deactivate the Theme Test Drive plugin
104
+ 1. Activate jonradio Multiple Themes
105
+ 1. Changes to the Options for the Current Theme can now be made normally, just as you would without either plugin
106
+ 1. Both the alternate and Current Themes should now display all Theme options properly when selected through the jonradio Multiple Themes plugin
107
+
108
+ = How do I change the Template for a specific Page or Post? =
109
+
110
+ 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.
111
+
112
+ 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.
113
+
114
+ 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.
115
+
116
+ 1. Deactivate jonradio Multiple Themes
117
+ 1. Install the Theme Test Drive plugin found at http://wordpress.org/extend/plugins/theme-test-drive/
118
+ 1. Activate the Theme Test Drive plugin
119
+ 1. Go to Appearance-Theme Test Drive
120
+ 1. In the Usage section, select an alternate Theme you will be using with jonradio Multiple Themes
121
+ 1. Push the Enable Theme Drive button at the bottom
122
+ 1. Go to the WordPress Admin panel's Page or Post menu (left sidebar)
123
+ 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
124
+ 1. If you have more than one alternate Theme with Templates you wish to change, repeat Steps 4-8 for each alternate Theme
125
+ 1. Deactivate the Theme Test Drive plugin
126
+ 1. Activate jonradio Multiple Themes
127
+ 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
128
+ 1. Both the alternate and Current Themes should now display all Templates properly when selected through the jonradio Multiple Themes plugin
129
+
130
+ = How do I select a Theme for a Category of Posts? =
131
+
132
+ 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:
133
+
134
+ 1. In the WordPress Admin panels, go to Settings-Permalinks
135
+ 1. Specify a Permalinks structure that begins with /%category%/
136
+ 1. Push the Save Changes button
137
+ 1. Go to Settings-Multiple Themes plugin
138
+ 1. In the Section "For An Individual Page, Post or other non-Admin page", select the Theme for the Category of Posts
139
+ 1. Enter the URL of the Categories page, e.g. - http://domain.com/news/
140
+ 1. Click the checkbox "Select here if URL is a Prefix"
141
+ 1. Push the Save Changes button
142
+
143
+ = How do I Edit a Theme? =
144
+
145
+ WordPress includes a built-in Theme Editor. Select Editor in the Admin panel's Appearance menu items on the left sidebar.
146
+
147
+ 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.
148
+
149
+ 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.
150
+
151
+ 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.
152
+
153
+ = How do I use Elegant's epanel? =
154
+
155
+ 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.
156
+
157
+ To make changes to other Active Themes that you will be specifying with the jonradio Multiple Themes plugin:
158
+
159
+ 1. Deactivate jonradio Multiple Themes
160
+ 1. Install the Theme Test Drive plugin found at http://wordpress.org/extend/plugins/theme-test-drive/
161
+ 1. Activate the Theme Test Drive plugin
162
+ 1. Go to Appearance-Theme Test Drive
163
+ 1. In the Usage section, select an alternate Theme you will be using with jonradio Multiple Themes
164
+ 1. Push the Enable Theme Drive button at the bottom
165
+ 1. Click on the Appearance menu item on the left sidebar of the WordPress Admin panel to refresh the submenu
166
+ 1. Click on the submenu item titled with your Elegant theme's name followed by "Theme Options"
167
+ 1. Elegant's epanel will now appear
168
+ 1. Make all the changes for this Theme, being sure to push the Save button
169
+ 1. If you have more than one alternate Theme with Options you wish to change, repeat Steps 4-10 for each alternate Theme
170
+ 1. Deactivate the Theme Test Drive plugin
171
+ 1. Activate jonradio Multiple Themes
172
+ 1. Changes to the Options for the Current Theme can now be made normally, just as you would without either plugin
173
+ 1. Both the alternate and Current Themes should now display all Theme options properly when selected through the jonradio Multiple Themes plugin
174
+
175
+ Thanks to Elegant for allowing us to test copies of any of their Themes provided by their customers.
176
+
177
+ = What happens when I change Permalinks? =
178
+
179
+ 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.
180
+
181
+ = I added a new entry but why doesn't it appear in the list of entries? =
182
+
183
+ If you add an entry that already exists, it merely replaces the previous entry.
184
+
185
+ = How can I change the Theme for an entry? =
186
+
187
+ Simply add the entry again, with the new Theme. It will replace the previous entry.
188
+
189
+ == Screenshots ==
190
+
191
+ 1. Plugin's Admin Page when first installed
192
+ 2. Plugin's Admin Page, adding entries
193
+
194
+ == Changelog ==
195
+
196
+ = 4.0.2 =
197
+ * Prevent Warning and Notice by initializing global $wp
198
+
199
+ = 4.0.1 =
200
+ * Prevent Fatal Error by initializing global $wp_rewrite
201
+
202
+ = 4 =
203
+ * Discovered url_to_postid() function, to address situations where Slug differed from Permalink, such as Posts with Year/Month folders
204
+
205
+ = 3.3.1 =
206
+ * Fix White Screen of Death on a Page selected by plugin
207
+
208
+ = 3.3 =
209
+ * Support Child Themes and any other situation where stylesheet and template names are not the same
210
+
211
+ = 3.2 =
212
+ * Correct Problem with P2 Theme, and its logged on verification at wp-admin/admin-ajax.php?p2ajax=true&action=logged_in_out&_loggedin={nonce}
213
+ * Add "Settings Saved" message to Admin page
214
+ * Tested with WordPress Version 3.5 beta
215
+
216
+ = 3.1 =
217
+ * Add Support for Prefixes, where all URLs beginning with the specified characters ("Prefix") can be assigned to a specified Theme
218
+
219
+ = 3.0 =
220
+ * Add Support for Categories and Archives when no Permalinks exist (support already existed Categories and Archives with Permalinks)
221
+ * Resolve several minor bugs
222
+
223
+ = 2.9 =
224
+ * Rewrite much of the Settings page and Plugin Directory documentation
225
+ * Add Support for IIS which returns incorrect values in $_SERVER['REQUEST_URI']
226
+ * Make it easier to select the Theme for the Site Home by providing a new Settings field
227
+ * 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
228
+ * Add version upgrade detection to add, remove and update Settings fields
229
+ * Move Settings link on Plugins page from beginning to end of links
230
+
231
+ = 2.0 =
232
+ * Address pecularities of wp_make_link_relative() related to root-based WordPress sites using Permalinks
233
+
234
+ = 1.1 =
235
+ * Fix foreach failing on some systems, based on PHP warning level
236
+
237
+ = 1.0 =
238
+ * Make plugin conform to WordPress plugin repository standards.
239
+ * Beta testing completed.
240
+
241
+ == Upgrade Notice ==
242
+
243
+ = 4.0.2 =
244
+ Fix "Warning: in_array() expects parameter 2 to be array, null given in domain.com/wp-includes/rewrite.php on line 364"
245
+
246
+ = 4.0.1 =
247
+ 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"
248
+
249
+ = 4 =
250
+ Fix Posts not working in some Permalink setups, most notably Year/Month
251
+
252
+ = 3.3.1 =
253
+ Fix White Screen of Death on a Page, Post or other element selected by plugin
254
+
255
+ = 3.3 =
256
+ Remove Restriction that Stylesheet Name must match Template Name, which it does not with Child Themes
257
+
258
+ = 3.2 =
259
+ Add Support for P2 Theme and provide "Settings Saved" message
260
+
261
+ = 3.1 =
262
+ Allow Prefix URLs to be used to specify where a Theme will be displayed
263
+
264
+ = 3.0 =
265
+ Improve support for Categories and Archives, and eliminate all known bugs.
266
+
267
+ = 2.9 =
268
+ Improve Settings fields, correct display of wrong Current Theme in Appearance-Themes Admin panel, and add IIS Support.
269
+
270
+ = 2.0 =
271
+ Selecting Individual Pages and Posts on a WordPress site installed in the root and using Permalinks now works correctly.
272
+
273
+ = 1.1 =
274
+ Eliminate possibility of foreach error message if PHP warning level is set at a high level
275
+
276
+ = 1.0 =
277
+ Beta version 0.9 had not been tested when installed from the WordPress Plugin Repository
278
+
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
+ ?>