Multiple Themes - Version 4.11.1

Version Description

  • Correct foreach() error
Download this release

Release Info

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

Version 4.11.1

includes/admin-other.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Exit if .php file accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
+
5
+
6
+ // Add Link to the plugin's entry on the Admin "Plugins" Page, for easy access
7
+ add_filter( 'plugin_action_links_' . jr_mt_plugin_basename(), 'jr_mt_plugin_action_links', 10, 1 );
8
+
9
+ /**
10
+ * Creates Settings entry right on the Plugins Page entry.
11
+ *
12
+ * Helps the user understand where to go immediately upon Activation of the Plugin
13
+ * by creating entries on the Plugins page, right beside Deactivate and Edit.
14
+ *
15
+ * @param array $links Existing links for our Plugin, supplied by WordPress
16
+ * @param string $file Name of Plugin currently being processed
17
+ * @return string $links Updated set of links for our Plugin
18
+ */
19
+ function jr_mt_plugin_action_links( $links ) {
20
+ // The "page=" query string value must be equal to the slug
21
+ // of the Settings admin page.
22
+ array_push( $links, '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=jr_mt_settings' . '">Settings</a>' );
23
+ return $links;
24
+ }
25
+
26
+ ?>
includes/admin.php ADDED
@@ -0,0 +1,1155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Exit if .php file accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
+
5
+
6
+ // Admin Page
7
+
8
+ require_once( jr_mt_path() . 'includes/admin-other.php' );
9
+
10
+ add_action( 'admin_menu', 'jr_mt_admin_hook' );
11
+ // Runs just before admin_init (below)
12
+
13
+ /**
14
+ * Add Admin Menu item for plugin
15
+ *
16
+ * Plugin needs its own Page in the Settings section of the Admin menu.
17
+ *
18
+ */
19
+ function jr_mt_admin_hook() {
20
+ // Add Settings Page for this Plugin
21
+ global $jr_mt_plugin_data;
22
+ add_theme_page( $jr_mt_plugin_data['Name'], 'Multiple Themes plugin', 'switch_themes', 'jr_mt_settings', 'jr_mt_settings_page' );
23
+ add_options_page( $jr_mt_plugin_data['Name'], 'Multiple Themes plugin', 'switch_themes', 'jr_mt_settings', 'jr_mt_settings_page' );
24
+ }
25
+
26
+ global $jr_mt_kwvalsep;
27
+ /* Everything is converted to lower-case, so upper-case letter makes a good keyword-value separator
28
+ */
29
+ $jr_mt_kwvalsep = 'A';
30
+
31
+ /**
32
+ * Settings page for plugin
33
+ *
34
+ * Display and Process Settings page for this plugin.
35
+ *
36
+ */
37
+ function jr_mt_settings_page() {
38
+ global $jr_mt_plugin_data;
39
+ $jr_mt_plugin_data = array_merge( $jr_mt_plugin_data, jr_readme() );
40
+ global $jr_mt_themes_cache;
41
+ $jr_mt_themes_cache = wp_get_themes();
42
+ global $jr_mt_plugins_cache;
43
+ $jr_mt_plugins_cache = get_plugins();
44
+ add_thickbox();
45
+ echo '<div class="wrap">';
46
+ echo '<h2>' . $jr_mt_plugin_data['Name'] . '</h2>';
47
+
48
+ // Required because it is only called automatically for Admin Pages in the Settings section
49
+ settings_errors( 'jr_mt_settings' );
50
+
51
+ $theme = wp_get_theme()->Name;
52
+ global $jr_mt_options_cache;
53
+
54
+ $current_wp_version = get_bloginfo( 'version' );
55
+
56
+ if ( $jr_mt_plugin_data['read readme'] && 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 has been tested with Version ' . $directory->tested . ' of WordPress and '
90
+ . 'will probably still work with your newer version of WordPress, but you need to be aware of the issue.</p>';
91
+ } else {
92
+ if ( version_compare( $jr_mt_plugin_data['Version'], $directory->version, '=' ) ) {
93
+ /* The latest version of the Plugin has been installed,
94
+ but the readme.txt has been updated in the WordPress Plugin Directory
95
+ to indicate that it now supports the installed version of WordPress.
96
+
97
+ Latest version of Plugin has already been installed, but readme.txt is out of date,
98
+ so update readme.txt. ...if you can
99
+ */
100
+
101
+ $errmsg_before = '<h3>Warning</h3><p>Here is the problem:<ul><li> &raquo; This version (' . $jr_mt_plugin_data['Version']
102
+ . ') of this Plugin (' . $jr_mt_plugin_data['Name']
103
+ . ') has been tested with the version of WordPress you are currently running (' . $current_wp_version
104
+ . '), but</li><li> &raquo; The currently installed readme.txt file for this plugin is out of date,'
105
+ . '</li><li> &raquo; The attempt to update the readme.txt from the WordPress Plugin Repository failed, and'
106
+ . '</li><li> &raquo; The specific error is: ';
107
+ $errmsg_after = '</li></ul></p>'
108
+ . '<p>Another attempt will be made to update readme.txt each time this Settings page is displayed.'
109
+ . ' Nonetheless, this plugin should work properly even if readme.txt is out of date.</p>';
110
+
111
+ if ( is_wp_error( $file_name = download_url( $directory->download_link ) ) ) {
112
+ // Error
113
+ echo $errmsg_before . 'The plugin failed to completely download from the WordPress Repository with 300 seconds' . $errmsg_after;
114
+ } else {
115
+ if ( function_exists( 'zip_open' ) ) {
116
+ if ( is_int( $resource_handle = zip_open( $file_name ) ) ) {
117
+ // Error
118
+ echo $errmsg_before
119
+ . "php function zip_open error number $resource_handle while attempting to open the plugin's"
120
+ . 'compressed .zip file successfully downloaded from the WordPress Plugin Repository'
121
+ . $errmsg_after;
122
+ } else {
123
+ $find_readme = TRUE;
124
+ while ( $find_readme && ( FALSE !== $dir_ent = zip_read( $resource_handle ) ) ) {
125
+ if ( is_int( $dir_ent ) ) {
126
+ // Error code
127
+ echo $errmsg_before
128
+ . "php function zip_read error number $dir_ent while attempting to read the plugin's"
129
+ . ' compressed .zip file successfully downloaded from the WordPress Plugin Repository'
130
+ . $errmsg_after;
131
+ // Get out of While loop
132
+ $find_readme = FALSE;
133
+ } else {
134
+ // Wait until the While loop gets to the readme.txt entry in the Plugin's Zip file
135
+ if ( zip_entry_name( $dir_ent ) == $jr_mt_plugin_data['slug'] . '/readme.txt' ) {
136
+ if ( FALSE === zip_entry_open( $resource_handle, $dir_ent, 'rb' ) ) {
137
+ // Error
138
+ echo $errmsg_before
139
+ . 'php function zip_entry_open failed to open readme.txt file compressed within plugin .zip file in WordPress Repository'
140
+ . $errmsg_after;
141
+ } else {
142
+ $filesize = zip_entry_filesize( $dir_ent );
143
+ if ( !is_int( $filesize ) || ( $filesize < 100 ) ) {
144
+ // Error
145
+ echo $errmsg_before
146
+ . 'Size, in bytes, of readme.txt file is being incorrectly reported by php function zip_entry_filesize as '
147
+ . var_export( $filesize, TRUE )
148
+ . $errmsg_after;
149
+ } else {
150
+ $readme_content = zip_entry_read( $dir_ent, $filesize );
151
+ if ( ( $readme_content === FALSE ) || ( $readme_content === '' ) ) {
152
+ // Error
153
+ echo $errmsg_before
154
+ . 'php function zip_entry_read failed to read readme.txt file compressed within plugin .zip file in WordPress Repository'
155
+ . $errmsg_after;
156
+ } else {
157
+ if ( FALSE === zip_entry_close( $dir_ent ) ) {
158
+ // Error
159
+ echo $errmsg_before
160
+ . 'php function zip_entry_close failed to close readme.txt file compressed within plugin .zip file in WordPress Repository'
161
+ . $errmsg_after;
162
+ } else {
163
+ // Alternate: file_put_contents( jr_mt_path() . 'readme.txt', $readme_content );
164
+ $write_return = jr_filesystem_text_write( $readme_content, 'readme.txt', jr_mt_path() );
165
+ if ( is_wp_error( $write_return ) || ( FALSE === $write_return ) ) {
166
+ // Error
167
+ echo $errmsg_before
168
+ . 'WP_filesystem failed to store readme.txt file as part of download/update process from WordPress Repository'
169
+ . $errmsg_after;
170
+ }
171
+ }
172
+ }
173
+ }
174
+ }
175
+ // Get out of While loop because we have found and processed readme.txt
176
+ $find_readme = FALSE;
177
+ }
178
+ }
179
+ }
180
+ zip_close( $resource_handle );
181
+ }
182
+ } else {
183
+ echo $errmsg_before
184
+ . "php zip_open function is not defined, so readme.txt could not be updated from WordPress Plugin Repository"
185
+ . $errmsg_after;
186
+ }
187
+ // Delete temporary download file
188
+ if ( !unlink( $file_name ) ) {
189
+ echo $errmsg_before
190
+ . "php unlink function failed to delete downloaded readme.txt in temporary download file $file_name"
191
+ . $errmsg_after;
192
+ }
193
+ }
194
+ $current = TRUE;
195
+ } else {
196
+ // Recommend updating Plugin to latest version which supports the version of WordPress being run,
197
+ // but the currently-installed version of the Plugin does not.
198
+ echo '<h3>Warning</h3><p>This plugin is out of date and should be updated for performance and reliability reasons.'
199
+ . ' Plugin updates are shown on the Plugins-Installed Plugins page and the Dashboard-Updates page here in the Admin panels.</p>';
200
+ }
201
+ }
202
+ }
203
+ } else {
204
+ // Currently-installed version of Plugin supports currently-installed version of WordPress
205
+ $current = TRUE;
206
+ }
207
+
208
+ global $jr_mt_plugins_cache;
209
+
210
+ $compatible = TRUE;
211
+
212
+ // Check for incompatible plugins that have been activated: BuddyPress and Theme Test Drive
213
+ global $jr_mt_incompat_plugins;
214
+ foreach ( $jr_mt_plugins_cache as $rel_path => $plugin_data ) {
215
+ if ( in_array( $plugin_data['Name'], $jr_mt_incompat_plugins ) && is_plugin_active( $rel_path ) ) {
216
+ if ( $compatible ) {
217
+ echo '<h3>Plugin Conflict Error Detected</h3>';
218
+ $compatible = FALSE;
219
+ }
220
+ echo '<p>This Plugin (' . $jr_mt_plugin_data['Name'] . ') cannot be used when the <b>' . $plugin_data['Name']
221
+ . '</b> plugin is Activated. If you wish to use the ' . $jr_mt_plugin_data['Name']
222
+ . ' plugin, please deactivate the ' . $plugin_data['Name']
223
+ . ' plugin (not just when using this Settings page, but whenever the '
224
+ . $jr_mt_plugin_data['Name'] . ' plugin is activated).</p>';
225
+ }
226
+ }
227
+
228
+ if ( $compatible ) {
229
+ ?>
230
+ <h3>Overview</h3>
231
+ <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.
232
+ You can choose from any of the <b>Available Themes</b> listed on the Appearance-Themes Admin panel for:
233
+ <ul>
234
+ <li> &raquo; All Pages</li>
235
+ <li> &raquo; All Posts</li>
236
+ <li> &raquo; Everything (Advanced Settings)</li>
237
+ <li> &raquo; The Site Home</li>
238
+ <li> &raquo; A Specific Page</li>
239
+ <li> &raquo; A Specific Post</li>
240
+ <li> &raquo; Any other non-Admin page that has its own Permalink; for example, a specific Archive or Category page</li>
241
+ <li> &raquo; A Specific Query Keyword, or Keyword/Value pair, in any URL (<code>?keyword=value</code> or <code>&keyword=value</code>)</li>
242
+ <li> &raquo; All non-Admin pages after a Specific Query Keyword/Value pair is specified in any URL (Advanced Settings)</li>
243
+ </ul>
244
+ </p>
245
+ <h3>Important Notes</h3>
246
+ <?php
247
+ if ( function_exists('is_multisite') && is_multisite() ) {
248
+ 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.";
249
+ }
250
+ echo '<p>';
251
+ echo "The Current Theme, defined to WordPress in Appearance-Themes admin panel, is <b>$theme</b>.";
252
+ $settings = get_option( 'jr_mt_settings' );
253
+ if ( trim( $settings['current'] ) ) {
254
+ echo " But it is being overridden in Advanced Settings (see below), which set the plugin's default Theme to <b>";
255
+ echo wp_get_theme( $settings['current'] )->Name;
256
+ echo '</b>. You will not normally need to specify this default Theme in any of the other Settings on this page, though you will need to specify the WordPress Current Theme wherever you want it appear. Or, if you specify, in the Advanced Settings section, a different Theme for All Pages, All Posts or Everything, and wish to use the default Theme for one or more specific Pages, Posts or other non-Admin pages.';
257
+ } else {
258
+ echo ' You will not normally need to specify it in any of the Settings on this page. The only exception would be if you specify, in the Advanced Settings section, a different Theme for All Pages, All Posts or Everything, and wish to use the Current Theme for one or more specific Pages, Posts or other non-Admin pages.';
259
+ }
260
+ echo '</p>';
261
+ if ( $jr_mt_plugin_data['read readme'] ) {
262
+ if ( $current ) {
263
+ echo '<p>This Plugin (' . $jr_mt_plugin_data['Name'] . ') has been tested with the version of WordPress you are currently running: '
264
+ . $current_wp_version . '</p>';
265
+ }
266
+ } else {
267
+ echo '<p>Compatibility checks could not be done because the plugin was unable to read its readme.txt file, likely a user/permissions hosting issue.</p>';
268
+ }
269
+ if ( jr_mt_plugin_update_available() ) {
270
+ echo '<p>A new version of this Plugin (' . $jr_mt_plugin_data['Name'] . ') is available from the WordPress Repository.'
271
+ . ' We strongly recommend updating ASAP because new versions fix problems that users like yourself have reported to us.'
272
+ . ' <a class="thickbox" title="' . $jr_mt_plugin_data['Name'] . '" href="' . network_admin_url()
273
+ . 'plugin-install.php?tab=plugin-information&plugin=' . $jr_mt_plugin_data['slug']
274
+ . '&section=changelog&TB_iframe=true&width=640&height=768">Click here</a> for more details.</p>';
275
+ }
276
+ echo '<hr /><form action="options.php" method="POST">';
277
+
278
+ // Plugin Settings are displayed and entered here:
279
+ settings_fields( 'jr_mt_settings' );
280
+ do_settings_sections( 'jr_mt_settings_page' );
281
+ echo '<p><input name="save" type="submit" value="Save All Changes" class="button-primary" /></p></form>';
282
+ }
283
+
284
+ echo '<hr /><h3>System Information</h3><p>You are currently running:<ul>';
285
+ echo "<li> &raquo; The {$jr_mt_plugin_data['Name']} plugin Version {$jr_mt_plugin_data['Version']}</li>";
286
+ echo "<li> &nbsp; &raquo;&raquo; The Path to the plugin's directory is <code>" . rtrim( jr_mt_path(), '/' ) . '</code></li>';
287
+ echo "<li> &nbsp; &raquo;&raquo; The URL to the plugin's directory is <code>" . plugins_url() . "/{$jr_mt_plugin_data['slug']}</code></li>";
288
+ echo "<li> &raquo; WordPress Version $current_wp_version</li>";
289
+ echo '<li> &nbsp; &raquo;&raquo; WordPress language is set to ' , get_bloginfo( 'language' ) . '</li>';
290
+ echo '<li> &raquo; ' . php_uname( 's' ) . ' operating system, Release/Version ' . php_uname( 'r' ) . ' / ' . php_uname( 'v' ) . '</li>';
291
+ echo '<li> &raquo; ' . php_uname( 'm' ) . ' computer hardware</li>';
292
+ echo '<li> &raquo; Host name ' . php_uname( 'n' ) . '</li>';
293
+ echo '<li> &raquo; php Version ' . phpversion() . '</li>';
294
+ echo '<li> &nbsp; &raquo;&raquo; php memory_limit ' . ini_get('memory_limit') . '</li>';
295
+ echo '<li> &raquo; Zend engine Version ' . zend_version() . '</li>';
296
+ echo '<li> &raquo; Web Server software is ' . getenv( 'SERVER_SOFTWARE' ) . '</li>';
297
+ if ( function_exists( 'apache_get_version' ) && ( FALSE !== $apache = apache_get_version() ) ) {
298
+ echo "<li> &nbsp; &raquo;&raquo; Apache Version $apache</li>";
299
+ }
300
+ global $wpdb;
301
+ echo '<li> &raquo; MySQL Version ' . $wpdb->get_var( 'SELECT VERSION();', 0, 0 ) . '</li>';
302
+
303
+ echo '</ul></p>';
304
+ }
305
+
306
+ add_action( 'admin_init', 'jr_mt_admin_init' );
307
+
308
+ /**
309
+ * Register and define the settings
310
+ *
311
+ * Everything to be stored and/or can be set by the user
312
+ *
313
+ */
314
+ function jr_mt_admin_init() {
315
+ register_setting( 'jr_mt_settings', 'jr_mt_settings', 'jr_mt_validate_settings' );
316
+ $settings = get_option( 'jr_mt_settings' );
317
+ if ( !empty( $settings['ids']) || !empty( $settings['query'] ) ) {
318
+ add_settings_section( 'jr_mt_delete_settings_section',
319
+ 'Current Theme Selection Entries',
320
+ 'jr_mt_delete_settings_expl',
321
+ 'jr_mt_settings_page'
322
+ );
323
+ if ( !empty( $settings['ids'] ) ) {
324
+ add_settings_field( 'del_entry', 'Page/Post/Prefix Entries:', 'jr_mt_echo_delete_entry', 'jr_mt_settings_page', 'jr_mt_delete_settings_section' );
325
+ }
326
+ if ( !empty( $settings['query'] ) ) {
327
+ add_settings_field( 'del_query_entry', 'Query Keyword Entries:', 'jr_mt_echo_delete_query_entry', 'jr_mt_settings_page', 'jr_mt_delete_settings_section' );
328
+ }
329
+ }
330
+ add_settings_section( 'jr_mt_all_settings_section',
331
+ '<input name="save" type="submit" value="Save All Changes" class="button-primary" /></h3><h3>For All Pages, All Posts and/or Site Home',
332
+ 'jr_mt_all_settings_expl',
333
+ 'jr_mt_settings_page'
334
+ );
335
+ $suffix = array(
336
+ 'Pages' => '<br />(Pages created with Add Page)',
337
+ 'Posts' => ''
338
+ );
339
+ foreach ( array( 'Pages', 'Posts' ) as $thing ) {
340
+ 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',
341
+ array( 'thing' => $thing ) );
342
+ }
343
+ add_settings_field( 'site_home',
344
+ 'Select Theme for Site Home<br />(' . get_home_url() . ')',
345
+ 'jr_mt_echo_site_home',
346
+ 'jr_mt_settings_page',
347
+ 'jr_mt_all_settings_section'
348
+ );
349
+ add_settings_section( 'jr_mt_single_settings_section',
350
+ 'For An Individual Page, Post or other non-Admin page;<br />or a group of pages, specified by URL Prefix, optionally with Asterisk(s)',
351
+ 'jr_mt_single_settings_expl',
352
+ 'jr_mt_settings_page'
353
+ );
354
+ 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' );
355
+ add_settings_field( 'add_theme', 'Theme', 'jr_mt_echo_add_theme', 'jr_mt_settings_page', 'jr_mt_single_settings_section' );
356
+ 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' );
357
+ add_settings_section( 'jr_mt_querykw_section',
358
+ 'For A Query Keyword on any Page, Post or other non-Admin page',
359
+ 'jr_mt_querykw_expl',
360
+ 'jr_mt_settings_page'
361
+ );
362
+ add_settings_field( 'add_querykw_theme', 'Theme', 'jr_mt_echo_add_querykw_theme', 'jr_mt_settings_page', 'jr_mt_querykw_section' );
363
+ add_settings_field( 'add_querykw_keyword', 'Query Keyword', 'jr_mt_echo_add_querykw_keyword', 'jr_mt_settings_page', 'jr_mt_querykw_section' );
364
+ add_settings_section( 'jr_mt_query_section',
365
+ 'For A Query Keyword=Value on any Page, Post or other non-Admin page',
366
+ 'jr_mt_query_expl',
367
+ 'jr_mt_settings_page'
368
+ );
369
+ add_settings_field( 'add_query_theme', 'Theme', 'jr_mt_echo_add_query_theme', 'jr_mt_settings_page', 'jr_mt_query_section' );
370
+ add_settings_field( 'add_query_keyword', 'Query Keyword', 'jr_mt_echo_add_query_keyword', 'jr_mt_settings_page', 'jr_mt_query_section' );
371
+ add_settings_field( 'add_query_value', 'Query Value', 'jr_mt_echo_add_query_value', 'jr_mt_settings_page', 'jr_mt_query_section' );
372
+ add_settings_section( 'jr_mt_sticky_section',
373
+ '<input name="save" type="submit" value="Save All Changes" class="button-primary" /></h3><h2>Advanced Settings</h2><p><b>Warning:</b> As the name of this section implies, Advanced Settings should be fully understood or they may surprise you with unintended consequences, so please be careful.</p><h3>Sticky and Override',
374
+ 'jr_mt_sticky_expl',
375
+ 'jr_mt_settings_page'
376
+ );
377
+ add_settings_field( 'query_present', 'When to add Sticky Query to a URL', 'jr_mt_echo_query_present', 'jr_mt_settings_page', 'jr_mt_sticky_section' );
378
+ add_settings_field( 'sticky_query', 'Keyword=Value Entries:', 'jr_mt_echo_sticky_query_entry', 'jr_mt_settings_page', 'jr_mt_sticky_section' );
379
+ add_settings_section( 'jr_mt_everything_section',
380
+ 'Theme for Everything',
381
+ 'jr_mt_everything_expl',
382
+ 'jr_mt_settings_page'
383
+ );
384
+ add_settings_field( 'current',
385
+ 'Select Theme for Everything, to Override WordPress Current Theme (<b>' . wp_get_theme()->Name . '</b>)',
386
+ 'jr_mt_echo_current',
387
+ 'jr_mt_settings_page',
388
+ 'jr_mt_everything_section'
389
+ );
390
+ }
391
+
392
+ /**
393
+ * Section text for Section2
394
+ *
395
+ * Display an explanation of this Section
396
+ *
397
+ */
398
+ function jr_mt_delete_settings_expl() {
399
+ ?>
400
+ <p>
401
+ In this section, all entries are displayed for Themes selected for individual Pages, Posts
402
+ and any other non-Admin pages that have their own Permalink; for example, specific Archive or Category pages.
403
+ Or groups of Pages, Posts or any other non-Admin pages that share the same <b>URL Prefix</b>
404
+ or <b>Query Keyword</b> (<code>?keyword=value</code> or <code>&keyword=value</code>).
405
+ </p>
406
+ <p>
407
+ You can delete any of these entries by filling in the check box beside each one
408
+ and clicking the <b>Save Changes</b> button.
409
+ To change the Theme for an entry, add the same entry with a different Theme in one of the sections below this one.</p>
410
+
411
+ <?php
412
+ }
413
+
414
+ function jr_mt_echo_delete_entry() {
415
+ $settings = get_option( 'jr_mt_settings' );
416
+ $first = TRUE;
417
+ foreach ( $settings['ids'] as $path_id => $opt_array ) {
418
+ if ( $first ) {
419
+ $first = FALSE;
420
+ } else {
421
+ echo '<br />';
422
+ }
423
+ echo "Delete <input type='checkbox' id='del_entry' name='jr_mt_settings[del_entry][]' value='$path_id' /> &nbsp; Theme="
424
+ . wp_get_theme( $opt_array['theme'] )->Name . '; ';
425
+ if ( $path_id == '' ) {
426
+ echo 'Site=<a href="' . get_home_url() . '" target="_blank">Home</a>';
427
+ } else {
428
+ switch ( $opt_array['type'] ) {
429
+ case '*':
430
+ echo 'Prefix*=<a href="' . get_home_url() . "/$path_id" . '" target="_blank">' . "$path_id</a>";
431
+ break;
432
+ case 'prefix':
433
+ echo 'Prefix=<a href="' . get_home_url() . "/$path_id" . '" target="_blank">' . "$path_id</a>";
434
+ break;
435
+ case 'cat':
436
+ echo 'Category=<a href="' . get_home_url() . '/?cat=' . $opt_array['id'] . '" target="_blank">' . get_cat_name( $opt_array['id'] ) . '</a>';
437
+ break;
438
+ case 'archive':
439
+ echo 'Archive=<a href="' . get_home_url() . '/?m=' . $opt_array['id'] . '" target="_blank">' . $opt_array['id'] . '</a>';
440
+ break;
441
+ default:
442
+ $p_array = get_posts( array( 'post_type' => 'any', 'include' => array( $path_id ) ) );
443
+ if ( empty( $p_array ) ) {
444
+ if ( $opt_array['type'] == 'admin' ) {
445
+ echo 'Admin=<a href="' . get_home_url() . '/' . $opt_array['rel_url'] . '" target="_blank">' . "$path_id</a>";
446
+ } else {
447
+ echo 'Path=<a href="' . get_home_url() . "/$path_id" . '" target="_blank">' . "$path_id</a>";
448
+ }
449
+ } else {
450
+ echo ucfirst( $p_array[0]->post_type ) . '=<a href="' . get_permalink( $path_id ) . '" target="_blank">' . $p_array[0]->post_title . '</a>';
451
+ }
452
+ }
453
+ }
454
+ }
455
+ }
456
+
457
+ function jr_mt_echo_delete_query_entry() {
458
+ global $jr_mt_kwvalsep;
459
+ $settings = get_option( 'jr_mt_settings' );
460
+ $three_dots = '&#133;';
461
+ $first = TRUE;
462
+ foreach ( $settings['query'] as $keyword => $value_array ) {
463
+ foreach ( $value_array as $value => $theme ) {
464
+ if ( $first ) {
465
+ $first = FALSE;
466
+ } else {
467
+ echo '<br />';
468
+ }
469
+ echo "Delete <input type='checkbox' id='del_query_entry' name='jr_mt_settings[del_query_entry][]' value='$keyword$jr_mt_kwvalsep$value' /> &nbsp; Theme="
470
+ . wp_get_theme( $theme )->Name . '; '
471
+ . 'Query='
472
+ . '<code>'
473
+ . trim( get_home_url(), '\ /' )
474
+ . "/</code>$three_dots<code>/?"
475
+ . "<b><input type='text' readonly='readonly' disable='disabled' name='jr_mt_delkw' value='$keyword' size='"
476
+ . jr_mt_strlen( $keyword )
477
+ . "' /></b>"
478
+ . '=';
479
+ if ( '*' === $value ) {
480
+ echo '</code>' . $three_dots;
481
+ } else {
482
+ echo "<b><input type='text' readonly='readonly' disable='disabled' name='jr_mt_delkwval' value='$value' size='"
483
+ . jr_mt_strlen( $value )
484
+ . "' /></b></code>";
485
+ }
486
+ }
487
+ }
488
+ }
489
+
490
+ /**
491
+ * Section text for Section1
492
+ *
493
+ * Display an explanation of this Section
494
+ *
495
+ */
496
+ function jr_mt_all_settings_expl() {
497
+ ?>
498
+ <p>
499
+ In this section, you can select a different Theme for All Pages, All Posts and/or Site Home.
500
+ To remove a previously selected Theme, select the blank entry from the drop-down list.
501
+ </p>
502
+ <p>
503
+ 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
504
+ any other non-Admin pages that have their own Permalink; for example, specific Archive or Category pages.
505
+ Or groups of Pages, Posts or any other non-Admin pages that share the same URL Prefix.
506
+ </p>
507
+ <p>
508
+ There is also a Query Keyword section
509
+ farther down this Settings page
510
+ that allows
511
+ you to select a Theme to use whenever a specified
512
+ Query Keyword (<code>?keyword=value</code> or <code>&keyword=value</code>)
513
+ appears in the URL of any Page, Post or other non-Admin page.
514
+ </p>
515
+ <?php
516
+ }
517
+
518
+ function jr_mt_echo_all_things( $thing ) {
519
+ $settings = get_option( 'jr_mt_settings' );
520
+ $field = 'all_' . strtolower( $thing['thing'] );
521
+ jr_mt_themes_field( $field, $settings[$field], 'jr_mt_settings', TRUE );
522
+ }
523
+
524
+ function jr_mt_echo_site_home() {
525
+ $settings = get_option( 'jr_mt_settings' );
526
+ jr_mt_themes_field( 'site_home', $settings['site_home'], 'jr_mt_settings', FALSE );
527
+ }
528
+
529
+ /**
530
+ * Section text for Section3
531
+ *
532
+ * Display an explanation of this Section
533
+ *
534
+ */
535
+ function jr_mt_single_settings_expl() {
536
+ ?>
537
+ <p>
538
+ Select a Theme for an individual Page, Post or
539
+ any other non-Admin page that has its own Permalink; for example, a specific Archive or Category page.
540
+ Or for a group of pages which have URLs that all begin with the same characters ("Prefix"),
541
+ optionally specifying an Asterisk ("*") to match all subdirectories at specific levels.
542
+ </p>
543
+ <p>
544
+ Then cut and paste the URL of the desired Page, Post, Prefix or other non-Admin page.
545
+ And click the <b>Save Changes</b> button to add the entry.
546
+ </p>
547
+ There are three types of Entries that you can specify here:
548
+ <ol>
549
+ <li>
550
+ <b>URL</b> - if Visitor URL matches this URL, use this Theme
551
+ </li>
552
+ <li>
553
+ <b>URL Prefix</b> - any Visitor URL that begins with this URL Prefix will use this Theme
554
+ </li>
555
+ <li>
556
+ <b>URL Prefix with Asterisk(s)</b> - URL Prefix that matches any subdirectory where Asterisk ("*") is specified
557
+ </li>
558
+ </ol>
559
+ For the third type, an Asterisk can only be specified to match the entire subdirectory name, not parts of the name:
560
+ <blockquote>
561
+ For example, using a Permalink structure that uses dates,
562
+ where a typical Post might be at URL
563
+ <code>http://example.com/wp/2014/04/13/daily-thoughts/</code>,
564
+ a URL Prefix with Asterisk entry of
565
+ <code>http://example.com/wp/*/04/*/d</code>
566
+ would match all April Posts with Titles that begin with the letter "d", no matter what year they were posted.
567
+ </blockquote>
568
+ </p>
569
+ <?php
570
+ }
571
+
572
+ function jr_mt_echo_add_is_prefix() {
573
+ ?>
574
+ <input type="radio" id="add_is_prefix" name="jr_mt_settings[add_is_prefix]" value="false" checked="checked" /> URL<br/>
575
+ <input type="radio" id="add_is_prefix" name="jr_mt_settings[add_is_prefix]" value="prefix" /> URL Prefix<br/>
576
+ <input type="radio" id="add_is_prefix" name="jr_mt_settings[add_is_prefix]" value="*" /> URL Prefix with Asterisk ("*")
577
+ <?php
578
+ }
579
+
580
+ function jr_mt_echo_add_theme() {
581
+ jr_mt_themes_field( 'add_theme', '', 'jr_mt_settings', FALSE );
582
+ }
583
+
584
+ function jr_mt_echo_add_path_id() {
585
+ ?>
586
+ <input id="add_path_id" name="jr_mt_settings[add_path_id]" type="text" size="100" maxlength="256" value="" />
587
+ <br />
588
+ (cut and paste URL here of Page, Post, Prefix or other)
589
+ <br />
590
+ URL must begin with
591
+ <?php
592
+ echo '<code>' . trim( get_home_url(), '\ /' ) . '/</code>';
593
+ }
594
+
595
+ /**
596
+ * Section text for Section5
597
+ *
598
+ * Display an explanation of this Section
599
+ *
600
+ */
601
+ function jr_mt_querykw_expl() {
602
+ ?>
603
+ <p>
604
+ Select a Theme to use
605
+ whenever the specified Query Keyword (<code>?keyword=</code> or <code>&keyword=</code>)
606
+ is found in the URL of
607
+ any Page, Post or
608
+ any other non-Admin page.
609
+ And click the <b>Save Changes</b> button to add the entry.
610
+ </p>
611
+ <p>
612
+ <b>
613
+ Note
614
+ </b>
615
+ that Query Keyword takes precedence over all other types of Theme selection entries.
616
+ For example,
617
+ <?php
618
+ echo '<code>' . trim( get_home_url(), '\ /' ) . '?firstname=dorothy</code>'
619
+ . ' would use the Theme specified for the <code>firstname</code> keyword, not the Theme specified for Site Home.</p>';
620
+ }
621
+ function jr_mt_echo_add_querykw_theme() {
622
+ jr_mt_themes_field( 'add_querykw_theme', '', 'jr_mt_settings', FALSE );
623
+ }
624
+ function jr_mt_echo_add_querykw_keyword() {
625
+ $three_dots = '&#133;';
626
+ echo '<code>'
627
+ . trim( get_home_url(), '\ /' )
628
+ . "/</code>$three_dots<code>/?"
629
+ . '<input id="add_querykw_keyword" name="jr_mt_settings[add_querykw_keyword]" type="text" size="20" maxlength="64" value="" />=</code>'
630
+ . $three_dots;
631
+ }
632
+
633
+ /**
634
+ * Section text for Section5
635
+ *
636
+ * Display an explanation of this Section
637
+ *
638
+ */
639
+ function jr_mt_query_expl() {
640
+ ?>
641
+ <p>
642
+ Select a Theme to use
643
+ whenever the specified Query Keyword <b>and</b> Value (<code>?keyword=value</code> or <code>&keyword=value</code>)
644
+ are found in the URL of
645
+ any Page, Post or
646
+ any other non-Admin page.
647
+ And click the <b>Save Changes</b> button to add the entry.
648
+ </p>
649
+ <p>
650
+ <b>
651
+ Note
652
+ </b>
653
+ that Query Keyword=Value takes precedence over all other Theme selection entries,
654
+ including a Query Keyword entry for the same Keyword.
655
+ For example,
656
+ <?php
657
+ echo '<code>' . trim( get_home_url(), '\ /' ) . '?firstname=dorothy</code>'
658
+ . ' would use the Theme specified for the <code>firstname=dorothy</code> keyword=value pair,'
659
+ . ' not the Theme specified for Site Home nor even the Theme specified for the Keyword <code>firstname</code>.</p>';
660
+ }
661
+ function jr_mt_echo_add_query_theme() {
662
+ jr_mt_themes_field( 'add_query_theme', '', 'jr_mt_settings', FALSE );
663
+ }
664
+ function jr_mt_echo_add_query_keyword() {
665
+ $three_dots = '&#133;';
666
+ echo '<code>'
667
+ . trim( get_home_url(), '\ /' )
668
+ . "/</code>$three_dots<code>/?"
669
+ . '<input id="add_query_keyword" name="jr_mt_settings[add_query_keyword]" type="text" size="20" maxlength="64" value="" /></code>';
670
+ }
671
+ function jr_mt_echo_add_query_value() {
672
+ echo '<code>'
673
+ . '='
674
+ . '<input id="add_query_value" name="jr_mt_settings[add_query_value]" type="text" size="20" maxlength="64" value="" /></code>';
675
+ }
676
+
677
+ /**
678
+ * Section text for Section6
679
+ *
680
+ * Display an explanation of this Section
681
+ *
682
+ */
683
+ function jr_mt_sticky_expl() {
684
+ ?>
685
+ <p>
686
+ If one of the
687
+ <b>
688
+ Keyword=Value Entries
689
+ </b>
690
+ shown below
691
+ (if any)
692
+ is present in the URL of a WordPress non-Admin webpage on the current WordPress Site
693
+ and that Entry is:
694
+ <ol>
695
+ <li>
696
+ <b>Sticky</b>,
697
+ then the specified Theme will continue to be displayed for subsequent
698
+ WordPress non-Admin webpages
699
+ viewed by the same Visitor
700
+ until an Override entry is encountered by the same Visitor.
701
+ </li>
702
+ <li>
703
+ <b>Override</b>,
704
+ then the specified Theme will be displayed,
705
+ effectively ending any previous Sticky Theme that was being displayed
706
+ for the same Visitor.
707
+ </li>
708
+ </ol>
709
+ <b>
710
+ Note
711
+ </b>
712
+ that,
713
+ as explained in the
714
+ Query Keyword=Value
715
+ section above,
716
+ Query Keyword=Value already takes precedence over all other Theme selection entries,
717
+ even without the Override checkbox selected.
718
+ Override is only intended to cancel a Sticky entry
719
+ and display the specified Theme on the current WordPress non-Admin webpage.
720
+ </p>
721
+ <p>
722
+ Implementation Notes:
723
+ <ol>
724
+ <li>
725
+ The term "Same Visitor",
726
+ used above,
727
+ refers to a single combination of
728
+ computer, browser and possibly computer user name,
729
+ if the visitor's computer has multiple accounts or user names.
730
+ A computer could be a smartphone, tablet, laptop, desktop or other Internet access device used by the Visitor.
731
+ </li>
732
+ <li>
733
+ When Sticky is active for a given Visitor,
734
+ the associated Query Keyword=Value is added to the
735
+ URL of links displayed on the current WordPress non-Admin webpage.
736
+ With the following exceptions:
737
+ <ul>
738
+ <li>
739
+ a)
740
+ Only links pointing to non-Admin webpages of the current WordPress Site are altered.
741
+ </li>
742
+ <li>
743
+ b)
744
+ The
745
+ "When to add Sticky Query to a URL"
746
+ setting below also controls when a Sticky Keyword=Value is added to a URL.
747
+ </li>
748
+ </ul>
749
+ <li>
750
+ Cookies are used for Sticky entries. If the visitor's browser refuses Cookies,
751
+ this setting will not work and no error messages will be displayed.
752
+ </li>
753
+ </ol>
754
+ </p>
755
+ <?php
756
+ }
757
+
758
+ function jr_mt_echo_query_present() {
759
+ $settings = get_option( 'jr_mt_settings' );
760
+ /*
761
+ FALSE if Setting "Append if no question mark ("?") found in URL", or
762
+ TRUE if Setting "Append if no Override keyword=value found in URL"
763
+ */
764
+ echo '<input type="radio" id="query_present" name="jr_mt_settings[query_present]" value="false" ';
765
+ checked( $settings['query_present'], FALSE );
766
+ echo ' /> Append if no question mark ("?") found in URL<br/><input type="radio" id="query_present" name="jr_mt_settings[query_present]" value="true" ';
767
+ checked( $settings['query_present'] );
768
+ echo ' /> Append if no Override <code>keyword=value</code> found in URL';
769
+ }
770
+
771
+ function jr_mt_echo_sticky_query_entry() {
772
+ global $jr_mt_kwvalsep;
773
+ $settings = get_option( 'jr_mt_settings' );
774
+ $three_dots = '&#133;';
775
+ $first = TRUE;
776
+ if ( !empty( $settings['query'] ) ) {
777
+ foreach ( $settings['query'] as $keyword => $value_array ) {
778
+ foreach ( $value_array as $value => $theme ) {
779
+ if ( '*' !== $value ) {
780
+ if ( $first ) {
781
+ $first = FALSE;
782
+ } else {
783
+ echo '<br />';
784
+ }
785
+ echo 'Sticky <input type="checkbox" id="sticky_query_entry" name="jr_mt_settings[sticky_query_entry][]" value="'
786
+ . "$keyword$jr_mt_kwvalsep$value"
787
+ . '" ';
788
+ checked( isset( $settings['remember']['query'][$keyword][$value] ) );
789
+ echo ' /> &nbsp; Override <input type="checkbox" id="override_query_entry" name="jr_mt_settings[override_query_entry][]" value="'
790
+ . "$keyword$jr_mt_kwvalsep$value"
791
+ . '" ';
792
+ checked( isset( $settings['override']['query'][$keyword][$value] ) );
793
+ echo ' /> &nbsp; Theme='
794
+ . wp_get_theme( $theme )->Name . '; '
795
+ . 'Query='
796
+ . '<code>'
797
+ . trim( get_home_url(), '\ /' )
798
+ . "/</code>$three_dots<code>/?"
799
+ . "<b><input type='text' readonly='readonly' disable='disabled' name='jr_mt_stkw' value='$keyword' size='"
800
+ . jr_mt_strlen( $keyword )
801
+ . "' /></b>"
802
+ . '='
803
+ . "<b><input type='text' readonly='readonly' disable='disabled' name='jr_mt_stkwval' value='$value' size='"
804
+ . jr_mt_strlen( $value )
805
+ . "' /></b></code>";
806
+ }
807
+ }
808
+ }
809
+ }
810
+ if ( $first ) {
811
+ echo 'None';
812
+ }
813
+ }
814
+
815
+ function jr_mt_everything_expl() {
816
+ ?>
817
+ <p>
818
+ <b>Theme for Everything</b>
819
+ simplifies the use of a Theme with Admin panel settings that you need to change frequently,
820
+ when the Theme is only going to be used on one or more Pages or Posts.
821
+ The Theme can be set as the WordPress Current Theme through the Appearance-Themes admin panel,
822
+ and set for specific Pages or Posts using this plugin's settings (above),
823
+ with another Theme specified below as the plugin's default theme ("Theme for Everything").
824
+ </p>
825
+ <?php
826
+ }
827
+
828
+ function jr_mt_echo_current() {
829
+ $settings = get_option( 'jr_mt_settings' );
830
+ jr_mt_themes_field( 'current', $settings['current'], 'jr_mt_settings', TRUE );
831
+ echo '<br />(select blank entry for default: WordPress Current Theme defined in Appearance-Themes, currently <b>' . wp_get_theme()->Name . '</b>)';
832
+ }
833
+
834
+ function jr_mt_validate_settings( $input ) {
835
+ global $jr_mt_kwvalsep;
836
+ $valid = array();
837
+ foreach ( array( 'all_pages', 'all_posts', 'site_home', 'current' ) as $thing ) {
838
+ $valid[$thing] = $input[$thing];
839
+ }
840
+
841
+ $settings = get_option( 'jr_mt_settings' );
842
+ $ids = $settings['ids'];
843
+ $query = $settings['query'];
844
+ $remember = array( 'query' => array() );
845
+ if ( isset( $input['sticky_query_entry'] ) ) {
846
+ foreach ( $input['sticky_query_entry'] as $query_entry ) {
847
+ list( $keyword, $value ) = explode( $jr_mt_kwvalsep, $query_entry );
848
+ $remember['query'][$keyword][$value] = TRUE;
849
+ }
850
+ }
851
+
852
+ $override = array( 'query' => array() );
853
+ if ( isset( $input['override_query_entry'] ) ) {
854
+ foreach ( $input['override_query_entry'] as $query_entry ) {
855
+ list( $keyword, $value ) = explode( $jr_mt_kwvalsep, $query_entry );
856
+ $override['query'][$keyword][$value] = TRUE;
857
+ }
858
+ }
859
+
860
+ if ( isset ( $input['del_entry'] ) ) {
861
+ foreach ( $input['del_entry'] as $del_entry ) {
862
+ unset( $ids[$del_entry] );
863
+ }
864
+ }
865
+ if ( isset ( $input['del_query_entry'] ) ) {
866
+ foreach ( $input['del_query_entry'] as $del_entry ) {
867
+ list( $keyword, $value ) = explode( $jr_mt_kwvalsep, $del_entry );
868
+ unset( $query[$keyword][$value] );
869
+ if ( empty( $query[$keyword] ) ) {
870
+ unset( $query[$keyword] );
871
+ }
872
+ /* unset() does nothing if a variable or array element does not exist.
873
+ */
874
+ unset( $remember['query'][$keyword][$value] );
875
+ if ( empty( $remember['query'][$keyword] ) ) {
876
+ unset( $remember['query'][$keyword] );
877
+ }
878
+ unset( $override['query'][$keyword][$value] );
879
+ if ( empty( $override['query'][$keyword] ) ) {
880
+ unset( $override['query'][$keyword] );
881
+ }
882
+ }
883
+ }
884
+
885
+ /* Handle troublesome %E2%80%8E UTF Left-to-right Mark (LRM) suffix first.
886
+ */
887
+ if ( FALSE === stripos( $input['add_path_id'], '%E2%80%8E' ) ) {
888
+ if ( FALSE === stripos( rawurlencode( $input['add_path_id'] ), '%E2%80%8E' ) ) {
889
+ $url = $input['add_path_id'];
890
+ } else {
891
+ $url = rawurldecode( str_ireplace( '%E2%80%8E', '', rawurlencode( $input['add_path_id'] ) ) );
892
+ }
893
+ } else {
894
+ $url = str_ireplace( '%E2%80%8E', '', $input['add_path_id'] );
895
+ }
896
+ $url = rawurldecode( trim( $url ) );
897
+
898
+ if ( ( empty( $input['add_theme'] ) && !empty( $url ) ) || ( !empty( $input['add_theme'] ) && empty( $url ) ) ) {
899
+ add_settings_error(
900
+ 'jr_mt_settings',
901
+ 'jr_mt_emptyerror',
902
+ 'Both URL and Theme must be specified to add an Individual entry',
903
+ 'error'
904
+ );
905
+ } else {
906
+ if ( !empty( $url ) ) {
907
+ $validate_url = jr_mt_site_url( $url );
908
+ if ( $validate_url === TRUE ) {
909
+ if ( ( '*' !== $input['add_is_prefix'] ) && ( FALSE !== strpos( $url, '*' ) ) ) {
910
+ add_settings_error(
911
+ 'jr_mt_settings',
912
+ 'jr_mt_queryerror',
913
+ 'Asterisk ("*") only allowed when "URL Prefix with Asterisk" selected: <code>' . $url . '</code>',
914
+ 'error'
915
+ );
916
+ } else {
917
+ extract( jr_mt_url_to_id( $url ) );
918
+ if ( 'false' === $input['add_is_prefix'] ) {
919
+ if ( $home ) {
920
+ add_settings_error(
921
+ 'jr_mt_settings',
922
+ 'jr_mt_homeerror',
923
+ 'Please use "Select Theme for Site Home" field instead of specifying Site Home URL as an individual entry.',
924
+ 'error'
925
+ );
926
+ } else {
927
+ if ( $type == 'admin' ) {
928
+ add_settings_error(
929
+ 'jr_mt_settings',
930
+ 'jr_mt_adminerror',
931
+ 'Admin Page URLs are not allowed because no known Themes alter the appearance of Admin pages: <code>' . $url . '</code>',
932
+ 'error'
933
+ );
934
+ } else {
935
+ if ( $id === FALSE ) {
936
+ $key = $page_url;
937
+ } else {
938
+ $key = $id;
939
+ }
940
+ }
941
+ }
942
+ } else {
943
+ if ( parse_url( $url, PHP_URL_QUERY ) === NULL ) {
944
+ if ( '*' === $input['add_is_prefix'] ) {
945
+ $asterisk_not_alone = FALSE;
946
+ $no_asterisk = TRUE;
947
+ $rel_url_dirs = explode( '/', str_replace( '\\', '/', $rel_url ) );
948
+ foreach ( $rel_url_dirs as $dir ) {
949
+ if ( $no_asterisk ) {
950
+ if ( FALSE !== strpos( $dir, '*' ) ) {
951
+ $no_asterisk = FALSE;
952
+ if ( '*' !== $dir ) {
953
+ $asterisk_not_alone = TRUE;
954
+ }
955
+ }
956
+ }
957
+ }
958
+ if ( $no_asterisk ) {
959
+ add_settings_error(
960
+ 'jr_mt_settings',
961
+ 'jr_mt_queryerror',
962
+ 'No Asterisk ("*") specified but "URL Prefix with Asterisk" selected: <code>' . $url . '</code>',
963
+ 'error'
964
+ );
965
+ } else {
966
+ if ( $asterisk_not_alone ) {
967
+ add_settings_error(
968
+ 'jr_mt_settings',
969
+ 'jr_mt_queryerror',
970
+ 'An Asterisk ("*") may only replace a full subdirectory name, not just a portion of it: <code>' . $url . '</code>',
971
+ 'error'
972
+ );
973
+ }
974
+ }
975
+ }
976
+ } else {
977
+ add_settings_error(
978
+ 'jr_mt_settings',
979
+ 'jr_mt_queryerror',
980
+ '?key=val&key=val Queries are not supported in a URL Prefix: <code>' . $url . '</code>',
981
+ 'error'
982
+ );
983
+ }
984
+ $type = $input['add_is_prefix'];
985
+ $key = $rel_url;
986
+ }
987
+ $errors = get_settings_errors();
988
+ if ( empty( $errors ) ) {
989
+ $ids[$key] = array(
990
+ 'theme' => $input['add_theme'],
991
+ 'type' => $type,
992
+ 'id' => $id,
993
+ 'page_url' => $page_url,
994
+ 'rel_url' => $rel_url,
995
+ 'url' => $url
996
+ );
997
+ }
998
+ /*
999
+ $errors = get_settings_errors();
1000
+ if ( empty( $errors ) ) {
1001
+ // Here is where to check if URL gives a 404, but it doesn't work, always getting 302, and obliterating Settings Saved message
1002
+ if ( 404 == $respcode = wp_remote_retrieve_response_code( wp_remote_head( $url ) ) ) {
1003
+ add_settings_error(
1004
+ 'jr_mt_settings',
1005
+ 'jr_mt_urlerror',
1006
+ "Warning: URL specified ('$url') generated error response $respcode",
1007
+ 'error'
1008
+ );
1009
+ }
1010
+ }
1011
+ */
1012
+ }
1013
+ } else {
1014
+ add_settings_error(
1015
+ 'jr_mt_settings',
1016
+ 'jr_mt_urlerror',
1017
+ 'URL specified for Individual page/post: <code>' . $url . '</code>' . $validate_url,
1018
+ 'updated'
1019
+ );
1020
+ }
1021
+ }
1022
+ }
1023
+
1024
+ /* Make sure reserved characters are not used
1025
+ in URL Query keyword or value fields on Settings page.
1026
+ */
1027
+ function jr_mt_query_chars( $element, $where ) {
1028
+ foreach (
1029
+ array(
1030
+ '=' => 'Equals Sign' ,
1031
+ '?' => 'Question Mark' ,
1032
+ '&' => 'Ampersand' ,
1033
+ ' ' => 'Blank' ,
1034
+ '#' => 'Number Sign' ,
1035
+ '/' => 'Slash' ,
1036
+ '\\' => 'Backslash' ,
1037
+ '[' => 'Square Bracket',
1038
+ ']' => 'Square Bracket',
1039
+ ) as $char => $name ) {
1040
+ if ( FALSE !== strpos( $element, $char ) ) {
1041
+ add_settings_error(
1042
+ 'jr_mt_settings',
1043
+ 'jr_mt_queryerror',
1044
+ 'Illegal character used in '
1045
+ . $where
1046
+ . ': '
1047
+ . $name
1048
+ . ' ("' . $char . '") in "'
1049
+ . $element
1050
+ . '"',
1051
+ 'error'
1052
+ );
1053
+ return FALSE;
1054
+ }
1055
+ }
1056
+ return TRUE;
1057
+ }
1058
+ /* Data Sanitization needed here
1059
+ */
1060
+ $keyword = jr_mt_prep_query_keyword( $input['add_querykw_keyword'] );
1061
+ if ( !empty( $input['add_querykw_theme'] ) && !empty( $keyword ) ) {
1062
+ if ( jr_mt_query_chars( $keyword, 'Query Keyword' ) ) {
1063
+ /* If there is an existing entry for the Keyword,
1064
+ then replace it.
1065
+ Otherwise, create a new entry.
1066
+ */
1067
+ $query[$keyword]['*'] = $input['add_querykw_theme'];
1068
+ }
1069
+ } else {
1070
+ if ( !( empty( $input['add_querykw_theme'] ) && empty( $keyword ) ) ) {
1071
+ add_settings_error(
1072
+ 'jr_mt_settings',
1073
+ 'jr_mt_emptyerror',
1074
+ 'Both Query Keyword and Theme must be specified to add an Individual Query Keyword entry',
1075
+ 'error'
1076
+ );
1077
+ }
1078
+ }
1079
+
1080
+ /* Data Sanitization needed here
1081
+ */
1082
+ $keyword = jr_mt_prep_query_keyword( $input['add_query_keyword'] );
1083
+ $value = jr_mt_prep_query_value( $input['add_query_value'] );
1084
+ if ( !empty( $input['add_query_theme'] ) && !empty( $keyword ) && !empty( $value ) ) {
1085
+ if ( jr_mt_query_chars( $keyword, 'Query Keyword' ) && jr_mt_query_chars( $value, 'Query Value' ) ) {
1086
+ /* If there is an existing entry for the Keyword and Value pair,
1087
+ then replace it.
1088
+ Otherwise, create a new entry.
1089
+ */
1090
+ $query[$keyword][$value] = $input['add_query_theme'];
1091
+ }
1092
+ } else {
1093
+ if ( !( empty( $input['add_query_theme'] ) && empty( $keyword ) && empty( $value ) ) ) {
1094
+ add_settings_error(
1095
+ 'jr_mt_settings',
1096
+ 'jr_mt_emptyerror',
1097
+ 'Query Keyword, Value and Theme must all be specified to add an Individual Query entry',
1098
+ 'error'
1099
+ );
1100
+ }
1101
+ }
1102
+
1103
+ if ( 'true' === $input['query_present'] ) {
1104
+ $valid['query_present'] = TRUE;
1105
+ } else {
1106
+ if ( 'false' === $input['query_present'] ) {
1107
+ $valid['query_present'] = FALSE;
1108
+ }
1109
+ }
1110
+
1111
+ $errors = get_settings_errors();
1112
+ if ( empty( $errors ) ) {
1113
+ add_settings_error(
1114
+ 'jr_mt_settings',
1115
+ 'jr_mt_saved',
1116
+ 'Settings Saved',
1117
+ 'updated'
1118
+ );
1119
+ }
1120
+ $valid['ids'] = $ids;
1121
+ $valid['query'] = $query;
1122
+ $valid['remember'] = $remember;
1123
+ $valid['override'] = $override;
1124
+ return $valid;
1125
+ }
1126
+
1127
+ // $theme_name is the name of the Theme's folder within the Theme directory
1128
+ function jr_mt_themes_field( $field_name, $theme_name, $setting, $excl_current_theme ) {
1129
+ echo "<select id='$field_name' name='$setting" . "[$field_name]' size='1'>";
1130
+ if ( empty( $theme_name ) ) {
1131
+ $selected = 'selected="selected"';
1132
+ } else {
1133
+ $selected = '';
1134
+ }
1135
+ echo "<option value='' $selected></option>";
1136
+ global $jr_mt_themes_cache;
1137
+ foreach ( $jr_mt_themes_cache as $folder => $theme_obj ) {
1138
+ if ( $excl_current_theme ) {
1139
+ if ( ( jr_mt_current_theme( 'stylesheet' ) == $theme_obj['stylesheet'] ) && ( jr_mt_current_theme( 'template' ) == $theme_obj['template'] ) ) {
1140
+ // Skip the Current Theme
1141
+ continue;
1142
+ }
1143
+ }
1144
+ if ( $theme_name == $folder ) {
1145
+ $selected = 'selected="selected"';
1146
+ } else {
1147
+ $selected = '';
1148
+ }
1149
+ $name = $theme_obj->Name;
1150
+ echo "<option value='$folder' $selected>$name</option>";
1151
+ }
1152
+ echo '</select>' . PHP_EOL;
1153
+ }
1154
+
1155
+ ?>
includes/functions.php ADDED
@@ -0,0 +1,414 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Exit if .php file accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
+
5
+ if ( function_exists( 'mb_strtolower' ) ) {
6
+ function jr_mt_strlen( $string ) {
7
+ return mb_strlen( $string );
8
+ }
9
+ function jr_mt_strtolower( $string ) {
10
+ return mb_strtolower( $string );
11
+ }
12
+ } else {
13
+ function jr_mt_strlen( $string ) {
14
+ return strlen( $string );
15
+ }
16
+ function jr_mt_strtolower( $string ) {
17
+ return strtolower( $string );
18
+ }
19
+ }
20
+
21
+ /**
22
+ * Return WordPress Current Theme, as defined in Appearance Admin panels
23
+ *
24
+ * Obtains Folder Name of Current Theme, from 'template' option of wp_load_alloptions().
25
+ *
26
+ * @param string $option parameter to select current template or stylesheet
27
+ * @return string type Folder Name of Current Theme
28
+ */
29
+ function jr_mt_current_theme( $option ) {
30
+ global $jr_mt_options_cache;
31
+ return $jr_mt_options_cache[$option];
32
+ }
33
+
34
+ /**
35
+ * Given URL, return post or page ID, if possible, and relative path if not
36
+ *
37
+ * Calls jr_mt_query_keywords.
38
+ *
39
+ * @param string $url full URL of WordPress page, post, admin, etc.
40
+ * @return array array with keys of "type", "id" and "page_url":
41
+ * string type "pages", "posts" or "admin"
42
+ * string id Page ID or Post ID or FALSE
43
+ * string page_url relative URL WordPress page, post, admin, etc. or FALSE
44
+ * string rel_url URL relative to WordPress home
45
+ * bool home is URL Site Home?
46
+ */
47
+ function jr_mt_url_to_id( $url_orig ) {
48
+ // Some hosts, likely only IIS, insert an erroneous "/index.php" into the middle of the Permalink in $_SERVER['REQUEST_URI']
49
+ $url = str_replace( '/index.php', '', $url_orig );
50
+
51
+ $trim = '\ /'; // remove leading and trailing backslashes, blanks and forward slashes
52
+
53
+ $is_home = FALSE;
54
+
55
+ // get_home_url() returns "https://subdomain.domain.com/wp" - the full URL of the home page of the site
56
+ $home = trim( parse_url( get_home_url(), PHP_URL_PATH ), $trim ); // "wp"
57
+
58
+ $admin_home = trim( parse_url( admin_url(), PHP_URL_PATH ), $trim );
59
+ $page_url = trim( parse_url( $url, PHP_URL_PATH ), $trim ); // "wp/fruit/apples"
60
+ $is_admin = ( $admin_home == substr( $page_url, 0, strlen( $admin_home ) ) );
61
+ if ( !empty( $home ) ) { // Only if WordPress is installed in a subfolder, NOT in the Root
62
+ $page_url = trim( substr( $page_url, stripos( $page_url, $home ) + strlen( $home ) ), $trim ); // "fruit/apples"
63
+ }
64
+ $rel_url = $page_url;
65
+
66
+ $type = FALSE;
67
+
68
+ $id = jr_mt_query_keywords( parse_url( $url, PHP_URL_QUERY ) );
69
+ if ( $id === NULL ) {
70
+ if ( $is_admin ) {
71
+ $id = FALSE;
72
+ $type = 'admin';
73
+ } else {
74
+ // Check for home page (url_to_postid() does not work for home page)
75
+ if ( empty( $page_url ) ) {
76
+ $is_home = TRUE;
77
+ $id = get_option('page_on_front');
78
+ if ( $id == 0 ) {
79
+ // There is no home Page; posts are displayed instead on the home page
80
+ $page_url = '';
81
+ $id = FALSE;
82
+ } else {
83
+ $type = 'pages';
84
+ }
85
+ } else {
86
+ global $wp_rewrite;
87
+ if ( is_null( $wp_rewrite ) ) {
88
+ $GLOBALS['wp_rewrite'] = new WP_Rewrite();
89
+ }
90
+ global $wp;
91
+ if ( is_null( $wp ) ) {
92
+ $GLOBALS['jr_mt_cache'] = FALSE;
93
+ $wp = (object) array( 'public_query_vars' => array() );
94
+ } else {
95
+ if ( !isset( $wp->public_query_vars ) ) {
96
+ $GLOBALS['jr_mt_cache'] = FALSE;
97
+ $wp->public_query_vars = array();
98
+ }
99
+ }
100
+ $id = url_to_postid( $url );
101
+ if ( $id == 0 ) {
102
+ $page = get_page_by_path( $page_url );
103
+ if ( $page === NULL ) {
104
+ // get_page_by_path() returns NULL for Posts, Home Page, Admin, etc.
105
+ // So, check for Posts:
106
+ $post = get_posts( array( 'name' => $page_url ) );
107
+ if ( empty( $post ) ) {
108
+ $id = FALSE;
109
+ } else {
110
+ $id = $post[0]->ID;
111
+ $type = 'posts';
112
+ }
113
+ } else {
114
+ $id = $page->ID;
115
+ $type = 'pages';
116
+ }
117
+ } else {
118
+ $post_obj = get_post( $id );
119
+ if ( $post_obj->post_type == 'page' ) {
120
+ $type = 'pages';
121
+ } else {
122
+ if ( $post_obj->post_type == 'post' ) {
123
+ $type = 'posts';
124
+ }
125
+ }
126
+ }
127
+ }
128
+ }
129
+ } else {
130
+ // id in query of URL (?keyword=value&keyword=value)
131
+ $type = key( $id );
132
+ $id = $id[$type];
133
+ $page_url = FALSE;
134
+ }
135
+ return array(
136
+ 'type' => $type,
137
+ 'id' => $id,
138
+ 'page_url' => $page_url,
139
+ 'rel_url' => $rel_url,
140
+ 'home' => $is_home
141
+ );
142
+ }
143
+
144
+ /**
145
+ * Return page_id= or p= (post ID) or page= (admin page) value from a URL
146
+ *
147
+ * Calls parse_str function in its own variable space because it could create virtually any variable name!
148
+ * Only looks at page_id=, p= and page= now, but could be expanded to other query keywords.
149
+ *
150
+ * @param string $url_query Query portion (after the ?) in a URL
151
+ * @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
152
+ */
153
+ function jr_mt_query_keywords( $url_query ) {
154
+ if ( $url_query === NULL ) {
155
+ return NULL;
156
+ } else {
157
+ parse_str( $url_query );
158
+ if ( isset( $page_id ) ) {
159
+ return array( 'pages' => $page_id );
160
+ } else {
161
+ if ( isset( $p ) ) {
162
+ return array( 'posts' => $p );
163
+ } else {
164
+ if ( isset( $page ) ) {
165
+ return array( 'admin' => $page );
166
+ } else {
167
+ if ( isset( $cat ) ) {
168
+ return array( 'cat' => $cat );
169
+ } else {
170
+ if ( isset( $m ) ) {
171
+ return array( 'archive' => $m );
172
+ } else {
173
+ if ( isset( $s ) ) {
174
+ return array( 'livesearch' => $s );
175
+ } else {
176
+ return NULL;
177
+ }
178
+ }
179
+ }
180
+ }
181
+ }
182
+ }
183
+ }
184
+ }
185
+
186
+ /**
187
+ * Is the URL on the current WordPress web site?
188
+ *
189
+ * Checks if URL begins with Site Home URL.
190
+ *
191
+ * @param string $url URL to be checked to be sure it is "on" the current WordPress web site
192
+ * @return var bool TRUE if URL on current WordPress web site; string error message otherwise
193
+ */
194
+ function jr_mt_site_url( $url ) {
195
+ $check_url = trim( $url );
196
+ if ( strcasecmp( 'http', substr( $check_url, 0, 4 ) ) != 0 ) {
197
+ return 'URL does not begin with http://';
198
+ }
199
+ $site_home = get_home_url();
200
+ if ( strcasecmp( $site_home, substr( $check_url, 0, strlen( $site_home ) ) ) != 0 ) {
201
+ return "URL specified is not part of current WordPress web site. URL must begin with '$site_home'";
202
+ }
203
+ return TRUE;
204
+ }
205
+
206
+ function jr_readme() {
207
+ $readme = array( 'read readme' => FALSE );
208
+ $file_array = jr_filesystem_text_read('readme.txt', jr_mt_path());
209
+ if ( ( FALSE !== $file_array ) && !is_wp_error( $file_array ) ) {
210
+ // Get first non-blank line
211
+ $results = jr_nextline( $file_array, 0 );
212
+ if ( '===' === substr( $results['line'], 0, 3) ) {
213
+ $readme['read readme'] = TRUE;
214
+ $readme['name'] = trim( $results['line'], ' =' );
215
+ do {
216
+ $results = jr_nextline( $file_array, $results['index'] );
217
+ if ( '==' === substr( $results['line'], 0, 2) ) {
218
+ break;
219
+ } else {
220
+ $colon = strpos( $results['line'], ":", 4 );
221
+ if ( $colon !== FALSE ) {
222
+ $key = preg_replace( '/\s+/', ' ', trim( substr( $results['line'], 0, $colon ) ) );
223
+ $readme[$key] = trim( substr( $results['line'], $colon + 1 ) );
224
+ }
225
+ }
226
+ } while ( $results['line'] != "" );
227
+ }
228
+ }
229
+ return $readme;
230
+ }
231
+ function jr_nextline( $file_array, $index ) {
232
+ $line = "";
233
+ while ( ( $index < count( $file_array ) ) && ( $line === "" ) ) {
234
+ $line = trim( $file_array[$index++] );
235
+ };
236
+ return array( 'line' => $line, 'index' => $index );
237
+ // ['line'] of "" indicates End of File
238
+ // ['index'] is the next line to be read
239
+ }
240
+
241
+ /**
242
+ * Initialize Filesystem object
243
+ *
244
+ * @param str $form_url - URL of the page to display request form
245
+ * @param str $method - connection method
246
+ * @param str $context - destination folder
247
+ * @param array $fields - fileds of $_POST array that should be preserved between screens
248
+ * @return bool/str - false on failure, stored text on success
249
+ **/
250
+ function jr_filesystem_init( $form_url, $method, $context, $fields = null ) {
251
+ global $wp_filesystem;
252
+
253
+ /* first attempt to get credentials */
254
+ if (false === ($creds = request_filesystem_credentials($form_url, $method, false, $context, $fields))) {
255
+
256
+ /**
257
+ * if we comes here - we don't have credentials
258
+ * so the request for them is displaying
259
+ * no need for further processing
260
+ **/
261
+ return false;
262
+ }
263
+
264
+ /* now we got some credentials - try to use them*/
265
+ if ( !WP_Filesystem( $creds ) ) {
266
+
267
+ /* incorrect connection data - ask for credentials again, now with error message */
268
+ request_filesystem_credentials($form_url, $method, true, $context);
269
+ return false;
270
+ }
271
+
272
+ return true; //filesystem object successfully initiated
273
+ }
274
+
275
+ /**
276
+ * Read text from file
277
+ *
278
+ * @param str $form_url - URL of the page where request form will be displayed
279
+ * @return bool/str - false on failure, stored text on success
280
+ **/
281
+ function jr_filesystem_text_read($file_name, $context){
282
+ global $wp_filesystem;
283
+
284
+ $text = '';
285
+
286
+ $form_url = wp_nonce_url('themes.php?page=jr_mt_settings', 'filesystem_dummy_screen');
287
+ $method = ''; //leave this empty to perform test for 'direct' writing
288
+
289
+ if(!jr_filesystem_init($form_url, $method, $context))
290
+ return false; //stop further processing when request forms displaying
291
+
292
+ /*
293
+ * now $wp_filesystem could be used
294
+ * get correct target file first
295
+ **/
296
+ $target_dir = $wp_filesystem->find_folder($context);
297
+ $target_file = trailingslashit($target_dir).$file_name;
298
+
299
+ /* read the file */
300
+ if($wp_filesystem->exists($target_file)){ //check for existence
301
+
302
+ $text = $wp_filesystem->get_contents_array($target_file);
303
+ if(!$text)
304
+ return new WP_Error('reading_error', 'Error when reading file'); //return error object
305
+
306
+ }
307
+
308
+ return $text;
309
+ }
310
+
311
+ /**
312
+ * Perform writing into file
313
+ *
314
+ * @param str $form_url - URL of the page to display request form
315
+ * @return bool/str - false on failure, stored text on success
316
+ **/
317
+ function jr_filesystem_text_write( $content, $file_name, $context ) {
318
+ global $wp_filesystem;
319
+
320
+ $method = ''; //leave this empty to perform test for 'direct' writing
321
+ $form_url = wp_nonce_url('themes.php?page=jr_mt_settings', 'filesystem_dummy_screen');
322
+
323
+ if(!jr_filesystem_init($form_url, $method, $context))
324
+ return false; //stop further processing when request form is displaying
325
+
326
+ /*
327
+ * now $wp_filesystem could be used
328
+ * get correct target file first
329
+ **/
330
+ $target_dir = $wp_filesystem->find_folder($context);
331
+ $target_file = trailingslashit($target_dir) . $file_name;
332
+
333
+ /* write into file */
334
+ if(!$wp_filesystem->put_contents($target_file, $content, FS_CHMOD_FILE))
335
+ return new WP_Error('writing_error', 'Error when writing file'); //return error object
336
+
337
+ return $content;
338
+ }
339
+
340
+ /**
341
+ * Update available for Plugin?
342
+ *
343
+ * @return bool - TRUE if an update is available in the WordPress Repository,
344
+ * FALSE if no update is available or if the update_plugins transient is not available
345
+ * (which also results in an error message).
346
+ **/
347
+ function jr_mt_plugin_update_available() {
348
+ global $jr_mt_update_plugins;
349
+ if ( !isset( $jr_mt_update_plugins ) ) {
350
+ $transient = get_site_transient( 'update_plugins' );
351
+ if ( FALSE === $transient ) {
352
+ // Error
353
+ return FALSE;
354
+ } else {
355
+ $jr_mt_update_plugins = $transient;
356
+ }
357
+ }
358
+ if ( empty( $jr_mt_update_plugins->response ) ) {
359
+ return FALSE;
360
+ }
361
+ return array_key_exists( jr_mt_plugin_basename(), $jr_mt_update_plugins->response );
362
+ }
363
+
364
+ /**
365
+ * What Themes are defined to Plugin?
366
+ *
367
+ * @return arr - a list of Themes (folder names) defined in Settings of Plugin
368
+ **/
369
+ function jr_mt_themes_defined() {
370
+ $themes = array();
371
+ $settings = get_option( 'jr_mt_settings' );
372
+ foreach ( $settings as $key => $value ) {
373
+ if ( 'ids' == $key ) {
374
+ foreach ( $value as $id => $arr ) {
375
+ $themes[] = $arr['theme'];
376
+ }
377
+ } else {
378
+ if ( !empty( $value ) ) {
379
+ $themes[] = $value;
380
+ }
381
+ }
382
+ }
383
+ return array_unique( $themes );
384
+ }
385
+
386
+ /**
387
+ * Prepare URL Query Value
388
+ *
389
+ * Sanitize and standardize a URL Query Value for storage in a database.
390
+ * Does not support ?keyword[]=value, i.e. - $value cannot be an Array.
391
+ *
392
+ * @param string $value URL Query Value to be sanitized and standardized; will fail if array
393
+ * @return string URL Query Value after being sanitized and standardized
394
+ */
395
+ function jr_mt_prep_query_value( $value ) {
396
+ return str_ireplace( '%e2%80%8e', '', jr_mt_strtolower( trim( $value ) ) );
397
+ }
398
+ function jr_mt_prep_query_keyword( $keyword ) {
399
+ return jr_mt_prep_query_value( $keyword );
400
+ }
401
+
402
+ function jr_mt_parse_query( $query ) {
403
+ /* Written to replace parse_str which converts a dot to an underscore
404
+ */
405
+ $marker = 'jr_mt_dot';
406
+ parse_str( str_replace( '.', $marker, $query ), $marker_array );
407
+ $query_array = array();
408
+ foreach ( $marker_array as $key => $val ) {
409
+ $query_array[str_replace( $marker, '.', $key )] = str_replace( $marker, '.', $val );
410
+ }
411
+ return $query_array;
412
+ }
413
+
414
+ ?>
includes/index.html ADDED
File without changes
includes/old-wp.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Exit if .php file accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
+
5
+ /* A Version of WordPress older than the first one supported by the Plugin
6
+ is being run.
7
+ */
8
+
9
+ add_action( 'all_admin_notices', 'jr_mt_all_admin_notice' );
10
+ // Runs after admin_menu hook
11
+ add_action( 'admin_notices', 'jr_mt_all_admin_notice' ); // for older versions
12
+
13
+ function jr_mt_all_admin_notice() {
14
+ // Only displayed in Admin panels:
15
+ echo '<div class="error">Deactivated the <b>jonradio Multiple Themes</b> plugin: requires WordPress Version 3.4 or newer; you are running Version '
16
+ . get_bloginfo( 'version' ) . '</div>';
17
+ global $jr_mt_file;
18
+ deactivate_plugins( $jr_mt_file );
19
+ }
20
+
21
+ ?>
includes/select-theme.php ADDED
@@ -0,0 +1,493 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* Exit if .php file accessed directly
3
+ */
4
+ if ( !defined( 'ABSPATH' ) ) {
5
+ exit;
6
+ }
7
+
8
+ add_action( 'plugins_loaded', 'jr_mt_plugins_loaded' );
9
+ function jr_mt_plugins_loaded() {
10
+ /* Select the relevant Theme
11
+ */
12
+ add_filter( 'pre_option_stylesheet', 'jr_mt_stylesheet' );
13
+ add_filter( 'pre_option_template', 'jr_mt_template' );
14
+ }
15
+
16
+ add_action( 'wp_loaded', 'jr_mt_wp_loaded', 999 );
17
+ function jr_mt_wp_loaded() {
18
+ /* Purpose of this hook is to output any required Cookie before it is too late
19
+ (after the <html> or any other HTML is generated).
20
+ There is no performance impact because this effectively pre-caches values
21
+ for use later.
22
+ This timing is also used to enqueue JavaScript related to the Sticky feature.
23
+ */
24
+ global $jr_mt_cache;
25
+ if ( $jr_mt_cache === FALSE ) {
26
+ $settings = get_option( 'jr_mt_settings' );
27
+ if ( !empty( $settings['remember']['query'] ) ) {
28
+ jr_mt_template();
29
+ }
30
+ }
31
+ DEFINE( 'JR_MT_TOO_LATE_FOR_COOKIES', TRUE );
32
+ }
33
+
34
+ function jr_mt_stylesheet() {
35
+ return jr_mt_theme( 'stylesheet' );
36
+ }
37
+
38
+ function jr_mt_template() {
39
+ return jr_mt_theme( 'template' );
40
+ }
41
+
42
+ function jr_mt_theme( $option ) {
43
+ /* The hooks that (indirectly) call this function are called repeatedly by WordPress,
44
+ so do the checking once and store the values in a global array.
45
+ $jt_mt_theme['stylesheet'] - Stylesheet Name of Theme chosen
46
+ $jt_mt_theme['template'] - Template Name of Theme chosen
47
+
48
+ Very important note:
49
+ - get_option( 'jr_mt_settings' ) ['ids']['theme'] is the Theme Subdirectory Name,
50
+ as opposed to the Template or Stylesheet Name for the Theme.
51
+ - likewise, the variable local variable $theme
52
+ These three different values for each Theme must be clearly separated, as all three usually
53
+ match, but do not have to, e.g. - Child Themes.
54
+ */
55
+ $GLOBALS['jr_mt_cache'] = TRUE;
56
+ global $jr_mt_theme;
57
+ if ( !isset( $jr_mt_theme ) ) {
58
+ $jr_mt_theme = array();
59
+ }
60
+ if ( !isset( $jr_mt_theme[$option] ) ) {
61
+ $theme = jr_mt_chosen();
62
+ if ( $theme === FALSE ) {
63
+ // Get both at once, to save a repeat of this logic later:
64
+ $jr_mt_theme['stylesheet'] = jr_mt_current_theme( 'stylesheet' );
65
+ $jr_mt_theme['template'] = jr_mt_current_theme( 'template' );
66
+ } else {
67
+ $themes = wp_get_themes();
68
+ $jr_mt_theme['stylesheet'] = $themes[$theme]->stylesheet;
69
+ $jr_mt_theme['template'] = $themes[$theme]->template;
70
+ }
71
+ if ( !is_admin() ) {
72
+ jr_mt_cookie( 'all', 'clean' );
73
+ }
74
+ }
75
+ $theme = $jr_mt_theme[$option];
76
+ global $jr_mt_cache;
77
+ if ( $jr_mt_cache === FALSE ) {
78
+ unset( $jr_mt_theme[$option] );
79
+ }
80
+ return $theme;
81
+ }
82
+
83
+ // Returns FALSE for Current Theme
84
+ function jr_mt_chosen() {
85
+ if ( is_admin() ) {
86
+ // Admin panel
87
+ // return P2 theme if p2ajax= is present; current theme otherwise
88
+ $keywords = jr_mt_kw( 'QUERY_STRING' );
89
+ if ( isset( $keywords['p2ajax'] ) && array_key_exists( 'p2', wp_get_themes() ) ) {
90
+ $theme = 'p2';
91
+ } else {
92
+ $theme = FALSE; // Current Theme
93
+ }
94
+ return $theme;
95
+ }
96
+
97
+ /* Non-Admin page, i.e. - Public Site, etc.
98
+
99
+ Begin by checking for any Query keywords specified by the Admin in Settings,
100
+ complicated by the fact that Override entries take precedence.
101
+ */
102
+ $settings = get_option( 'jr_mt_settings' );
103
+ if ( !empty( $settings['query'] ) ) {
104
+ if ( '' !== $_SERVER['QUERY_STRING'] ) {
105
+ /* $queries - array of [keyword] => array( value, value, ... )
106
+ in the current URL.
107
+ */
108
+ $queries = jr_mt_query_array();
109
+ /* Check Override entries
110
+ */
111
+ foreach ( $settings['override']['query'] as $override_keyword => $override_value_array ) {
112
+ if ( isset( $queries[ $override_keyword ] ) ) {
113
+ foreach ( $override_value_array as $override_value => $bool ) {
114
+ if ( in_array( $override_value, $queries[ $override_keyword ] ) ) {
115
+ $override_found[] = array( $override_keyword, $override_value );
116
+ }
117
+ }
118
+ }
119
+ }
120
+ if ( !isset( $overrides_found ) ) {
121
+ /* Look for both keyword=value settings and keyword=* settings,
122
+ with keyword=value taking precedence (sorted out later).
123
+ */
124
+ foreach ( $settings['query'] as $query_settings_keyword => $value_array ) {
125
+ if ( isset( $queries[ $query_settings_keyword ] ) ) {
126
+ foreach ( $value_array as $query_settings_value => $theme ) {
127
+ if ( in_array( $query_settings_value, $queries[ $query_settings_keyword ] ) ) {
128
+ $query_found[] = array( $query_settings_keyword, $query_settings_value );
129
+ }
130
+ }
131
+ if ( in_array( '*', $queries[ $query_settings_keyword ] ) ) {
132
+ $keyword_found[] = $query_settings_keyword;
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }
138
+ }
139
+
140
+ /* Handle Overrides:
141
+ First, for Override keyword=value query in URL.
142
+ Second, for previous Override detected by PHP cookie.
143
+ */
144
+ if ( isset( $override_found ) ) {
145
+ /* If sticky, create JavaScript Sticky Cookie,
146
+ and PHP Sticky Cookie.
147
+ No matter what:
148
+ return Theme from the first Override found.
149
+ */
150
+ $keyword = $override_found[0][0];
151
+ $value = $override_found[0][1];
152
+ if ( isset( $settings['remember']['query'][ $keyword ][ $value ] ) ) {
153
+ jr_mt_js_sticky_query( $keyword, $value );
154
+ jr_mt_cookie( 'php', 'put', "$keyword=$value" );
155
+ }
156
+ return $settings['query'][ $keyword ][ $value ];
157
+ } else {
158
+ /* Is there a previous Override Query for this Site Visitor?
159
+ If so, use it, but only if it is still valid.
160
+ */
161
+ if ( FALSE !== ( $cookie = jr_mt_cookie( 'php', 'get' ) ) ) {
162
+ list( $keyword, $value ) = explode( '=', $cookie );
163
+ if ( isset( $settings['override']['query'][ $keyword ][ $value ] ) ) {
164
+ /* If sticky, create JavaScript Sticky Cookie,
165
+ and renew PHP Sticky Cookie.
166
+ No matter what:
167
+ Return Theme
168
+ */
169
+ if ( isset( $settings['remember']['query'][ $keyword ][ $value ] ) ) {
170
+ jr_mt_js_sticky_query( $keyword, $value );
171
+ jr_mt_cookie( 'php', 'put', "$keyword=$value" );
172
+ }
173
+ return $settings['query'][ $keyword ][ $value ];
174
+ }
175
+ }
176
+ }
177
+
178
+ /* Handle Non-Overrides:
179
+ keyword=value query in URL with matching setting entry.
180
+ */
181
+ if ( isset( $query_found ) ) {
182
+ $query_keyword_found = $query_found[0][0];
183
+ $query_value_found = $query_found[0][1];
184
+ /* Probably makes sense to give preference to the Sticky ones
185
+ */
186
+ foreach ( $query_found as $query_kwval_array ) {
187
+ if ( isset( $settings['remember']['query'][ $query_kwval_array[0] ][ $query_kwval_array[1] ] ) ) {
188
+ $query_keyword_found = $query_kwval_array[0];
189
+ $query_value_found = $query_kwval_array[1];
190
+ /* Create JavaScript Sticky Cookie,
191
+ and PHP Sticky Cookie.
192
+ */
193
+ jr_mt_js_sticky_query( $query_keyword_found, $query_value_found );
194
+ jr_mt_cookie( 'php', 'put', "$query_keyword_found=$query_value_found" );
195
+ break;
196
+ }
197
+ }
198
+ /* Return Theme
199
+ */
200
+ return $settings['query'][ $query_keyword_found ][ $query_value_found ];
201
+ }
202
+
203
+ /* Handle Keyword wildcards:
204
+ keyword=* setting entry that matches keyword in URL query.
205
+ */
206
+ if ( isset( $keyword_found ) ) {
207
+ return $settings['query'][ $keyword_found[0] ]['*'];
208
+ }
209
+
210
+ $full_url = parse_url( home_url(), PHP_URL_SCHEME ) . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
211
+
212
+ extract( jr_mt_url_to_id( rawurldecode( $full_url ) ) );
213
+ if ( ( 'livesearch' === $type ) && ( FALSE !== $livesearch_theme = jr_mt_livesearch_theme() ) ) {
214
+ return $livesearch_theme;
215
+ }
216
+ if ( $home ) {
217
+ if ( trim( $settings['site_home'] ) != '' ) {
218
+ return $settings['site_home'];
219
+ }
220
+ }
221
+ $ids = $settings['ids'];
222
+ if ( $id === FALSE ) {
223
+ if ( isset( $ids[$page_url] ) ) {
224
+ $theme = $ids[$page_url]['theme'];
225
+ } else {
226
+ $theme = jr_mt_check_all( $type, $rel_url, $ids );
227
+ }
228
+ } else {
229
+ if ( isset( $ids[$id] ) ) {
230
+ $theme = $ids[$id]['theme'];
231
+ } else {
232
+ $theme = jr_mt_check_all( $type, $rel_url, $ids );
233
+ }
234
+ }
235
+
236
+ return $theme;
237
+ }
238
+
239
+ /** Cookie to JavaScript with Sticky Query and related info.
240
+
241
+ Replace Existing or Create New (if no existing) Cookie
242
+ to remember what Stickey Keyword=Value to use on this Browser on this Visitor Computer.
243
+ Cookie is an encoding of this array:
244
+ - keyword=value query to append to URL
245
+ - FALSE if Setting "Append if no question mark ("?") found in URL", or
246
+ TRUE if Setting "Append if no Override keyword=value found in URL"
247
+ - an array of all sticky or override queries (empty array if FALSE)
248
+ */
249
+ function jr_mt_js_sticky_query( $keyword, $value ) {
250
+ add_action( 'wp_enqueue_scripts', 'jr_mt_wp_enqueue_scripts' );
251
+ function jr_mt_wp_enqueue_scripts() {
252
+ global $jr_mt_plugin_data;
253
+ wp_enqueue_script( 'jr_mt_sticky', plugins_url() . '/' . dirname( jr_mt_plugin_basename() ) . '/js/sticky.js', array(), $jr_mt_plugin_data['Version'] );
254
+ /* JavaScript needs some values passed in HTML,
255
+ so add that hook here, too.
256
+ */
257
+ add_action( 'wp_footer', 'jr_mt_wp_footer' );
258
+ }
259
+ function jr_mt_wp_footer() {
260
+ echo '<div style="display: none;"><div id="jr-mt-home-url" title="'
261
+ . jr_mt_prep_comp_url( get_home_url() )
262
+ . '"></div><div id="jr-mt-site-admin" title="'
263
+ . jr_mt_prep_comp_url( admin_url() )
264
+ . '"></div></div>';
265
+ }
266
+ /** Prepare URL for JavaScript compares
267
+
268
+ Remove http[s]//: from beginning
269
+ Convert rest of URL to lower-case
270
+ Remove www. from beginning, if present
271
+ Convert any backslashes to forward slashes
272
+ Remove any trailing slash(es).
273
+ */
274
+ function jr_mt_prep_comp_url( $url ) {
275
+ $comp_url = strtolower( substr( $url, 3 + strpos( $url, '://' ) ) );
276
+ if ( 'www.' === substr( $comp_url, 0, 4 ) ) {
277
+ $comp_url = substr( $comp_url, 4 );
278
+ }
279
+ return rtrim( str_replace( '\\', '/', $comp_url ), '/' );
280
+ }
281
+
282
+ $settings = get_option( 'jr_mt_settings' );
283
+
284
+ if ( $settings['query_present'] ) {
285
+ foreach ( $settings['override']['query'] as $override_keyword => $override_value_array ) {
286
+ foreach ( $override_value_array as $override_value => $theme ) {
287
+ $override[] = "$override_keyword=$override_value";
288
+ }
289
+ }
290
+ } else {
291
+ $override = array();
292
+ }
293
+
294
+ jr_mt_cookie( 'js', 'put', strtr( rawurlencode( json_encode(
295
+ array( "$keyword=$value", $settings['query_present'], $override ) ) ),
296
+ array( '%21' => '!', '%2A' => '*', '%27' => "'", '%28' => '(', '%29' => ')' ) )
297
+ );
298
+ }
299
+
300
+ /* All Cookie Handling occurs here.
301
+ $action - 'get', 'put', 'del'
302
+ */
303
+ function jr_mt_cookie( $lang, $action, $cookie_value = '' ) {
304
+ switch ( $lang ) {
305
+ case 'js':
306
+ $cookie_name = 'jr-mt-remember-query';
307
+ $raw = TRUE;
308
+ $expiry = '+36 hours';
309
+ $function = 'setrawcookie';
310
+ break;
311
+ case 'php':
312
+ $cookie_name = 'jr_mt_php_override_query';
313
+ $raw = FALSE;
314
+ $expiry = '+1 year';
315
+ $function = 'setcookie';
316
+ break;
317
+ }
318
+ if ( 'get' === $action ) {
319
+ if ( isset( $_COOKIE[ $cookie_name ] ) ) {
320
+ return $_COOKIE[ $cookie_name ];
321
+ } else {
322
+ return FALSE;
323
+ }
324
+ } else {
325
+ global $jr_mt_cookie_track;
326
+ if ( defined( 'JR_MT_TOO_LATE_FOR_COOKIES' ) ) {
327
+ return FALSE;
328
+ }
329
+ /* Determine Path off Domain to WordPress Address, not Site Address, for Cookie Path value.
330
+ Using get_home_url().
331
+ */
332
+ $cookie_path = parse_url( get_home_url(), PHP_URL_PATH ) . '/';
333
+ switch ( $action ) {
334
+ case 'put':
335
+ if ( empty( $cookie_value ) ) {
336
+ return FALSE;
337
+ } else {
338
+ return ( $jr_mt_cookie_track[ $lang ] = $function( $cookie_name, $cookie_value, strtotime( $expiry ), $cookie_path, $_SERVER['SERVER_NAME'] ) );
339
+ }
340
+ break;
341
+ case 'del':
342
+ /* Don't clutter up output to browser with a Cookie Delete request if a Cookie does not exist.
343
+ */
344
+ if ( isset( $_COOKIE[ $cookie_name ] ) ) {
345
+ return ( $jr_mt_cookie_track[ $lang ] = setrawcookie( $cookie_name, '', strtotime( '-2 days' ), $cookie_path, $_SERVER['SERVER_NAME'] ) );
346
+ }
347
+ break;
348
+ case 'clean':
349
+ if ( 'all' === $lang ) {
350
+ $clean_langs = array( 'php', 'js' );
351
+ } else {
352
+ $clean_langs = array( $lang );
353
+ }
354
+ foreach ( $clean_langs as $clean_lang ) {
355
+ if ( !isset( $jr_mt_cookie_track[ $clean_lang ] ) ) {
356
+ jr_mt_cookie( $clean_lang, 'del' );
357
+ }
358
+ }
359
+ break;
360
+ }
361
+ }
362
+ }
363
+
364
+ /** Build Query Array
365
+
366
+ $array[keyword] = array( value, value, ... )
367
+ */
368
+ function jr_mt_query_array() {
369
+ $query = explode( '&', $_SERVER['QUERY_STRING'] );
370
+ $queries = array();
371
+ foreach ( $query as $pair ) {
372
+ $kwval = explode( '=', $pair );
373
+ $keyword = $kwval[0];
374
+ if ( isset( $kwval[1] ) ) {
375
+ $value = $kwval[1];
376
+ } else {
377
+ $value = '';
378
+ }
379
+ if ( '' !== $keyword ) {
380
+ $queries[ $keyword ][] = $value;
381
+ }
382
+ }
383
+ return $queries;
384
+ }
385
+
386
+ /* Returns Keyword=Value array based on $_SERVER variable requested.
387
+ */
388
+ function jr_mt_kw( $server ) {
389
+ $keywords_raw = jr_mt_parse_query( $_SERVER[ $server ] );
390
+ $keywords = array();
391
+ foreach ( $keywords_raw as $keyword => $value ) {
392
+ if ( is_array( $value ) ) {
393
+ $kw_prepped = jr_mt_prep_query_keyword( $keyword );
394
+ foreach ( $value as $arr_key => $arr_value ) {
395
+ $keywords[$kw_prepped][jr_mt_prep_query_value( $arr_key )] = jr_mt_prep_query_value( $arr_value );
396
+ }
397
+ } else {
398
+ $keywords[jr_mt_prep_query_keyword( $keyword )] = jr_mt_prep_query_value( $value );
399
+ }
400
+ }
401
+ return $keywords;
402
+ }
403
+
404
+ // Returns FALSE for Current Theme
405
+ function jr_mt_check_all( $type, $rel_url, $ids ) {
406
+ // Check Prefix entries first, because we already know there is no specific entry for this URL.
407
+ $theme = '';
408
+ $match_length = 0;
409
+ foreach ( $ids as $key => $array ) {
410
+ if ( $array['type'] == 'prefix' ) {
411
+ $this_length = strlen( $array['rel_url'] );
412
+ if ( $array['rel_url'] == substr( $rel_url, 0, $this_length ) ) {
413
+ // Need to find longest match if there are multiple prefix matches.
414
+ if ( $this_length > $match_length ) {
415
+ $theme = $array['theme'];
416
+ $match_length = $this_length;
417
+ }
418
+ }
419
+ }
420
+ }
421
+ // See if a Prefix entry was found
422
+ if ( $match_length == 0 ) {
423
+ /* No, so now check for Asterisk
424
+ */
425
+ $current_url = str_replace( '\\', '/', $rel_url );
426
+ $current_url_dirs = explode( '/', $current_url );
427
+ $current_url_dirs_count = count( $current_url_dirs );
428
+ foreach ( $ids as $key => $array ) {
429
+ if ( '*' === $array['type'] ) {
430
+ $prefix_url = str_replace( '\\', '/', $array['rel_url'] );
431
+ $prefix_url_dirs = explode( '/', $prefix_url );
432
+ /* Current URL must have at least as many subdirectory levels
433
+ specified as Prefix Entry being tested, or it cannot match
434
+ */
435
+ if ( $current_url_dirs_count >= count( $prefix_url_dirs ) ) {
436
+ foreach ( $prefix_url_dirs as $element => $dir ) {
437
+ /* Anywhere there is an Asterisk in Entry,
438
+ Make the Current URL match at that point (subdirectory level)
439
+ */
440
+ if ( '*' === $dir ) {
441
+ $current_url_dirs[$element] = '*';
442
+ }
443
+ }
444
+ $this_length = strlen( $prefix_url );
445
+ if ( $prefix_url === substr( implode( '/', $current_url_dirs ), 0, $this_length ) ) {
446
+ // Need to find longest match if there are multiple prefix matches.
447
+ if ( $this_length > $match_length ) {
448
+ $theme = $array['theme'];
449
+ $match_length = $this_length;
450
+ }
451
+ }
452
+ }
453
+ }
454
+ }
455
+ if ( $match_length == 0 ) {
456
+ if ( $type === FALSE ) {
457
+ $theme = FALSE; // Current Theme
458
+ } else {
459
+ $settings = get_option( 'jr_mt_settings' );
460
+ if ( isset( $settings["all_$type"] ) ) {
461
+ $theme = $settings["all_$type"];
462
+ } else {
463
+ $theme = '';
464
+ }
465
+ if ( empty( $theme ) ) {
466
+ $theme = FALSE; // Current Theme
467
+ }
468
+ }
469
+ }
470
+ }
471
+ return $theme;
472
+ }
473
+
474
+ function jr_mt_livesearch_theme() {
475
+ $livesearch_themes = array( 'knowhow' );
476
+ if ( in_array( jr_mt_current_theme( 'stylesheet' ), $livesearch_themes ) ) {
477
+ return jr_mt_current_theme( 'stylesheet' );
478
+ } else {
479
+ if ( in_array( jr_mt_current_theme( 'template' ), $livesearch_themes ) ) {
480
+ return jr_mt_current_theme( 'template' );
481
+ } else {
482
+ // Go through all the Themes defined in the Plugin's settings
483
+ foreach ( jr_mt_themes_defined() as $theme ) {
484
+ if ( in_array( $theme, $livesearch_themes ) ) {
485
+ return $theme;
486
+ }
487
+ }
488
+ }
489
+ }
490
+ return FALSE;
491
+ }
492
+
493
+ ?>
index.html ADDED
File without changes
jonradio-multiple-themes.php ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.11.1
7
+ Author: David Gewirtz
8
+ Author URI: http://zatzlabs.com/plugins/
9
+ License: GPLv2
10
+ */
11
+
12
+ /* Copyright 2014 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
+ /* Exit if .php file accessed directly
30
+ */
31
+ if ( !defined( 'ABSPATH' ) ) {
32
+ exit;
33
+ }
34
+
35
+ global $jr_mt_file;
36
+ $jr_mt_file = __FILE__;
37
+
38
+ /* Catch old unsupported version of WordPress before any damage can be done.
39
+ */
40
+ if ( version_compare( get_bloginfo( 'version' ), '3.4', '<' ) ) {
41
+ require_once( plugin_dir_path( __FILE__ ) . 'includes/old-wp.php' );
42
+ } else {
43
+ /* Use $plugin_data['Name'] for the array of incompatible plugins
44
+ */
45
+ global $jr_mt_incompat_plugins;
46
+ $jr_mt_incompat_plugins = array( 'Theme Test Drive', 'BuddyPress', 'Polylang' );
47
+
48
+ global $jr_mt_path;
49
+ $jr_mt_path = plugin_dir_path( __FILE__ );
50
+ /**
51
+ * Return Plugin's full directory path with trailing slash
52
+ *
53
+ * Local XAMPP install might return:
54
+ * C:\xampp\htdocs\wpbeta\wp-content\plugins\jonradio-multiple-themes/
55
+ *
56
+ */
57
+ function jr_mt_path() {
58
+ global $jr_mt_path;
59
+ return $jr_mt_path;
60
+ }
61
+
62
+ global $jr_mt_plugin_basename;
63
+ $jr_mt_plugin_basename = plugin_basename( __FILE__ );
64
+ /**
65
+ * Return Plugin's Basename
66
+ *
67
+ * For this plugin, it would be:
68
+ * jonradio-multiple-themes/jonradio-multiple-themes.php
69
+ *
70
+ */
71
+ function jr_mt_plugin_basename() {
72
+ global $jr_mt_plugin_basename;
73
+ return $jr_mt_plugin_basename;
74
+ }
75
+
76
+ if ( !function_exists( 'get_plugin_data' ) ) {
77
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
78
+ }
79
+
80
+ global $jr_mt_plugin_data;
81
+ $jr_mt_plugin_data = get_plugin_data( __FILE__ );
82
+ $jr_mt_plugin_data['slug'] = basename( dirname( __FILE__ ) );
83
+
84
+ global $jr_mt_options_cache;
85
+ $all_options = wp_load_alloptions();
86
+ $jr_mt_options_cache['stylesheet'] = $all_options['stylesheet'];
87
+ $jr_mt_options_cache['template'] = $all_options['template'];
88
+
89
+ /* Detect initial activation or a change in plugin's Version number
90
+
91
+ Sometimes special processing is required when the plugin is updated to a new version of the plugin.
92
+ Also used in place of standard activation and new site creation exits provided by WordPress.
93
+ Once that is complete, update the Version number in the plugin's Network-wide settings.
94
+ */
95
+
96
+ if ( ( FALSE === ( $internal_settings = get_option( 'jr_mt_internal_settings' ) ) )
97
+ || empty( $internal_settings['version'] ) )
98
+ {
99
+ /* Plugin is either:
100
+ - updated from a version so old that Version was not yet stored in the plugin's settings, or
101
+ - first use after install:
102
+ - first time ever installed, or
103
+ - installed previously and properly uninstalled (data deleted)
104
+ */
105
+
106
+ $old_version = '0.1';
107
+ } else {
108
+ $old_version = $internal_settings['version'];
109
+ }
110
+
111
+ $settings = get_option( 'jr_mt_settings' );
112
+ if ( empty( $settings ) ) {
113
+ $settings = array(
114
+ 'all_pages' => '',
115
+ 'all_posts' => '',
116
+ 'site_home' => '',
117
+ 'current' => '',
118
+ 'query' => array(),
119
+ 'remember' => array( 'query' => array() ),
120
+ 'override' => array( 'query' => array() ),
121
+ 'query_present' => FALSE,
122
+ 'ids' => array()
123
+ );
124
+ /* Add if Settings don't exist, re-initialize if they were empty.
125
+ */
126
+ update_option( 'jr_mt_settings', $settings );
127
+ /* New install on this site, very old version or corrupt settings
128
+ */
129
+ $old_version = $jr_mt_plugin_data['Version'];
130
+ }
131
+
132
+ require_once( jr_mt_path() . 'includes/functions.php' );
133
+
134
+ if ( version_compare( $old_version, $jr_mt_plugin_data['Version'], '!=' ) ) {
135
+ if ( !isset( $settings['remember'] ) ) {
136
+ $settings['remember'] = array( 'query' => array() );
137
+ }
138
+
139
+ if ( isset( $settings['ids'] ) && is_array( $settings['ids'] ) ) {
140
+ $ids = $settings['ids'];
141
+ } else {
142
+ $ids = array();
143
+ }
144
+
145
+ /* Create, if internal settings do not exist; update if they do exist
146
+ */
147
+ $internal_settings['version'] = $jr_mt_plugin_data['Version'];
148
+ update_option( 'jr_mt_internal_settings', $internal_settings );
149
+
150
+ /* Handle all Settings changes made in old plugin versions
151
+ */
152
+ if ( version_compare( $old_version, '2.1', '<' ) ) {
153
+ unset( $settings['all_admin'] );
154
+ // Check for Site Home entry, remove it and set Site Home field
155
+ // And remove all Admin entries (no longer supported)
156
+ if ( isset( $ids[''] ) ) {
157
+ $settings['site_home'] = $ids['']['theme'];
158
+ unset( $ids[''] );
159
+ } else {
160
+ $settings['site_home'] = '';
161
+ }
162
+ foreach ( $ids as $key => $arr ) {
163
+ if ( $arr['type'] == 'admin' ) {
164
+ unset( $ids[$key] );
165
+ }
166
+ }
167
+ }
168
+ if ( version_compare( $old_version, '3.0', '<' ) ) {
169
+ foreach ( $ids as $key => $arr ) {
170
+ if ( strcasecmp( 'http', substr( $arr['rel_url'], 0, 4 ) ) == 0 ) {
171
+ unset( $ids[$key] );
172
+ }
173
+ }
174
+ }
175
+ if ( version_compare( $old_version, '4.1', '<' ) ) {
176
+ /* Replace %hex with real character to support languages like Chinese
177
+ */
178
+ foreach ( $ids as $key => $arr ) {
179
+ $newkey = rawurldecode( $key );
180
+ $newarr = $arr;
181
+ unset( $ids[$key] );
182
+ $newarr['page_url'] = rawurldecode( $newarr['page_url'] );
183
+ $newarr['rel_url'] = rawurldecode( $newarr['rel_url'] );
184
+ $newarr['url'] = rawurldecode( $newarr['url'] );
185
+ $ids[$newkey] = $newarr;
186
+ }
187
+ }
188
+ if ( version_compare( $old_version, '4.1.2', '<' ) ) {
189
+ // Add new Current Theme override option
190
+ $settings['current'] = '';
191
+ }
192
+ if ( version_compare( $old_version, '4.6', '<' ) ) {
193
+ // Add new Query Keyword override option
194
+ $settings['query'] = array();
195
+ }
196
+ if ( version_compare( $old_version, '4.7', '<' ) ) {
197
+ /* Change the format of the Query array
198
+ */
199
+ $query = array();
200
+ foreach ( $settings['query'] as $number => $keyword_array ) {
201
+ foreach ( $keyword_array as $keyword => $theme ) {
202
+ $query[ jr_mt_prep_query_keyword( $keyword ) ]['*'] = $theme;
203
+ }
204
+ }
205
+ $settings['query'] = $query;
206
+ }
207
+ if ( version_compare( $old_version, '4.11', '<' ) ) {
208
+ $settings['override'] = $settings['remember'];
209
+ $settings['query_present'] = FALSE;
210
+ }
211
+ if ( version_compare( $old_version, '4.11.1', '<' ) ) {
212
+ foreach ( array( 'override', 'remember' ) as $what ) {
213
+ if ( empty( $settings[ $what ] ) ) {
214
+ $settings[ $what ] = array( 'query' => array() );
215
+ }
216
+ }
217
+ }
218
+
219
+ $settings['ids'] = $ids;
220
+ update_option( 'jr_mt_settings', $settings );
221
+ }
222
+
223
+ if ( is_admin() ) {
224
+ // Admin panel
225
+ require_once( jr_mt_path() . 'includes/admin.php' );
226
+ } else {
227
+ // Setting of Blank uses WordPress Current Theme value
228
+ if ( trim( $settings['current'] ) ) {
229
+ $jr_mt_options_cache['stylesheet'] = $settings['current'];
230
+ $jr_mt_options_cache['template'] = $settings['current'];
231
+ }
232
+ require_once( jr_mt_path() . 'includes/select-theme.php' );
233
+ }
234
+ }
235
+
236
+ /* Settings structure:
237
+ code - get_option( 'jr_mt_settings' )
238
+ ['all_pages'] => zero length string or folder in Themes directory containing theme to use for All Pages
239
+ ['all_posts'] => zero length string or folder in Themes directory containing theme to use for All Posts
240
+ ['site_home'] => zero length string or folder in Themes directory containing theme to use for Home Page
241
+ ['current'] => zero length string or folder in Themes directory containing theme to override WordPress Current Theme
242
+ ['ids']
243
+ [id] - zero length string or WordPress ID of Page, Post, etc.
244
+ ['type'] => 'page' or 'post' or 'admin' or 'cat' or 'archive' or 'prefix' or other
245
+ ['theme'] => folder in Themes directory containing theme to use
246
+ ['id'] => FALSE or WordPress ID of Page, Post, etc.
247
+ ['page_url'] => relative URL WordPress page, post, admin, etc. or FALSE
248
+ ['rel_url'] => URL relative to WordPress home
249
+ ['url'] => original full URL, from Settings page entry by user
250
+ */
251
+
252
+ /*
253
+ Research Notes:
254
+ 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:
255
+ - is_admin()
256
+ - is_user_logged_in()
257
+ - get_option("page_on_front") - ID of home page; zero if Reading Settings NOT set to a Static Page of a WordPress Page
258
+ */
259
+
260
+ ?>
js/sticky.js ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* When the page has fully loaded,
2
+ check if the Plugin's cookie is present
3
+ and decipher it into values that will
4
+ control processing:
5
+ an array consisting of:
6
+ - keyword=value query to append to URL
7
+ - FALSE if Setting "append if question mark ("?") not present", or
8
+ TRUE if Setting "append if another Override query not present"
9
+ - an array of all sticky or override queries (empty array if FALSE)
10
+ If cookie is present, look at all <a> tag href= URLs.
11
+ Restriction: ignore all Relative URLs - those without ://
12
+ For each one, check if it is in the current WordPress site,
13
+ but not in Admin panels (/wp-admin/):
14
+ - strip up to and including ://
15
+ - convert to lower-case
16
+ - if present, strip leading www.
17
+ - convert \ to /
18
+ - remove trailing / of Home URL and Site Admin URL
19
+ If so, append the current Query (keyword=value) specified in
20
+ the plugin's Cookie, to the href= URL, except when:
21
+ - a ? is present in the URL if the plugin Setting is set to that;
22
+ - an override query is already present in the URL, if the plugin
23
+ Setting allows ? in the URL
24
+ - the same sticky query is already present in the URL
25
+ Appending a Query to the URL is done by:
26
+ - inserting it before any # (Fragment, i.e. - Bookmark) in the URL
27
+ - appending to URL otherwise
28
+ - prefixed by ? is ? is not already present
29
+ - prefixed by & if ? is already present
30
+ In addition, hidden text in the HTML provides:
31
+ - WordPress Site Address (URL)
32
+ - WordPress /wp-admin/ URL
33
+ These values are not available for the Cookie, because WordPress must be
34
+ loaded before these values are available.
35
+ */
36
+ window.onload =
37
+ function ( ) {
38
+ var allCookies, keywordMatch, pos, valueStart, cookieArray, query, homeUrl, siteAdmin, appendSetting, overrideQueries, overrideQueriesEmpty, hrefs, i, max, href, colonSlashSlash, hrefCompare, addQuery, posQuestionMark, posNumberSign, hrefQueries,
39
+ cookieEquals = 'jr-mt-remember-query=',
40
+ cookieSplit = '; ';
41
+
42
+ /* Check if there are any Cookies at all.
43
+ */
44
+ if ( '' !== allCookies ) {
45
+ allCookies = cookieSplit + document.cookie + cookieSplit;
46
+ keywordMatch = cookieSplit + cookieEquals;
47
+ pos = allCookies.indexOf( keywordMatch );
48
+ /* Check if our cookie is present.
49
+ */
50
+ if ( -1 !== pos ) {
51
+ valueStart = pos + keywordMatch.length;
52
+ /* Extract Value of Cookie, which is found after the equals sign and before the semicolon
53
+ */
54
+ cookieArray = JSON.parse( decodeURIComponent( allCookies.substring( pos + keywordMatch.length, allCookies.indexOf( cookieSplit, pos + cookieSplit.length ) ) ) );
55
+ /* Assign Cookie array elements to meaningfully-named variables.
56
+ */
57
+ query = cookieArray[0];
58
+ appendSetting = cookieArray[1];
59
+ overrideQueries = cookieArray[2];
60
+ overrideQueriesEmpty = ( 0 === overrideQueries.length );
61
+
62
+ homeUrl = document.getElementById( 'jr-mt-home-url' )['title'];
63
+ siteAdmin = document.getElementById( 'jr-mt-site-admin' )['title'];
64
+
65
+ hrefs = document.getElementsByTagName ( 'a' );
66
+ for ( i = 0, max = hrefs.length; i < max; i++ ) {
67
+ href = hrefs [ i ] ['href'];
68
+ colonSlashSlash = href.indexOf( '://' );
69
+ /* Ignore Relative URLs: those without ://
70
+ */
71
+ if ( -1 !== colonSlashSlash ) {
72
+ hrefCompare = href.substring( colonSlashSlash + 3 ).toLowerCase();
73
+ if ( 'www.' === hrefCompare.substring( 0, 4 ) ) {
74
+ hrefCompare = hrefCompare.substring( 4 );
75
+ }
76
+ hrefCompare = hrefCompare.replace( /\\/g, '/' );
77
+ addQuery = '';
78
+ if ( hrefCompare.substring( 0, homeUrl.length ) === homeUrl ) {
79
+ if ( hrefCompare.substring( 0, siteAdmin.length ) !== siteAdmin ) {
80
+ posQuestionMark = href.indexOf( '?' );
81
+ posNumberSign = href.indexOf( '#' );
82
+ if ( -1 === posNumberSign ) {
83
+ posNumberSign = href.length;
84
+ }
85
+ /* Only add a Query if one does not already exist.
86
+ */
87
+ if ( -1 === posQuestionMark ) {
88
+ /* Query must be before the Fragment (#anchor),
89
+ when one exists.
90
+ */
91
+ addQuery = '?';
92
+ } else {
93
+ /* Query exists because "?" found in URL.
94
+ Check if setting set to add query when one already exists.
95
+ If not, don't touch this URL.
96
+ */
97
+ if ( appendSetting ) {
98
+ addQuery = '&';
99
+ hrefQueries = href.substring( posQuestionMark + 1, posNumberSign ).split( '&' );
100
+ /* Don't append Sticky query if it is already present in the URL
101
+ */
102
+ if ( -1 !== hrefQueries.indexOf( query ) ) {
103
+ addQuery = '';
104
+ } else {
105
+ if ( !overrideQueriesEmpty ) {
106
+ for ( j = 0, hrefQueriesLength = hrefQueries.length; j < hrefQueriesLength; j++ ) {
107
+ /* Don't append Sticky query if an Override query is present in URL
108
+ */
109
+ if ( -1 !== overrideQueries.indexOf( hrefQueries[ j ] ) ) {
110
+ /* Override query already in URL.
111
+ */
112
+ addQuery = '';
113
+ break;
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+ }
120
+ }
121
+ }
122
+ if ( '' !== addQuery ) {
123
+ /* No override or sticky query already in URL, so safe to add current sticky query.
124
+ */
125
+ hrefs [ i ] ['href'] = href.substring( 0, posNumberSign ) + addQuery + query + href.substring( posNumberSign );
126
+ }
127
+ }
128
+ }
129
+ }
130
+ }
131
+ };
readme.txt ADDED
@@ -0,0 +1,420 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: 4.0
7
+ Stable tag: 4.11.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"), an Asterisk ("*") can be used to match all subdirectories at a specific level in the directory/folder hierarchy, and a Query Keyword feature allows a Theme to be selected whenever a specified ?keyword= or &keyword= is found in the URL. A Theme can also be specified for All Pages, All Posts or Everywhere. In turn, even when a Theme is specified for All Pages, All Posts or Everywhere, 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 Paid Themes**: Some Paid Themes do not work with this plugin. See the FAQ tab for more information and alternatives.
30
+
31
+ **Use with other Plugins**: **BuddyPress**, **Polylang** and **Theme Test Drive** plugins must all be Deactivated when jonradio Multiple Themes is Activated
32
+
33
+ **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.
34
+
35
+ 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.
36
+
37
+ To select any URL on the site that contains a specified Query Keyword ("?keyword=" or "&keyword=") or Query Keyword=Value combination ("?keyword=value" or "&keyword=value"), a "Query Keyword" entry can be created. A Sticky option can be set to make all subsequent non-Admin pages viewed by the same Visitor display using the same Theme, but it does require the Visitor's browser to accept Cookies.
38
+
39
+ Normally, 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. The plugin has an Advanced Setting "Select Theme for Everything" that can be used to define a default Theme for the plugin to use instead of the WordPress Current Theme. This is useful for a Theme that has many frequently-used options that are much easier to access when it is the WordPress Current Theme, but there is another Theme to be used everywhere except for a few select Pages or Posts.
40
+
41
+ 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.
42
+
43
+ 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.
44
+
45
+ == Installation ==
46
+
47
+ This section describes how to install the *jonradio Multiple Themes* plugin and get it working.
48
+
49
+ 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.
50
+ 1. Activate the *jonradio Multiple Themes* plugin through the **Installed Plugins** Admin panel in WordPress. If you have a WordPress Network ("Multisite"), you can either **Network Activate** this plugin through the **Installed Plugins** Network Admin panel, 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. Alternatively, to avoid this confusion, you can install the *jonradio Reveal Network Activated Plugins* plugin.
51
+ 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 ("Multisite"), Themes must be **Network Enabled** before they will appear as Available Themes on individual sites' Appearance-Themes panel.
52
+ 1. Select Themes to be used on the plugin's **Multiple Themes plugin** Settings page in the WordPress Admin panels, which is found in both the **Appearance** and **Settings** sections. You can also get to this Settings page by clicking on the **Settings** link for this plugin on the **Installed Plugins** page of the Admin panel.
53
+ 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.
54
+
55
+ == Frequently Asked Questions ==
56
+
57
+ = What if my Themes or other plugins don't seem to be working with the jonradio Multiple Themes plugin? =
58
+
59
+ Please ask before giving up. Either by [posting a Support question](http://wordpress.org/support/plugin/jonradio-multiple-themes "Support Forum") or contacting us directly by filling out this [Contact Form (click here)](http://zatzlabs.com/contact-us/ "Contact Form").
60
+
61
+ If we cannot solve the problem, please consider using a WordPress Network. One install of WordPress allows you to have multiple separate Sites ("MultiSite"), each with a different Theme, without using the jonradio Multiple Themes plugin. The sites can look to the outside world as if they are just one web site by using the Sub-directories option. For example, Site 1 would be at example.com, and Site 2 could be at example.com/forum.
62
+
63
+ = What if a Theme has a lot of Options that I need to change frequently? =
64
+
65
+ You will probably want to make it the WordPress Current Theme defined in the Appearance-Themes admin panel,
66
+ so that you will have instant access to the Theme's many Options, especially if the Theme has its own Section(s) of the Admin panel menu.
67
+
68
+ The plugin's Advanced Setting **Select Theme for Everything** can be used to select another Theme to be used everywhere except for the specific Page(s) or Post(s) where you wish the WordPress Current Theme to appear.
69
+
70
+ = Will this plugin work with Paid Themes? =
71
+
72
+ Some do, some do not; unfortunately, there are a growing number of newer Paid Themes that incorporate so many WordPress Hooks that it is not feasible for this plugin to handle them all. 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.
73
+
74
+ 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.
75
+
76
+ 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.
77
+
78
+ = How do I change the Theme Options (Widgets, Sidebars, Menus, Background, Header, etc.) used for each Theme? =
79
+
80
+ **NOTE**: See the next FAQ for information on Templates.
81
+
82
+ 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.
83
+
84
+ 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.
85
+
86
+ 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.
87
+
88
+ **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.
89
+
90
+ **Method #1:**
91
+
92
+ Set the Theme Options with Live Preview.
93
+
94
+ Note: Widgets cannot be placed using this Method.
95
+
96
+ 1. Go to Appearance-Themes-Live Preview in the Admin panels.
97
+ 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.
98
+ 1. Click the Save & Activate button.
99
+ 1. Go immediately to Appearance-Themes to reactivate the Current Theme.
100
+
101
+ **Method #2:**
102
+
103
+ Use the Theme Test Drive plugin.
104
+
105
+ 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.
106
+
107
+ 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.
108
+
109
+ 1. Deactivate jonradio Multiple Themes
110
+ 1. Install the Theme Test Drive plugin found at http://wordpress.org/extend/plugins/theme-test-drive/
111
+ 1. Activate the Theme Test Drive plugin
112
+ 1. Go to Appearance-Theme Test Drive
113
+ 1. In the Usage section, select an alternate Theme you will be using with jonradio Multiple Themes
114
+ 1. Push the Enable Theme Drive button at the bottom
115
+ 1. Go to the WordPress Admin panel's Appearance menu (left sidebar)
116
+ 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)
117
+ 1. If you have more than one alternate Theme with Options you wish to change, repeat Steps 4-8 for each alternate Theme
118
+ 1. Deactivate the Theme Test Drive plugin
119
+ 1. Activate jonradio Multiple Themes
120
+ 1. Changes to the Options for the Current Theme can now be made normally, just as you would without either plugin
121
+ 1. Both the alternate and Current Themes should now display all Theme options properly when selected through the jonradio Multiple Themes plugin
122
+
123
+ = How do I change the Template for a specific Page or Post? =
124
+
125
+ 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.
126
+
127
+ 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.
128
+
129
+ 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.
130
+
131
+ 1. Deactivate jonradio Multiple Themes
132
+ 1. Install the Theme Test Drive plugin found at http://wordpress.org/extend/plugins/theme-test-drive/
133
+ 1. Activate the Theme Test Drive plugin
134
+ 1. Go to Appearance-Theme Test Drive
135
+ 1. In the Usage section, select an alternate Theme you will be using with jonradio Multiple Themes
136
+ 1. Push the Enable Theme Drive button at the bottom
137
+ 1. Go to the WordPress Admin panel's Page or Post menu (left sidebar)
138
+ 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
139
+ 1. If you have more than one alternate Theme with Templates you wish to change, repeat Steps 4-8 for each alternate Theme
140
+ 1. Deactivate the Theme Test Drive plugin
141
+ 1. Activate jonradio Multiple Themes
142
+ 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
143
+ 1. Both the alternate and Current Themes should now display all Templates properly when selected through the jonradio Multiple Themes plugin
144
+
145
+ = How do I select a Theme for a Category of Posts? =
146
+
147
+ 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:
148
+
149
+ 1. In the WordPress Admin panels, go to Settings-Permalinks
150
+ 1. Specify a Permalinks structure that begins with /%category%/
151
+ 1. Push the Save Changes button
152
+ 1. Go to Settings-Multiple Themes plugin
153
+ 1. In the Section "For An Individual Page, Post or other non-Admin page", select the Theme for the Category of Posts
154
+ 1. Enter the URL of the Categories page, e.g. - http://domain.com/news/
155
+ 1. Click the checkbox "Select here if URL is a Prefix"
156
+ 1. Push the Save Changes button
157
+
158
+ = How do I Edit a Theme? =
159
+
160
+ WordPress includes a built-in Theme Editor. Select Editor in the Admin panel's Appearance menu items on the left sidebar.
161
+
162
+ 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.
163
+
164
+ 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.
165
+
166
+ 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.
167
+
168
+ = How do I use Elegant's epanel? =
169
+
170
+ 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.
171
+
172
+ To make changes to other Active Themes that you will be specifying with the jonradio Multiple Themes plugin:
173
+
174
+ 1. Deactivate jonradio Multiple Themes
175
+ 1. Install the Theme Test Drive plugin found at http://wordpress.org/extend/plugins/theme-test-drive/
176
+ 1. Activate the Theme Test Drive plugin
177
+ 1. Go to Appearance-Theme Test Drive
178
+ 1. In the Usage section, select an alternate Theme you will be using with jonradio Multiple Themes
179
+ 1. Push the Enable Theme Drive button at the bottom
180
+ 1. Click on the Appearance menu item on the left sidebar of the WordPress Admin panel to refresh the submenu
181
+ 1. Click on the submenu item titled with your Elegant theme's name followed by "Theme Options"
182
+ 1. Elegant's epanel will now appear
183
+ 1. Make all the changes for this Theme, being sure to push the Save button
184
+ 1. If you have more than one alternate Theme with Options you wish to change, repeat Steps 4-10 for each alternate Theme
185
+ 1. Deactivate the Theme Test Drive plugin
186
+ 1. Activate jonradio Multiple Themes
187
+ 1. Changes to the Options for the Current Theme can now be made normally, just as you would without either plugin
188
+ 1. Both the alternate and Current Themes should now display all Theme options properly when selected through the jonradio Multiple Themes plugin
189
+
190
+ Thanks to Elegant for allowing us to test copies of any of their Themes provided by their customers.
191
+
192
+ = What happens when I change Permalinks? =
193
+
194
+ 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.
195
+
196
+ = I added a new entry but why doesn't it appear in the list of entries? =
197
+
198
+ If you add an entry that already exists, it merely replaces the previous entry.
199
+
200
+ = How can I change the Theme for an entry? =
201
+
202
+ Simply add the entry again, with the new Theme. It will replace the previous entry.
203
+
204
+ == Screenshots ==
205
+
206
+ 1. Plugin's Admin Page
207
+
208
+ == Changelog ==
209
+
210
+ = 4.11.1 =
211
+ * Correct foreach() error
212
+
213
+ = 4.11 =
214
+ * Complete Rewrite of Sticky logic, adding additional Settings, including Override
215
+
216
+ = 4.10.1 =
217
+ * Sticky: add a unique Query to URL so that Caching plugins will cache separate copies for each Theme used on a particular page
218
+
219
+ = 4.10 =
220
+ * Add a Sticky option (Advanced Setting) for URL Queries (keyword=value) that will select the same Theme for all subsequent pages viewed by the same Visitor
221
+ * Enhance performance by eliminating processing related to each Type of Setting when no Setting entries of that Type exist
222
+
223
+ = 4.9 =
224
+ * Add an Asterisk ("*") to match any Subdirectory at a given level of the File Hierarchy, as another form of the Prefix URL option
225
+ * Reorganize Settings page
226
+
227
+ = 4.8 =
228
+ * Delay intercept of get_options 'stylesheet' and 'template' until 'plugins_loaded' (NextGen Gallery conflict)
229
+ * Check for illegal characters in Keyword and Value of Query portion of URL in Settings fields
230
+
231
+ = 4.7.3 =
232
+ * Add support for dot in URL Queries (keyword or value) by replacing parse_str()
233
+ * Removed subfolder /includes/debug/
234
+
235
+ = 4.7.2 =
236
+ * Do not execute select-theme.php on Admin panels, to eliminate error message whenever any plugin is uninstalled
237
+ * Handle URL Query Keyword[]=Value
238
+ * Add Polylang to list of incompatible plugins
239
+
240
+ = 4.7.1 =
241
+ * Handle PHP without mbstring extension
242
+
243
+ = 4.7 =
244
+ * Add option to select a Theme based on Query Keyword and Value pair in URL
245
+ * Redesign how Query entries are stored
246
+ * Full testing completed with WordPress Version 3.8
247
+
248
+ = 4.6 =
249
+ * Add option to select a Theme based on Query Keyword in URL
250
+ * Rearrange Settings page
251
+
252
+ = 4.5.2 =
253
+ * Eliminate Fatal Error if php zip_open() function is not available, when readme.txt is out of date
254
+
255
+ = 4.5.1 =
256
+ * Remove %E2%80%8E suffix from URLs being entered
257
+
258
+ = 4.5 =
259
+ * Check with get_page_by_path() and get_posts( array( 'name' => $page_url ) ) if url_to_postid() fails to find URL input
260
+
261
+ = 4.4 =
262
+ * Rewrite Plugin's handling of its own version number to fix issues when new sites are activated in a Network and plugin is Network-Activated
263
+ * Prevent Fatal Error for Versions of WordPress before 3.4, and Deactivate Plugin instead, because plugin requires at least 3.4 to function
264
+ * Security: require "switch_themes" Capability rather than "manage_options" Capability to access plugin's Settings page
265
+
266
+ = 4.3 =
267
+ * Add SSL support so that visitors can view the WordPress site with https:// URLs and Site URL can be https://
268
+
269
+ = 4.2 =
270
+ * Add option to override WordPress Current Theme
271
+ * Security enhancements to eliminate direct execution of .php files
272
+
273
+ = 4.1.1 =
274
+ * Handle situations where readme.txt file in plugin's directory cannot be read or written
275
+
276
+ = 4.1 =
277
+ * Support for non-alphanumeric characters in URLs, e.g. - languages using characters not in the English alphabet
278
+ * Support for Live Search feature of KnowHow Theme
279
+ * Display errors, not settings, on plugin's Admin page for activated BuddyPress or Theme Test Drive plugins, or old versions of WordPress
280
+ * Add error checking/messages and diagnostic information to plugin's Admin page
281
+
282
+ = 4.0.2 =
283
+ * Prevent Warning and Notice by initializing global $wp
284
+
285
+ = 4.0.1 =
286
+ * Prevent Fatal Error by initializing global $wp_rewrite
287
+
288
+ = 4 =
289
+ * Discovered url_to_postid() function, to address situations where Slug differed from Permalink, such as Posts with Year/Month folders
290
+
291
+ = 3.3.1 =
292
+ * Fix White Screen of Death on a Page selected by plugin
293
+
294
+ = 3.3 =
295
+ * Support Child Themes and any other situation where stylesheet and template names are not the same
296
+
297
+ = 3.2 =
298
+ * Correct Problem with P2 Theme, and its logged on verification at wp-admin/admin-ajax.php?p2ajax=true&action=logged_in_out&_loggedin={nonce}
299
+ * Add "Settings Saved" message to Admin page
300
+ * Tested with WordPress Version 3.5 beta
301
+
302
+ = 3.1 =
303
+ * Add Support for Prefixes, where all URLs beginning with the specified characters ("Prefix") can be assigned to a specified Theme
304
+
305
+ = 3.0 =
306
+ * Add Support for Categories and Archives when no Permalinks exist (support already existed Categories and Archives with Permalinks)
307
+ * Resolve several minor bugs
308
+
309
+ = 2.9 =
310
+ * Rewrite much of the Settings page and Plugin Directory documentation
311
+ * Add Support for IIS which returns incorrect values in $_SERVER['REQUEST_URI']
312
+ * Make it easier to select the Theme for the Site Home by providing a new Settings field
313
+ * 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
314
+ * Add version upgrade detection to add, remove and update Settings fields
315
+ * Move Settings link on Plugins page from beginning to end of links
316
+
317
+ = 2.0 =
318
+ * Address pecularities of wp_make_link_relative() related to root-based WordPress sites using Permalinks
319
+
320
+ = 1.1 =
321
+ * Fix foreach failing on some systems, based on PHP warning level
322
+
323
+ = 1.0 =
324
+ * Make plugin conform to WordPress plugin repository standards.
325
+ * Beta testing completed.
326
+
327
+ == Upgrade Notice ==
328
+
329
+ = 4.11.1 =
330
+ Fix foreach() error
331
+
332
+ = 4.11 =
333
+ Complete rewrite of Sticky logic
334
+
335
+ = 4.10.1 =
336
+ Make Sticky work with Caching plugins
337
+
338
+ = 4.10 =
339
+ Performance improvements and add Sticky Queries
340
+
341
+ = 4.9 =
342
+ Allow Prefix URLs to match all subdirectories with an Asterisk ("*")
343
+
344
+ = 4.8 =
345
+ Compatibility with NextGen Gallery plugin
346
+
347
+ = 4.7.3 =
348
+ Allow dots in URL Queries
349
+
350
+ = 4.7.2 =
351
+ Avoid Error Message during Uninstall of other Plugins
352
+
353
+ = 4.7.1 =
354
+ Avoid mb_ function errors for PHP without mbstring extension
355
+
356
+ = 4.7 =
357
+ Select Theme by Query Keyword/Value pair in URL
358
+
359
+ = 4.6 =
360
+ Select Theme by Query Keyword in URL
361
+
362
+ = 4.5.2 =
363
+ Fix zip_open Fatal Error
364
+
365
+ = 4.5.1 =
366
+ Fix %E2%80%8E suffix problem on input URLs
367
+
368
+ = 4.5 =
369
+ Handle URL input for non-standard Pages and Posts
370
+
371
+ = 4.4 =
372
+ Fix errors when new Network site created or old WordPress version used, and correct Setting page Permissions to "switch_themes"
373
+
374
+ = 4.3 =
375
+ Add SSL support for sites with https:// URLs
376
+
377
+ = 4.2 =
378
+ Add "Select Theme for Everything" feature and improve security
379
+
380
+ = 4.1.1 =
381
+ Resolve issues with readme.txt permissions introduced in Version 4.1's compatibility checking
382
+
383
+ = 4.1 =
384
+ Support non-English alphabet in URLs and Live Search feature in KnowHow Theme
385
+
386
+ = 4.0.2 =
387
+ Fix "Warning: in_array() expects parameter 2 to be array, null given in domain.com/wp-includes/rewrite.php on line 364"
388
+
389
+ = 4.0.1 =
390
+ 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"
391
+
392
+ = 4 =
393
+ Fix Posts not working in some Permalink setups, most notably Year/Month
394
+
395
+ = 3.3.1 =
396
+ Fix White Screen of Death on a Page, Post or other element selected by plugin
397
+
398
+ = 3.3 =
399
+ Remove Restriction that Stylesheet Name must match Template Name, which it does not with Child Themes
400
+
401
+ = 3.2 =
402
+ Add Support for P2 Theme and provide "Settings Saved" message
403
+
404
+ = 3.1 =
405
+ Allow Prefix URLs to be used to specify where a Theme will be displayed
406
+
407
+ = 3.0 =
408
+ Improve support for Categories and Archives, and eliminate all known bugs.
409
+
410
+ = 2.9 =
411
+ Improve Settings fields, correct display of wrong Current Theme in Appearance-Themes Admin panel, and add IIS Support.
412
+
413
+ = 2.0 =
414
+ Selecting Individual Pages and Posts on a WordPress site installed in the root and using Permalinks now works correctly.
415
+
416
+ = 1.1 =
417
+ Eliminate possibility of foreach error message if PHP warning level is set at a high level
418
+
419
+ = 1.0 =
420
+ Beta version 0.9 had not been tested when installed from the WordPress Plugin Repository
uninstall.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Ensure call comes from WordPress, not a hacker or anyone else trying direct access.
3
+ if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
4
+ exit ();
5
+
6
+
7
+ /* Remove any tables, options, and such created by this Plugin */
8
+ if ( function_exists('is_multisite') && is_multisite() ) {
9
+ global $wpdb, $site_id;
10
+ $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = $site_id" );
11
+ foreach ($blogs as $blog_obj) {
12
+ delete_blog_option( $blog_obj->blog_id, 'jr_mt_settings' );
13
+ delete_blog_option( $blog_obj->blog_id, 'jr_mt_internal_settings' );
14
+ }
15
+ } else {
16
+ delete_option( 'jr_mt_settings' );
17
+ delete_option( 'jr_mt_internal_settings' );
18
+ }
19
+
20
+ ?>