Multiple Themes - Version 7.0.1

Version Description

  • Fix Query Matching when Value is an Integer in Query Settings
Download this release

Release Info

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

Version 7.0.1

includes/admin-functions.php ADDED
@@ -0,0 +1,303 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* Exit if .php file accessed directly
4
+ */
5
+ if ( !defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ function jr_mt_messages( $message, $action = 'count' ) {
10
+ global $jr_mt_messages;
11
+ switch ( $action ) {
12
+ case 'display':
13
+ if ( isset( $jr_mt_messages ) ) {
14
+ foreach ( $jr_mt_messages as $echo => $count ) {
15
+ echo '<li>' . $echo;
16
+ if ( $count > 1 ) {
17
+ echo ' ('. $count . ' times)';
18
+ }
19
+ echo '</li>';
20
+ }
21
+ unset( $jr_mt_messages );
22
+ }
23
+ if ( empty( $message ) ) {
24
+ break;
25
+ }
26
+ /* Purposely let it fall through to output message,
27
+ after stored messages are output.
28
+ */
29
+ case 'immediate':
30
+ echo '<li>' . $message . '</li>';
31
+ break;
32
+ case 'count':
33
+ if ( isset( $jr_mt_messages[ $message ] ) ) {
34
+ ++$jr_mt_messages[ $message ];
35
+ } else {
36
+ $jr_mt_messages[ $message ] = 1;
37
+ }
38
+ break;
39
+ }
40
+ }
41
+
42
+ function jr_mt_theme_entry( $type, $theme = '', $display1 = NULL, $display2 = NULL ) {
43
+ $three_dots = '&#133;';
44
+ $before = '<li>Delete <input type="checkbox" id="del_entry" name="jr_mt_settings[del_entry][]" value="';
45
+ $after = '" /> &nbsp; ';
46
+ /* Fortunately, wp_get_theme() creates an Object if $theme does not exist,
47
+ complete with a Name entry that matches the folder name.
48
+
49
+ TODO: flag the situation of a non-existent Theme (i.e. - was deleted after entry was created)
50
+ */
51
+ $theme_equals = 'Theme=' . wp_get_theme( $theme )->Name . '; ';
52
+ switch ( $type ) {
53
+ case 'Query':
54
+ echo $before
55
+ . 'query'
56
+ . '='
57
+ . $display1
58
+ . '='
59
+ . $display2
60
+ . $after
61
+ . $theme_equals;
62
+ if ( '*' !== $display2 ) {
63
+ $settings = get_option( 'jr_mt_settings' );
64
+ $sticky = isset( $settings['remember']['query'][ $display1 ][ $display2 ] );
65
+ $override = isset( $settings['override']['query'][ $display1 ][ $display2 ] );
66
+ if ( $sticky ) {
67
+ if ( $override ) {
68
+ echo 'Sticky/Override ';
69
+ } else {
70
+ echo 'Sticky ';
71
+ }
72
+ } else {
73
+ if ( $override ) {
74
+ echo 'Override ';
75
+ }
76
+ }
77
+ }
78
+ echo 'Query='
79
+ . '<code>'
80
+ . JR_MT_HOME_URL
81
+ . "/</code>$three_dots<code>/?"
82
+ . '<b><input type="text" readonly="readonly" disable="disabled" name="jr_mt_delkw" value="'
83
+ . $display1
84
+ . '" size="'
85
+ . jr_mt_strlen( $display1 )
86
+ . '" /></b>'
87
+ . '=';
88
+ if ( '*' === $display2 ) {
89
+ echo '</code>' . $three_dots;
90
+ } else {
91
+ echo '<b><input type="text" readonly="readonly" disable="disabled" name="jr_mt_delkwval" value="'
92
+ . $display2
93
+ . '" size="'
94
+ . jr_mt_strlen( $display2 )
95
+ . '" /></b></code>';
96
+ }
97
+ break;
98
+ case 'url':
99
+ case 'url_prefix':
100
+ case 'url_asterisk':
101
+ echo $before
102
+ . $type
103
+ . '='
104
+ . 'url'
105
+ . '='
106
+ . $display1
107
+ . $after
108
+ . $theme_equals
109
+ . $display2
110
+ . '=<code>' . $display1 . '</code>';
111
+ break;
112
+ case 'wordpress':
113
+ echo '<li><a href="'
114
+ . get_admin_url()
115
+ . 'themes.php" class="button-primary">Change</a> &nbsp; '
116
+ . 'Theme='
117
+ . wp_get_theme()->Name
118
+ . ', the Theme chosen as Active from Appearance-Themes in the WordPress Admin panels';
119
+ break;
120
+ default:
121
+ echo $before
122
+ . $type
123
+ . $after
124
+ . $theme_equals
125
+ . $display1;
126
+ if ( 'site_home' === $type ) {
127
+ echo ' (<code>' . JR_MT_HOME_URL . '</code>) setting';
128
+ } else {
129
+ echo ' setting (see Advanced Settings tab)';
130
+ }
131
+ break;
132
+ }
133
+ echo '</li>';
134
+ }
135
+
136
+ // $theme_name is the name of the Theme's folder within the Theme directory
137
+ function jr_mt_themes_field( $field_name, $theme_name, $setting, $excl_current_theme ) {
138
+ echo "<select id='$field_name' name='$setting" . "[$field_name]' size='1'>";
139
+ if ( empty( $theme_name ) ) {
140
+ $selected = 'selected="selected"';
141
+ } else {
142
+ $selected = '';
143
+ }
144
+ echo "<option value='' $selected></option>";
145
+ foreach ( jr_mt_all_themes() as $folder => $theme_obj ) {
146
+ if ( $excl_current_theme ) {
147
+ if ( ( jr_mt_current_theme( 'stylesheet' ) == $theme_obj['stylesheet'] ) && ( jr_mt_current_theme( 'template' ) == $theme_obj['template'] ) ) {
148
+ // Skip the Current Theme
149
+ continue;
150
+ }
151
+ }
152
+ if ( $theme_name === $folder ) {
153
+ $selected = 'selected="selected"';
154
+ } else {
155
+ $selected = '';
156
+ }
157
+ $name = $theme_obj->Name;
158
+ echo "<option value='$folder' $selected>$name</option>";
159
+ }
160
+ echo '</select>' . PHP_EOL;
161
+ }
162
+
163
+ /**
164
+ * Update available for Plugin?
165
+ *
166
+ * @return bool - TRUE if an update is available in the WordPress Repository,
167
+ * FALSE if no update is available or if the update_plugins transient is not available
168
+ * (which also results in an error message).
169
+ **/
170
+ function jr_mt_plugin_update_available() {
171
+ global $jr_mt_update_plugins;
172
+ if ( !isset( $jr_mt_update_plugins ) ) {
173
+ $transient = get_site_transient( 'update_plugins' );
174
+ if ( FALSE === $transient ) {
175
+ // Error
176
+ return FALSE;
177
+ } else {
178
+ $jr_mt_update_plugins = $transient;
179
+ }
180
+ }
181
+ if ( empty( $jr_mt_update_plugins->response ) ) {
182
+ return FALSE;
183
+ }
184
+ return array_key_exists( jr_mt_plugin_basename(), $jr_mt_update_plugins->response );
185
+ }
186
+
187
+ /**
188
+ * Prepare URL Query Value
189
+ *
190
+ * Sanitize and standardize a URL Query Value for storage in a database.
191
+ * Does not support ?keyword[]=value, i.e. - $value cannot be an Array.
192
+ *
193
+ * @param string $value URL Query Value to be sanitized and standardized; will fail if array
194
+ * @return string URL Query Value after being sanitized and standardized
195
+ */
196
+ function jr_mt_prep_query_value( $value ) {
197
+ return str_ireplace( '%e2%80%8e', '', jr_mt_strtolower( trim( $value ) ) );
198
+ }
199
+ function jr_mt_prep_query_keyword( $keyword ) {
200
+ return jr_mt_prep_query_value( $keyword );
201
+ }
202
+
203
+ /**
204
+ * Sanitize a URL from a Text Form field intended for database storage
205
+ */
206
+ function jr_mt_sanitize_url( $url ) {
207
+ /* Handle troublesome %E2%80%8E UTF Left-to-right Mark (LRM) suffix first.
208
+ */
209
+ if ( FALSE === stripos( $url, '%E2%80%8E' ) ) {
210
+ if ( FALSE === stripos( rawurlencode( $url ), '%E2%80%8E' ) ) {
211
+ $clean_url = $url;
212
+ } else {
213
+ $clean_url = rawurldecode( str_ireplace( '%E2%80%8E', '', rawurlencode( $url ) ) );
214
+ }
215
+ } else {
216
+ $clean_url = str_ireplace( '%E2%80%8E', '', $url );
217
+ }
218
+ $clean_url = rawurldecode( trim( $clean_url ) );
219
+
220
+ return $clean_url;
221
+ }
222
+
223
+ /**
224
+ * Make URL Relative to Site URL
225
+ *
226
+ */
227
+ function jr_mt_relative_url( $url, $site_url ) {
228
+ $url_path_array = parse_url( $url );
229
+ $url_path = $url_path_array['path'];
230
+ if ( !empty( $url_path_array['query'] ) ) {
231
+ $url_path .= '?' . $url_path_array['query'];
232
+ }
233
+ $site_url_path = parse_url( $site_url, PHP_URL_PATH );
234
+ return trim( jr_mt_substr( $url_path, jr_mt_strlen( $site_url_path ) ), '/\\' );
235
+ }
236
+
237
+ function jr_mt_missing_rel_url( $settings, $relative_to_url ) {
238
+ global $jr_mt_url_types;
239
+ foreach ( $jr_mt_url_types as $url_type ) {
240
+ if ( isset( $settings[ $url_type ] ) && is_array( $settings[ $url_type ] ) ) {
241
+ foreach ( $settings[ $url_type ] as $index => $url_array ) {
242
+ if ( !isset( $url_array['rel_url'] ) ) {
243
+ $settings[ $url_type ][ $index ]['rel_url'] = jr_mt_relative_url( $url_array['url'], $relative_to_url );
244
+ jr_mt_messages( 'Missing Relative URL added to URL setting' );
245
+ }
246
+ }
247
+ }
248
+ }
249
+ return $settings;
250
+ }
251
+
252
+ function jr_mt_rebuild_display_url( $settings, $old_site_url ) {
253
+ global $jr_mt_url_types;
254
+ foreach ( $jr_mt_url_types as $url_type ) {
255
+ if ( isset( $settings[ $url_type ] ) && is_array( $settings[ $url_type ] ) ) {
256
+ foreach ( $settings[ $url_type ] as $index => $url_array ) {
257
+ if ( !isset( $url_array['rel_url'] ) ) {
258
+ $settings[ $url_type ][ $index ]['rel_url'] = jr_mt_relative_url( $url_array['url'], $old_site_url );
259
+ }
260
+ $settings[ $url_type ][ $index ]['url'] = JR_MT_HOME_URL . '/' . $settings[ $url_type ][ $index ]['rel_url'];
261
+ }
262
+ } else {
263
+ $settings[ $url_type ] = array();
264
+ }
265
+ }
266
+ return $settings;
267
+ }
268
+
269
+ function jr_mt_rebuild_alias_home( $settings ) {
270
+ /* See if there is an Alias entry for the new Site URL.
271
+ If not, add one, and perhaps another with/without www.
272
+ */
273
+ $no_home = TRUE;
274
+ foreach ( $settings['aliases'] as $index => $alias ) {
275
+ if ( $settings['aliases'][ $index ]['home'] = jr_mt_same_url( $alias['prep'], JR_MT_HOME_URL ) ) {
276
+ $no_home = FALSE;
277
+ }
278
+ }
279
+ if ( $no_home ) {
280
+ $settings['aliases'] = array_merge( $settings['aliases'], jr_mt_init_aliases() );
281
+ }
282
+ return $settings;
283
+ }
284
+
285
+ function jr_mt_rebuild_prep( $settings ) {
286
+ /* Assumes that ['url'*] and ['aliases'] Settings have been checked,
287
+ so doesn't check if they exist and are array.
288
+ Be sure to do that if wrappering this function with get_ and update_option().
289
+ */
290
+ global $jr_mt_url_types;
291
+ foreach ( $jr_mt_url_types as $url_type ) {
292
+ foreach ( $settings[ $url_type ] as $url_key => $url_array ) {
293
+ $settings[ $url_type ][ $url_key ]['prep'] = array();
294
+ $rel_url = $url_array['rel_url'];
295
+ foreach ( $settings['aliases'] as $index => $alias ) {
296
+ $settings[ $url_type ][ $url_key ]['prep'][ $index ] = jr_mt_prep_url( $alias['url'] . '/' . $rel_url );
297
+ }
298
+ }
299
+ }
300
+ return $settings;
301
+ }
302
+
303
+ ?>
includes/admin-sections.php ADDED
@@ -0,0 +1,835 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* Exit if .php file accessed directly
4
+ */
5
+ if ( !defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ /**
10
+ * Define the settings
11
+ *
12
+ * Everything to be stored and/or can be set by the user
13
+ *
14
+ */
15
+ function jr_mt_admin_init() {
16
+ $settings = get_option( 'jr_mt_settings' );
17
+ foreach ( array( 'query', 'url', 'url_prefix', 'url_asterisk' ) as $key ) {
18
+ if ( !empty( $settings[ $key ] ) ) {
19
+ DEFINE( 'JR_MT_LIST_SETTINGS', TRUE );
20
+ break;
21
+ }
22
+ }
23
+ if ( defined( 'JR_MT_LIST_SETTINGS' ) ) {
24
+ add_settings_section(
25
+ 'jr_mt_delete_settings_section',
26
+ 'Current Theme Selection Entries',
27
+ 'jr_mt_delete_settings_expl',
28
+ 'jr_mt_settings_page'
29
+ );
30
+ add_settings_field(
31
+ 'del_entry',
32
+ 'Theme Selection Entries:',
33
+ 'jr_mt_echo_delete_entry',
34
+ 'jr_mt_settings_page',
35
+ 'jr_mt_delete_settings_section'
36
+ );
37
+ }
38
+ add_settings_section(
39
+ 'jr_mt_site_home_section',
40
+ '<input name="jr_mt_settings[tab1]" type="submit" value="Save All Changes" class="button-primary" /></h3><h3>Site Home',
41
+ 'jr_mt_site_home_expl',
42
+ 'jr_mt_settings_page'
43
+ );
44
+ add_settings_field(
45
+ 'site_home',
46
+ 'Select Theme for Site Home<br /><code>' . JR_MT_HOME_URL . '</code>',
47
+ 'jr_mt_echo_site_home',
48
+ 'jr_mt_settings_page',
49
+ 'jr_mt_site_home_section'
50
+ );
51
+ add_settings_section(
52
+ 'jr_mt_single_settings_section',
53
+ 'For An Individual Page, Post or other non-Admin page;<br />or a group of pages, specified by URL Prefix, optionally with Asterisk(s)',
54
+ 'jr_mt_single_settings_expl',
55
+ 'jr_mt_settings_page'
56
+ );
57
+ 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' );
58
+ add_settings_field( 'add_theme', 'Theme', 'jr_mt_echo_add_theme', 'jr_mt_settings_page', 'jr_mt_single_settings_section' );
59
+ 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' );
60
+ add_settings_section( 'jr_mt_querykw_section',
61
+ 'For A Query Keyword on any Page, Post or other non-Admin page',
62
+ 'jr_mt_querykw_expl',
63
+ 'jr_mt_settings_page'
64
+ );
65
+ add_settings_field( 'add_querykw_theme', 'Theme', 'jr_mt_echo_add_querykw_theme', 'jr_mt_settings_page', 'jr_mt_querykw_section' );
66
+ add_settings_field( 'add_querykw_keyword', 'Query Keyword', 'jr_mt_echo_add_querykw_keyword', 'jr_mt_settings_page', 'jr_mt_querykw_section' );
67
+ add_settings_section( 'jr_mt_query_section',
68
+ 'For A Query Keyword=Value on any Page, Post or other non-Admin page',
69
+ 'jr_mt_query_expl',
70
+ 'jr_mt_settings_page'
71
+ );
72
+ add_settings_field( 'add_query_theme', 'Theme', 'jr_mt_echo_add_query_theme', 'jr_mt_settings_page', 'jr_mt_query_section' );
73
+ add_settings_field( 'add_query_keyword', 'Query Keyword', 'jr_mt_echo_add_query_keyword', 'jr_mt_settings_page', 'jr_mt_query_section' );
74
+ add_settings_field( 'add_query_value', 'Query Value', 'jr_mt_echo_add_query_value', 'jr_mt_settings_page', 'jr_mt_query_section' );
75
+ add_settings_section( 'jr_mt_aliases_section',
76
+ '<input name="jr_mt_settings[tab1]" type="submit" value="Save All Changes" class="button-primary" /></h3></div><div id="jr-mt-settings2" style="display: none;"><h3>Site Aliases used in URLs to Access This WordPress Site',
77
+ 'jr_mt_aliases_expl',
78
+ 'jr_mt_settings_page'
79
+ );
80
+ /* There is always an entry for the Site URL ("Home").
81
+ */
82
+ if ( count( $settings['aliases'] ) > 1 ) {
83
+ add_settings_section(
84
+ 'jr_mt_delete_aliases_section',
85
+ 'Current Site Alias Entries',
86
+ 'jr_mt_delete_aliases_expl',
87
+ 'jr_mt_settings_page'
88
+ );
89
+ add_settings_field(
90
+ 'del_alias_entry',
91
+ 'Site Alias Entries:',
92
+ 'jr_mt_echo_delete_alias_entry',
93
+ 'jr_mt_settings_page',
94
+ 'jr_mt_delete_aliases_section'
95
+ );
96
+ }
97
+ add_settings_section(
98
+ 'jr_mt_create_alias_section',
99
+ 'Create New Site Alias Entry',
100
+ 'jr_mt_create_alias_expl',
101
+ 'jr_mt_settings_page'
102
+ );
103
+ add_settings_field(
104
+ 'add_alias',
105
+ 'Site Alias',
106
+ 'jr_mt_echo_add_alias',
107
+ 'jr_mt_settings_page',
108
+ 'jr_mt_create_alias_section'
109
+ );
110
+ add_settings_section( 'jr_mt_sticky_section',
111
+ '<input name="jr_mt_settings[tab2]" type="submit" value="Save All Changes" class="button-primary" /></h3></div><div id="jr-mt-settings3" style="display: none;"><h3>Advanced Settings</h3><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',
112
+ 'jr_mt_sticky_expl',
113
+ 'jr_mt_settings_page'
114
+ );
115
+ 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' );
116
+ add_settings_field( 'sticky_query', 'Keyword=Value Entries:', 'jr_mt_echo_sticky_query_entry', 'jr_mt_settings_page', 'jr_mt_sticky_section' );
117
+ add_settings_section( 'jr_mt_everything_section',
118
+ 'Theme for Everything',
119
+ 'jr_mt_everything_expl',
120
+ 'jr_mt_settings_page'
121
+ );
122
+ add_settings_field( 'current',
123
+ 'Select Theme for Everything, to Override WordPress Current Theme (<b>' . wp_get_theme()->Name . '</b>)',
124
+ 'jr_mt_echo_current',
125
+ 'jr_mt_settings_page',
126
+ 'jr_mt_everything_section'
127
+ );
128
+ add_settings_section( 'jr_mt_all_settings_section',
129
+ 'For All Pages and/or All Posts',
130
+ 'jr_mt_all_settings_expl',
131
+ 'jr_mt_settings_page'
132
+ );
133
+ $suffix = array(
134
+ 'Pages' => '<br />(Pages created with Add Page)',
135
+ 'Posts' => ''
136
+ );
137
+ foreach ( array( 'Pages', 'Posts' ) as $thing ) {
138
+ add_settings_field( 'all_' . jr_mt_strtolower( $thing ), "Select Theme for All $thing" . $suffix[$thing], 'jr_mt_echo_all_things', 'jr_mt_settings_page', 'jr_mt_all_settings_section',
139
+ array( 'thing' => $thing ) );
140
+ }
141
+ }
142
+
143
+ /**
144
+ * Section text for Section1
145
+ *
146
+ * Display an explanation of this Section
147
+ *
148
+ */
149
+ function jr_mt_delete_settings_expl() {
150
+ if ( defined( 'JR_MT_LIST_SETTINGS' ) ) {
151
+ ?>
152
+ <p>
153
+ All Theme Selection entries are displayed below,
154
+ in the exact order in which they will be processed.
155
+ For example,
156
+ if a match is made with the first Entry,
157
+ the first Entry's Theme will be used,
158
+ no matter what Theme the Second and subsequent Entries specify.
159
+ </p>
160
+ <p>
161
+ You can delete any of these entries by filling in the check box beside the entry
162
+ and clicking any of the <b>Save All Changes</b> buttons.
163
+ To change the Theme for an entry,
164
+ you will need to delete the entry
165
+ and add the same entry with a different Theme in the relevant section
166
+ on this or the Advanced Settings tab.
167
+ </p>
168
+ <p>
169
+ To add or remove (or to learn about) the Sticky or Override setting for a Query,
170
+ see the Advanced Settings tab.
171
+ </p>
172
+ <?php
173
+ }
174
+ }
175
+
176
+ function jr_mt_echo_delete_entry() {
177
+ echo 'In order of Selection:<ol>';
178
+ $settings = get_option( 'jr_mt_settings' );
179
+ /* Display any Override entries first,
180
+ because they have the highest priority.
181
+ */
182
+ foreach ( $settings['override']['query'] as $override_keyword => $override_value_array ) {
183
+ foreach ( $override_value_array as $override_value => $bool ) {
184
+ jr_mt_theme_entry(
185
+ 'Query',
186
+ wp_get_theme( $settings['query'][ $override_keyword ][ $override_value ] )->Name,
187
+ $override_keyword,
188
+ $override_value
189
+ );
190
+ }
191
+ }
192
+ /* Display Non-Overrides:
193
+ first, keyword=value query in URL with matching setting entry.
194
+ */
195
+ foreach ( $settings['query'] as $keyword => $value_array ) {
196
+ foreach ( $value_array as $value => $theme ) {
197
+ /* Wildcard Keyword=* entries come later
198
+ */
199
+ if ( '*' !== $value ) {
200
+ if ( !isset( $settings['override']['query'][ $keyword ][ $value ] ) ) {
201
+ jr_mt_theme_entry(
202
+ 'Query',
203
+ wp_get_theme( $theme )->Name,
204
+ $keyword,
205
+ $value
206
+ );
207
+ }
208
+ }
209
+ }
210
+ }
211
+ /* Display Non-Overrides:
212
+ second, wildcard keyword=* query in URL with matching setting entry.
213
+ */
214
+ foreach ( $settings['query'] as $keyword => $value_array ) {
215
+ foreach ( $value_array as $value => $theme ) {
216
+ /* Wildcard Keyword=* entries
217
+ Overrides are not allowed, so no need to check.
218
+ */
219
+ if ( '*' === $value ) {
220
+ jr_mt_theme_entry(
221
+ 'Query',
222
+ wp_get_theme( $theme )->Name,
223
+ $keyword,
224
+ '*'
225
+ );
226
+ }
227
+ }
228
+ }
229
+ /* Display URL entries:
230
+ first, exact match URL entries;
231
+ second, prefix URL entries;
232
+ then, prefix URL entries with asterisk wildcards.
233
+ */
234
+ foreach ( array(
235
+ 'url' => 'URL',
236
+ 'url_prefix' => 'URL Prefix',
237
+ 'url_asterisk' => 'URL Prefix*'
238
+ ) as $key => $description ) {
239
+ foreach ( $settings[ $key ] as $settings_array ) {
240
+ jr_mt_theme_entry(
241
+ $key,
242
+ wp_get_theme( $settings_array['theme'] )->Name,
243
+ $settings_array['url'],
244
+ $description
245
+ );
246
+ }
247
+ }
248
+ /* Home Entry, then All Posts and Pages, and Everything Else
249
+ */
250
+ foreach ( array(
251
+ 'site_home' => 'Home',
252
+ 'all_posts' => 'All Posts',
253
+ 'all_pages' => 'All Pages',
254
+ 'current' => 'Everything Else'
255
+ ) as $key => $description ) {
256
+ if ( '' !== $settings[ $key ] ) {
257
+ jr_mt_theme_entry(
258
+ $key,
259
+ wp_get_theme( $settings[ $key ] )->Name,
260
+ $description
261
+ );
262
+ }
263
+ }
264
+ if ( '' === $settings['current'] ) {
265
+ jr_mt_theme_entry(
266
+ 'wordpress'
267
+ );
268
+ }
269
+ echo '</ol>';
270
+ }
271
+
272
+ /**
273
+ * Section text for Section2
274
+ *
275
+ * Display an explanation of this Section
276
+ *
277
+ */
278
+ function jr_mt_site_home_expl() {
279
+ ?>
280
+ <p>
281
+ In this section, you can select a different Theme for Site Home.
282
+ To remove a previously selected Theme, select the blank entry from the drop-down list.
283
+ </p>
284
+ <p>
285
+ In the <i>next</i> section, you will be able to select a Theme, including the Current Theme, for individual Pages, Posts or
286
+ any other non-Admin pages that have their own Permalink; for example, specific Archive or Category pages.
287
+ Or groups of Pages, Posts or any other non-Admin pages that share the same URL Prefix.
288
+ </p>
289
+ <p>
290
+ There is also a Query Keyword section
291
+ farther down this Settings page
292
+ that allows
293
+ you to select a Theme to use whenever a specified
294
+ Query Keyword (<code>?keyword=value</code> or <code>&keyword=value</code>)
295
+ appears in the URL of any Page, Post or other non-Admin page.
296
+ Query entries will even override the Site Home entry,
297
+ if the Query Keyword follows the Site Home URL.
298
+ </p>
299
+ <?php
300
+ }
301
+
302
+ function jr_mt_echo_site_home() {
303
+ $settings = get_option( 'jr_mt_settings' );
304
+ jr_mt_themes_field( 'site_home', $settings['site_home'], 'jr_mt_settings', FALSE );
305
+ }
306
+
307
+ /**
308
+ * Section text for Section3
309
+ *
310
+ * Display an explanation of this Section
311
+ *
312
+ */
313
+ function jr_mt_single_settings_expl() {
314
+ ?>
315
+ <p>
316
+ Select a Theme for an individual Page, Post or
317
+ any other non-Admin page that has its own Permalink; for example, a specific Archive or Category page.
318
+ Or for a group of pages which have URLs that all begin with the same characters ("Prefix"),
319
+ optionally specifying an Asterisk ("*") to match all subdirectories at specific levels.
320
+ </p>
321
+ <p>
322
+ Then cut and paste the URL of the desired Page, Post, Prefix or other non-Admin page.
323
+ And click any of the <b>Save All Changes</b> buttons to add the entry.
324
+ </p>
325
+ There are three types of Entries that you can specify here:
326
+ <ol>
327
+ <li>
328
+ <b>URL</b> - if Visitor URL matches this URL, use this Theme
329
+ </li>
330
+ <li>
331
+ <b>URL Prefix</b> - any Visitor URL that begins with this URL Prefix will use this Theme
332
+ </li>
333
+ <li>
334
+ <b>URL Prefix with Asterisk(s)</b> - URL Prefix that matches any subdirectory where Asterisk ("*") is specified
335
+ </li>
336
+ </ol>
337
+ For the third type, an Asterisk can only be specified to match the entire subdirectory name, not parts of the name:
338
+ <blockquote>
339
+ For example, using a Permalink structure that uses dates,
340
+ where a typical Post might be at URL
341
+ <code>http://example.com/wp/2014/04/13/daily-thoughts/</code>,
342
+ a URL Prefix with Asterisk entry of
343
+ <code>http://example.com/wp/*/04/*/d</code>
344
+ would match all April Posts with Titles that begin with the letter "d", no matter what year they were posted.
345
+ </blockquote>
346
+ </p>
347
+ </p>
348
+ Beginning with Version 5.0, <code>keyword=value</code> Queries are now supported in all URLs
349
+ (on this Settings tab;
350
+ Site Aliases may not include Queries).
351
+ </p>
352
+ <?php
353
+ }
354
+
355
+ function jr_mt_echo_add_is_prefix() {
356
+ echo '<input type="radio" id="add_is_prefix" name="jr_mt_settings[add_is_prefix]" value="false" checked="checked" /> URL';
357
+ ?>
358
+ <br/>
359
+ <input type="radio" id="add_is_prefix" name="jr_mt_settings[add_is_prefix]" value="prefix" /> URL Prefix<br/>
360
+ <input type="radio" id="add_is_prefix" name="jr_mt_settings[add_is_prefix]" value="*" /> URL Prefix with Asterisk ("*")
361
+ <?php
362
+ }
363
+
364
+ function jr_mt_echo_add_theme() {
365
+ jr_mt_themes_field( 'add_theme', '', 'jr_mt_settings', FALSE );
366
+ }
367
+
368
+ function jr_mt_echo_add_path_id() {
369
+ ?>
370
+ <input id="add_path_id" name="jr_mt_settings[add_path_id]" type="text" size="75" maxlength="256" value="" />
371
+ <br />
372
+ &nbsp;
373
+ (cut and paste URL here of Page, Post, Prefix or other)
374
+ <br />
375
+ &nbsp;
376
+ URL must begin with
377
+ the current
378
+ <a href="options-general.php">Site Address (URL)</a>:
379
+ <?php
380
+ echo '<code>' . JR_MT_HOME_URL . '/</code>.';
381
+ }
382
+
383
+ /**
384
+ * Section text for Section4
385
+ *
386
+ * Display an explanation of this Section
387
+ *
388
+ */
389
+ function jr_mt_querykw_expl() {
390
+ ?>
391
+ <p>
392
+ Select a Theme to use
393
+ whenever the specified Query Keyword (<code>?keyword=</code> or <code>&keyword=</code>)
394
+ is found in the URL of
395
+ any Page, Post or
396
+ any other non-Admin page.
397
+ And click any of the <b>Save All Changes</b> buttons to add the entry.
398
+ </p>
399
+ <p>
400
+ <b>
401
+ Note
402
+ </b>
403
+ that Query Keyword takes precedence over all other types of Theme selection entries.
404
+ For example,
405
+ <?php
406
+ echo '<code>' . JR_MT_HOME_URL . '?firstname=dorothy</code>'
407
+ . ' would use the Theme specified for the <code>firstname</code> keyword, not the Theme specified for Site Home.'
408
+ . ' Query matching is case-insensitive, so all Keywords entered are stored in lower-case.</p>';
409
+ }
410
+ function jr_mt_echo_add_querykw_theme() {
411
+ jr_mt_themes_field( 'add_querykw_theme', '', 'jr_mt_settings', FALSE );
412
+ }
413
+ function jr_mt_echo_add_querykw_keyword() {
414
+ $three_dots = '&#133;';
415
+ echo '<code>'
416
+ . JR_MT_HOME_URL
417
+ . "/</code>$three_dots<code>/?"
418
+ . '<input id="add_querykw_keyword" name="jr_mt_settings[add_querykw_keyword]" type="text" size="20" maxlength="64" value="" />=</code>'
419
+ . $three_dots;
420
+ }
421
+
422
+ /**
423
+ * Section text for Section5
424
+ *
425
+ * Display an explanation of this Section
426
+ *
427
+ */
428
+ function jr_mt_query_expl() {
429
+ ?>
430
+ <p>
431
+ Select a Theme to use
432
+ whenever the specified Query Keyword <b>and</b> Value (<code>?keyword=value</code> or <code>&keyword=value</code>)
433
+ are found in the URL of
434
+ any Page, Post or
435
+ any other non-Admin page.
436
+ And click any of the <b>Save All Changes</b> buttons to add the entry.
437
+ </p>
438
+ <p>
439
+ <b>
440
+ Note
441
+ </b>
442
+ that Query Keyword=Value takes precedence over all other Theme selection entries,
443
+ including a Query Keyword entry for the same Keyword.
444
+ For example,
445
+ <?php
446
+ echo '<code>' . JR_MT_HOME_URL . '?firstname=dorothy</code>'
447
+ . ' would use the Theme specified for the <code>firstname=dorothy</code> keyword=value pair,'
448
+ . ' not the Theme specified for Site Home nor even the Theme specified for the Keyword <code>firstname</code>.'
449
+ . ' Query matching is case-insensitive, so all Keywords and Values entered are stored in lower-case.</p>';
450
+ }
451
+ function jr_mt_echo_add_query_theme() {
452
+ jr_mt_themes_field( 'add_query_theme', '', 'jr_mt_settings', FALSE );
453
+ }
454
+ function jr_mt_echo_add_query_keyword() {
455
+ $three_dots = '&#133;';
456
+ echo '<code>'
457
+ . JR_MT_HOME_URL
458
+ . "/</code>$three_dots<code>/?"
459
+ . '<input id="add_query_keyword" name="jr_mt_settings[add_query_keyword]" type="text" size="20" maxlength="64" value="" /></code>';
460
+ }
461
+ function jr_mt_echo_add_query_value() {
462
+ echo '<code>'
463
+ . '='
464
+ . '<input id="add_query_value" name="jr_mt_settings[add_query_value]" type="text" size="20" maxlength="64" value="" /></code>';
465
+ }
466
+
467
+ function jr_mt_aliases_expl() {
468
+ ?>
469
+ <p>
470
+ Define any
471
+ <b>
472
+ Site Aliases
473
+ </b>
474
+ that may be used to access your WordPress website.
475
+ </p>
476
+ <p>
477
+ This plugin uses the value of
478
+ <b>
479
+ Site Address (URL)
480
+ </b>
481
+ defined on the
482
+ <a href="options-general.php">
483
+ General Settings</a>
484
+ Admin panel
485
+ to match URLs against the Theme Selection settings.
486
+ By default, when the plugin is first installed,
487
+ or the value of Site Address changed,
488
+ a
489
+ <i>
490
+ www Alias Entry
491
+ </i>
492
+ is automatically defined
493
+ to handle the most common Alias used on WordPress sites:
494
+ by adding or removing the "www." prefix of the Domain Name.
495
+ </p>
496
+ <p>
497
+ If your WordPress website is accessed by
498
+ anything other than the Site Address or Site Aliases defined below,
499
+ this Plugin will always use the WordPress Active Theme defined on the
500
+ <a href="themes.php">
501
+ Appearance-Themes</a>
502
+ Admin panel.
503
+ </p>
504
+ <p>
505
+ Although by no means exhaustive,
506
+ this list can help you remember where you might have defined Aliases that need to be defined below.
507
+ </p>
508
+ <ul class="jrmtpoints">
509
+ <?php
510
+ if ( is_multisite() ) {
511
+ echo '<li><b>Mapped Domain</b>. Plugins such as <a href="https://wordpress.org/plugins/wordpress-mu-domain-mapping/">WordPress MU Domain Mapping</a> allow each Site in a WordPress Network to have its own Domain Name.</li>';
512
+ }
513
+ ?>
514
+ <li>
515
+ <b>IP Address</b>.
516
+ Most sites can be accessed by an IP address,
517
+ either the IPv4 format of four numbers separated by dots (168.1.0.1)
518
+ or the newer IPv6 format of several hexadecimal numbers separated by colons (2001:0DB8:AC10:FE01::).
519
+ </li>
520
+ <li>
521
+ <b>Parked Domain</b>.
522
+ example.com might have example.club as a Alias defined as a Parked Domain to your web host.
523
+ </li>
524
+ <li>
525
+ <b>ServerAlias</b> or equivalent.
526
+ Apache allows one or more Domain or Subdomain aliases to be defined with the SeverAlias directive;
527
+ non-Apache equivalents offer similar capabilities.
528
+ </li>
529
+ <li>
530
+ <b>Redirection</b>.
531
+ Most domain name registration and web hosting providers also offer a Redirection service.
532
+ Optionally, Redirection can be Masked (or not) to keep the redirected URL in the browser's address bar.
533
+ </li>
534
+ <li>
535
+ <b>.htaccess RewriteRule</b> or equivalent.
536
+ Each directory can contain a hidden file named
537
+ <code>.htaccess</code>.
538
+ These files may include RewriteRule statements that modify the URL
539
+ to change the URL of a site
540
+ as it appears in the Site Visitor's web browser address bar
541
+ from,
542
+ for example,
543
+ <code>http://example.com/wordpress</code>
544
+ to
545
+ <code>http://example.com</code>.
546
+ </li>
547
+ </ul>
548
+ <?php
549
+ }
550
+
551
+ function jr_mt_delete_aliases_expl() {
552
+ ?>
553
+ <p>
554
+ Here you can see,
555
+ and are able to delete,
556
+ any Site Aliases that have been created in the
557
+ Create New Sites Alias Entry section below,
558
+ or were created by default by this Plugin
559
+ for the current Site Address (URL) defined on the
560
+ <a href="options-general.php">General Settings</a>
561
+ Admin panel:
562
+ <?php
563
+ echo '<code>' . JR_MT_HOME_URL. '</code></p>';
564
+ }
565
+
566
+ function jr_mt_echo_delete_alias_entry() {
567
+ $settings = get_option( 'jr_mt_settings' );
568
+ echo '<p>In addition to the <a href="options-general.php">Site Address (URL)</a> <code>'
569
+ . JR_MT_HOME_URL
570
+ . '</code>, this Plugin will also control Themes for the following Site Aliases:</p><ol>';
571
+ foreach ( $settings['aliases'] as $array_index => $alias ) {
572
+ /* Do not allow the Site URL ("Home") alias to be deleted.
573
+ In fact, do not even display it.
574
+ */
575
+ if ( !$alias['home'] ) {
576
+ echo '<li>Delete <input type="checkbox" id="del_alias_entry" name="jr_mt_settings[del_alias_entry][]" value="'
577
+ . $array_index
578
+ . '"> <code>'
579
+ . $alias['url']
580
+ . '</code></li>';
581
+ }
582
+ }
583
+ echo '</ol>';
584
+ }
585
+
586
+ function jr_mt_create_alias_expl() {
587
+ echo '<p>To add another Site Alias, cut and paste its URL below.</p>';
588
+ }
589
+
590
+ function jr_mt_echo_add_alias() {
591
+ ?>
592
+ <input id="add_alias" name="jr_mt_settings[add_alias]" type="text" size="75" maxlength="256" value="" />
593
+ <br />
594
+ &nbsp;
595
+ (cut and paste URL of a new Site Alias here)
596
+ <br />
597
+ &nbsp;
598
+ URL must begin with
599
+ <code>http://</code>
600
+ or
601
+ <code>https://</code>
602
+ <?php
603
+ }
604
+
605
+ /**
606
+ * Section text for Section6
607
+ *
608
+ * Display an explanation of this Section
609
+ *
610
+ */
611
+ function jr_mt_sticky_expl() {
612
+ /* "Membership System V2" is a paid plugin that blocks (our sticky) Cookies
613
+ */
614
+ global $jr_mt_plugins_cache;
615
+ foreach ( $jr_mt_plugins_cache as $rel_path => $plugin_data ) {
616
+ if ( 0 === strncasecmp( 'memberium', $rel_path, 9 ) ) {
617
+ echo '<b><u>IMPORTANT</u></b>: The Sticky feature of this plugin does not work with the <b>Membership System V2</b> plugin, which blocks the required Cookies. At least one plugin from memberium.com appears to have been installed: '
618
+ . $plugin_data['Name'];
619
+ break;
620
+ }
621
+ }
622
+ ?>
623
+ <p>
624
+ If one of the
625
+ <b>
626
+ Keyword=Value Entries
627
+ </b>
628
+ shown below
629
+ (if any)
630
+ is present in the URL of a WordPress non-Admin webpage on the current WordPress Site
631
+ and that Entry is:
632
+ <ol>
633
+ <li>
634
+ <b>Sticky</b>,
635
+ then the specified Theme will continue to be displayed for subsequent
636
+ WordPress non-Admin webpages
637
+ viewed by the same Visitor
638
+ until an Override entry is encountered by the same Visitor.
639
+ </li>
640
+ <li>
641
+ <b>Override</b>,
642
+ then the specified Theme will be displayed,
643
+ effectively ending any previous Sticky Theme that was being displayed
644
+ for the same Visitor.
645
+ </li>
646
+ </ol>
647
+ <b>
648
+ Note
649
+ </b>
650
+ that,
651
+ as explained in the
652
+ Query Keyword=Value
653
+ section on the Settings tab,
654
+ Query Keyword=Value already takes precedence over all other Theme selection entries,
655
+ even without the Override checkbox selected.
656
+ Override is only intended to cancel a Sticky entry
657
+ and display the specified Theme on the current WordPress non-Admin webpage.
658
+ </p>
659
+ <p>
660
+ Implementation Notes:
661
+ <ol>
662
+ <li>
663
+ The term "Same Visitor",
664
+ used above,
665
+ refers to a single combination of
666
+ computer, browser and possibly computer user name,
667
+ if the visitor's computer has multiple accounts or user names.
668
+ A computer could be a smartphone, tablet, laptop, desktop or other Internet access device used by the Visitor.
669
+ </li>
670
+ <li>
671
+ When Sticky is active for a given Visitor,
672
+ the associated Query Keyword=Value is added to the
673
+ URL of links displayed on the current WordPress non-Admin webpage.
674
+ With the following exceptions:
675
+ <ul>
676
+ <li>
677
+ a)
678
+ Only links pointing to non-Admin webpages of the current WordPress Site are altered.
679
+ </li>
680
+ <li>
681
+ b)
682
+ The
683
+ "When to add Sticky Query to a URL"
684
+ setting below also controls when a Sticky Keyword=Value is added to a URL.
685
+ </li>
686
+ </ul>
687
+ <li>
688
+ Cookies are used for Sticky entries. If the visitor's browser refuses Cookies,
689
+ or another Plugin blocks cookies,
690
+ this setting will not work and no error messages will be displayed.
691
+ </li>
692
+ </ol>
693
+ </p>
694
+ <p>
695
+ <b>
696
+ Important:
697
+ </b>
698
+ the Sticky feature cannot be made to work in all WordPress environments.
699
+ Timing, Cookie and other issues may be caused by other plugins, themes and visitor browser settings,
700
+ so please test carefully and realize that the solution to some problems will involve a choice between not using the Sticky feature and not using a particular plugin or theme.
701
+ </p>
702
+ <?php
703
+ }
704
+
705
+ function jr_mt_echo_query_present() {
706
+ $settings = get_option( 'jr_mt_settings' );
707
+ /*
708
+ FALSE if Setting "Append if no question mark ("?") found in URL", or
709
+ TRUE if Setting "Append if no Override keyword=value found in URL"
710
+ */
711
+ echo '<input type="radio" id="query_present" name="jr_mt_settings[query_present]" value="false" ';
712
+ checked( $settings['query_present'], FALSE );
713
+ echo ' /> Append if no question mark ("?") found in URL<br/><input type="radio" id="query_present" name="jr_mt_settings[query_present]" value="true" ';
714
+ checked( $settings['query_present'] );
715
+ echo ' /> Append if no Override <code>keyword=value</code> found in URL';
716
+ }
717
+
718
+ function jr_mt_echo_sticky_query_entry() {
719
+ global $jr_mt_kwvalsep;
720
+ $settings = get_option( 'jr_mt_settings' );
721
+ $three_dots = '&#133;';
722
+ $first = TRUE;
723
+ if ( !empty( $settings['query'] ) ) {
724
+ foreach ( $settings['query'] as $keyword => $value_array ) {
725
+ foreach ( $value_array as $value => $theme ) {
726
+ if ( '*' !== $value ) {
727
+ if ( $first ) {
728
+ $first = FALSE;
729
+ } else {
730
+ echo '<br />';
731
+ }
732
+ echo 'Sticky <input type="checkbox" id="sticky_query_entry" name="jr_mt_settings[sticky_query_entry][]" value="'
733
+ . "$keyword$jr_mt_kwvalsep$value"
734
+ . '" ';
735
+ checked( isset( $settings['remember']['query'][$keyword][$value] ) );
736
+ echo ' /> &nbsp; Override <input type="checkbox" id="override_query_entry" name="jr_mt_settings[override_query_entry][]" value="'
737
+ . "$keyword$jr_mt_kwvalsep$value"
738
+ . '" ';
739
+ checked( isset( $settings['override']['query'][$keyword][$value] ) );
740
+ echo ' /> &nbsp; Theme='
741
+ . wp_get_theme( $theme )->Name . '; '
742
+ . 'Query='
743
+ . '<code>'
744
+ . JR_MT_HOME_URL
745
+ . "/</code>$three_dots<code>/?"
746
+ . "<b><input type='text' readonly='readonly' disable='disabled' name='jr_mt_stkw' value='$keyword' size='"
747
+ . jr_mt_strlen( $keyword )
748
+ . "' /></b>"
749
+ . '='
750
+ . "<b><input type='text' readonly='readonly' disable='disabled' name='jr_mt_stkwval' value='$value' size='"
751
+ . jr_mt_strlen( $value )
752
+ . "' /></b></code>";
753
+ }
754
+ }
755
+ }
756
+ }
757
+ if ( $first ) {
758
+ echo 'None';
759
+ }
760
+ }
761
+
762
+ function jr_mt_everything_expl() {
763
+ ?>
764
+ <p>
765
+ <b>Theme for Everything</b>
766
+ simplifies the use of a Theme with Theme Settings that you need to change frequently,
767
+ when the Theme is only going to be used on one or more Pages or Posts.
768
+ The Theme can be set as the WordPress Active Theme through the Appearance-Themes admin panel,
769
+ and set for specific Pages or Posts using this plugin's settings (on Settings tab),
770
+ with another Theme specified below as the plugin's default theme ("Theme for Everything").
771
+ </p>
772
+ <?php
773
+ }
774
+
775
+ function jr_mt_echo_current() {
776
+ $settings = get_option( 'jr_mt_settings' );
777
+ jr_mt_themes_field( 'current', $settings['current'], 'jr_mt_settings', TRUE );
778
+ echo '<br /> &nbsp; (select blank entry for default: WordPress Active Theme defined in Appearance-Themes, currently <b>' . wp_get_theme()->Name . '</b>)';
779
+ }
780
+
781
+ function jr_mt_all_settings_expl() {
782
+ ?>
783
+ <p>
784
+ These are
785
+ <b>
786
+ Advanced Setting
787
+ </b>
788
+ because they may not work with every other plugin, theme or permalinks setting.
789
+ This plugin is only able to determine whether what is about to be displayed at the current URL
790
+ is a Page or Post
791
+ after all other Plugins have been loaded;
792
+ the one exception to this is the Default setting for Permalinks,
793
+ when <code>?p=</code> and <code>?page_id=</code> are used.
794
+ </p>
795
+ <p>
796
+ Some other plugins and themes request the name of the current Theme
797
+ <i>
798
+ too early,
799
+ </i>
800
+ while they are being loaded,
801
+ which is before this plugin is able to determine if it is on a Page or Post.
802
+ For this reason,
803
+ using either of these settings may not work properly for all other plugins and themes.
804
+ As a result,
805
+ if you choose to use either or both of these two settings,
806
+ careful testing is advised immediately
807
+ <u>and</u>
808
+ whenever you change the Permalink setting, activate a plugin or start using a different theme.
809
+ </p>
810
+ <p>
811
+ In this section, you can select a different Theme for All Pages and/or All Posts.
812
+ To remove a previously selected Theme, select the blank entry from the drop-down list.
813
+ </p>
814
+ <p>
815
+ On the Settings tab, you were able to select a Theme, including WordPress' Active Theme, to override any choice you make here, for individual Pages, Posts or
816
+ any other non-Admin pages that have their own Permalink; for example, specific Archive or Category pages.
817
+ Or groups of Pages, Posts or any other non-Admin pages that share the same URL Prefix.
818
+ </p>
819
+ <p>
820
+ The Settings tab also has a Query Keyword section
821
+ that allows
822
+ you to select a Theme to use whenever a specified
823
+ Query Keyword (<code>?keyword=value</code> or <code>&keyword=value</code>)
824
+ appears in the URL of any Page, Post or other non-Admin page.
825
+ </p>
826
+ <?php
827
+ }
828
+
829
+ function jr_mt_echo_all_things( $thing ) {
830
+ $settings = get_option( 'jr_mt_settings' );
831
+ $field = 'all_' . jr_mt_strtolower( $thing['thing'] );
832
+ jr_mt_themes_field( $field, $settings[$field], 'jr_mt_settings', TRUE );
833
+ }
834
+
835
+ ?>
includes/admin-validate.php ADDED
@@ -0,0 +1,452 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* Exit if .php file accessed directly
4
+ */
5
+ if ( !defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ function jr_mt_validate_settings( $input ) {
10
+ global $jr_mt_kwvalsep;
11
+ $valid = array();
12
+
13
+ $prefix_types = array(
14
+ 'false' => 'url',
15
+ 'prefix' => 'url_prefix',
16
+ '*' => 'url_asterisk'
17
+ );
18
+
19
+ $settings = get_option( 'jr_mt_settings' );
20
+ $query = $settings['query'];
21
+ $aliases = $settings['aliases'];
22
+
23
+ /* Begin by deciding which Tab to display on the plugin's Settings page
24
+
25
+ Default value should never be used if plugin is written correctly.
26
+ */
27
+ $tab = 1;
28
+ for ( $i = 1; $i <= 6; $i++ ) {
29
+ if ( isset( $input[ "tab$i" ] ) ) {
30
+ $tab = $i;
31
+ break;
32
+ }
33
+ }
34
+ set_transient( 'jr_mt_' . get_current_user_id() . '_tab', $tab, 5 );
35
+
36
+ if ( isset( $input['permalink'] ) ) {
37
+ $internal_settings = get_option( 'jr_mt_internal_settings' );
38
+ $internal_settings['permalink'] = get_option( 'permalink_structure' );
39
+ update_option( 'jr_mt_internal_settings', $internal_setting );
40
+ }
41
+
42
+ foreach ( array( 'all_pages', 'all_posts', 'site_home', 'current' ) as $thing ) {
43
+ $valid[$thing] = $input[$thing];
44
+ }
45
+
46
+ foreach ( $prefix_types as $key => $thing ) {
47
+ $valid[$thing] = $settings[$thing];
48
+ }
49
+ $remember = array( 'query' => array() );
50
+ if ( isset( $input['sticky_query_entry'] ) ) {
51
+ foreach ( $input['sticky_query_entry'] as $query_entry ) {
52
+ list( $keyword, $value ) = explode( $jr_mt_kwvalsep, $query_entry );
53
+ /* Data Sanitization not required as
54
+ Keyword and Value are not entered by a human,
55
+ but extracted from previously-generated HTML.
56
+ */
57
+ $remember['query'][$keyword][$value] = TRUE;
58
+ }
59
+ }
60
+
61
+ $override = array( 'query' => array() );
62
+ if ( isset( $input['override_query_entry'] ) ) {
63
+ foreach ( $input['override_query_entry'] as $query_entry ) {
64
+ list( $keyword, $value ) = explode( $jr_mt_kwvalsep, $query_entry );
65
+ /* Data Sanitization not required as
66
+ Keyword and Value are not entered by a human,
67
+ but extracted from previously-generated HTML.
68
+ */
69
+ $override['query'][$keyword][$value] = TRUE;
70
+ }
71
+ }
72
+
73
+ if ( isset ( $input['del_entry'] ) ) {
74
+ foreach ( $input['del_entry'] as $del_entry ) {
75
+ $del_array = explode( '=', $del_entry, 3 );
76
+ if ( 'query' === $del_array[0] ) {
77
+ unset( $query[ $del_array[1] ][ $del_array[2] ] );
78
+ if ( empty( $query[ $del_array[1] ] ) ) {
79
+ unset( $query[ $del_array[1] ] );
80
+ }
81
+ /* unset() does nothing if a variable or array element does not exist.
82
+ */
83
+ unset( $remember['query'][ $del_array[1] ][ $del_array[2] ] );
84
+ if ( empty( $remember['query'][ $del_array[1] ] ) ) {
85
+ unset( $remember['query'][ $del_array[1] ] );
86
+ }
87
+ unset( $override['query'][ $del_array[1] ][ $del_array[2] ] );
88
+ if ( empty( $override['query'][ $del_array[1] ] ) ) {
89
+ unset( $override['query'][ $del_array[1] ] );
90
+ }
91
+ } else {
92
+ /* Check for a URL entry
93
+ */
94
+ if ( 'url' === jr_mt_substr( $del_array[0], 0, 3 ) ) {
95
+ foreach ( $valid[ $del_array[0] ] as $i => $entry_array ) {
96
+ if ( $entry_array['url'] === $del_array[2] ) {
97
+ /* Cannot unset $entry_array, even if prefixed by & in foreach
98
+ */
99
+ unset( $valid[ $del_array[0] ][ $i ] );
100
+ break;
101
+ }
102
+ }
103
+ } else {
104
+ /* Must be Home, All Pages or Posts, or Everything
105
+ */
106
+ $valid[ $del_array[0] ] = '';
107
+ }
108
+ }
109
+ }
110
+ }
111
+
112
+ /* Handle troublesome %E2%80%8E UTF Left-to-right Mark (LRM) suffix first.
113
+ */
114
+ $url = jr_mt_sanitize_url( $input['add_path_id'] );
115
+
116
+ if ( ( empty( $input['add_theme'] ) && !empty( $url ) ) || ( !empty( $input['add_theme'] ) && empty( $url ) ) ) {
117
+ add_settings_error(
118
+ 'jr_mt_settings',
119
+ 'jr_mt_emptyerror',
120
+ 'Both URL and Theme must be specified to add an Individual entry',
121
+ 'error'
122
+ );
123
+ } else {
124
+ if ( !empty( $url ) ) {
125
+ if ( jr_mt_same_prefix_url( JR_MT_HOME_URL, $url ) ) {
126
+ if ( ( '*' !== $input['add_is_prefix'] ) && ( FALSE !== strpos( $url, '*' ) ) ) {
127
+ add_settings_error(
128
+ 'jr_mt_settings',
129
+ 'jr_mt_queryerror',
130
+ 'Asterisk ("*") only allowed when "URL Prefix with Asterisk" selected: <code>' . $url . '</code>',
131
+ 'error'
132
+ );
133
+ } else {
134
+ $prep_url = jr_mt_prep_url( $url );
135
+ if ( 'false' === $input['add_is_prefix'] ) {
136
+ if ( jr_mt_same_url( $prep_url, JR_MT_HOME_URL ) ) {
137
+ add_settings_error(
138
+ 'jr_mt_settings',
139
+ 'jr_mt_homeerror',
140
+ 'Please use "Select Theme for Site Home" field instead of specifying Site Home URL as an individual entry.',
141
+ 'error'
142
+ );
143
+ } else {
144
+ if ( jr_mt_same_prefix_url( $prep_url, admin_url() ) ) {
145
+ add_settings_error(
146
+ 'jr_mt_settings',
147
+ 'jr_mt_adminerror',
148
+ 'Admin Page URLs are not allowed because no known Themes alter the appearance of Admin pages: <code>' . $url . '</code>',
149
+ 'error'
150
+ );
151
+ }
152
+ }
153
+ } else {
154
+ if ( '*' === $input['add_is_prefix'] ) {
155
+ $url_dirs = explode( '/', str_replace( '\\', '/', $url ) );
156
+ foreach ( $url_dirs as $dir ) {
157
+ if ( FALSE !== strpos( $dir, '*' ) ) {
158
+ $asterisk_found = TRUE;
159
+ if ( '*' !== $dir ) {
160
+ $asterisk_not_alone = TRUE;
161
+ }
162
+ break;
163
+ }
164
+ }
165
+ if ( isset( $asterisk_found ) ) {
166
+ if ( isset( $asterisk_not_alone ) ) {
167
+ add_settings_error(
168
+ 'jr_mt_settings',
169
+ 'jr_mt_queryerror',
170
+ 'An Asterisk ("*") may only replace a full subdirectory name, not just a portion of it: <code>' . $url . '</code>',
171
+ 'error'
172
+ );
173
+ }
174
+ } else {
175
+ add_settings_error(
176
+ 'jr_mt_settings',
177
+ 'jr_mt_queryerror',
178
+ 'No Asterisk ("*") specified but "URL Prefix with Asterisk" selected: <code>' . $url . '</code>',
179
+ 'error'
180
+ );
181
+ }
182
+ }
183
+ }
184
+
185
+ function jr_mt_settings_errors() {
186
+ $errors = get_settings_errors();
187
+ if ( !empty( $errors ) ) {
188
+ foreach ( $errors as $error_array ) {
189
+ if ( 'error' === $error_array['type'] ) {
190
+ return TRUE;
191
+ }
192
+ }
193
+ }
194
+ return FALSE;
195
+ }
196
+
197
+ /* If there have been no errors detected,
198
+ create the new URL setting entry.
199
+ */
200
+ if ( !jr_mt_settings_errors() ) {
201
+ /* ['url'], ['url_prefix'] or ['url_asterisk']
202
+ */
203
+ $key = $prefix_types[ $input['add_is_prefix'] ];
204
+ $rel_url = jr_mt_relative_url( $url, JR_MT_HOME_URL );
205
+ $valid[ $key ][] = array(
206
+ 'url' => $url,
207
+ 'rel_url' => $rel_url,
208
+ 'theme' => $input['add_theme']
209
+ );
210
+ /* Get index of element just added to array $valid[ $key ]
211
+ */
212
+ end( $valid[ $key ] );
213
+ $valid_key = key( $valid[ $key ] );
214
+ /* Create the URL Prep array for each of the current Site Aliases,
215
+ including the Current Site URL
216
+ */
217
+ foreach ( $aliases as $index => $alias ) {
218
+ $valid[ $key ][ $valid_key ]['prep'][] = jr_mt_prep_url( $alias['url'] . '/' . $rel_url );
219
+ }
220
+ /* Only for URL type Setting, not Prefix types.
221
+ */
222
+ if ( 'url' === $key ) {
223
+ /* Try and figure out ID and WordPress Query Keyword for Type, if possible and relevant
224
+ */
225
+ if ( ( 0 === ( $id = url_to_postid( $url ) ) ) &&
226
+ ( version_compare( get_bloginfo( 'version' ), '4', '>=' ) ) ) {
227
+ $id = attachment_url_to_postid( $url );
228
+ }
229
+ if ( !empty( $id ) ) {
230
+ /* Type Cast ID as String, to match ?p=id Query in URL after Prep
231
+ */
232
+ $valid[ $key ][ $valid_key ]['id'] = (string) $id;
233
+ if ( NULL !== ( $post = get_post( $id ) ) ) {
234
+ switch ( $post->post_type ) {
235
+ case 'post':
236
+ $valid[ $key ][ $valid_key ]['id_kw'] = 'p';
237
+ break;
238
+ case 'page':
239
+ $valid[ $key ][ $valid_key ]['id_kw'] = 'page_id';
240
+ break;
241
+ case 'attachment':
242
+ $valid[ $key ][ $valid_key ]['id_kw'] = 'attachment_id';
243
+ break;
244
+ }
245
+ }
246
+ }
247
+ }
248
+ }
249
+ }
250
+ } else {
251
+ add_settings_error(
252
+ 'jr_mt_settings',
253
+ 'jr_mt_urlerror',
254
+ ' URL specified is not part of current WordPress web site: <code>'
255
+ . $url
256
+ . '</code>. URL must begin with <code>'
257
+ . JR_MT_HOME_URL
258
+ . '</code>.',
259
+ 'updated'
260
+ );
261
+ }
262
+ }
263
+ }
264
+
265
+ /* Make sure reserved characters are not used
266
+ in URL Query keyword or value fields on Settings page.
267
+ */
268
+ function jr_mt_query_chars( $element, $where ) {
269
+ foreach (
270
+ array(
271
+ '=' => 'Equals Sign' ,
272
+ '?' => 'Question Mark' ,
273
+ '&' => 'Ampersand' ,
274
+ ' ' => 'Blank' ,
275
+ '#' => 'Number Sign' ,
276
+ '/' => 'Slash' ,
277
+ '\\' => 'Backslash' ,
278
+ '[' => 'Square Bracket',
279
+ ']' => 'Square Bracket'
280
+ ) as $char => $name ) {
281
+ if ( FALSE !== strpos( $element, $char ) ) {
282
+ add_settings_error(
283
+ 'jr_mt_settings',
284
+ 'jr_mt_queryerror',
285
+ 'Illegal character used in '
286
+ . $where
287
+ . ': '
288
+ . $name
289
+ . ' ("' . $char . '") in "'
290
+ . $element
291
+ . '"',
292
+ 'error'
293
+ );
294
+ return FALSE;
295
+ }
296
+ }
297
+ return TRUE;
298
+ }
299
+ /* Data Sanitization needed here
300
+ */
301
+ $keyword = jr_mt_prep_query_keyword( $input['add_querykw_keyword'] );
302
+ if ( !empty( $input['add_querykw_theme'] ) && !empty( $keyword ) ) {
303
+ if ( jr_mt_query_chars( $keyword, 'Query Keyword' ) ) {
304
+ /* If there is an existing entry for the Keyword,
305
+ then replace it.
306
+ Otherwise, create a new entry.
307
+ */
308
+ $query[ $keyword ]['*'] = $input['add_querykw_theme'];
309
+ }
310
+ } else {
311
+ if ( !( empty( $input['add_querykw_theme'] ) && empty( $keyword ) ) ) {
312
+ add_settings_error(
313
+ 'jr_mt_settings',
314
+ 'jr_mt_emptyerror',
315
+ 'Both Query Keyword and Theme must be specified to add an Individual Query Keyword entry',
316
+ 'error'
317
+ );
318
+ }
319
+ }
320
+
321
+ /* Data Sanitization needed here
322
+ */
323
+ $keyword = jr_mt_prep_query_keyword( $input['add_query_keyword'] );
324
+ $value = jr_mt_prep_query_value( $input['add_query_value'] );
325
+ if ( !empty( $input['add_query_theme'] ) && !empty( $keyword ) && !empty( $value ) ) {
326
+ if ( jr_mt_query_chars( $keyword, 'Query Keyword' ) && jr_mt_query_chars( $value, 'Query Value' ) ) {
327
+ /* If there is an existing entry for the Keyword and Value pair,
328
+ then replace it.
329
+ Otherwise, create a new entry.
330
+
331
+ Be sure that a numeric Keyword or Value still is type String.
332
+ */
333
+ $query[ $keyword ][ $value ] = $input['add_query_theme'];
334
+ }
335
+ } else {
336
+ if ( !( empty( $input['add_query_theme'] ) && empty( $keyword ) && empty( $value ) ) ) {
337
+ add_settings_error(
338
+ 'jr_mt_settings',
339
+ 'jr_mt_emptyerror',
340
+ 'Query Keyword, Value and Theme must all be specified to add an Individual Query entry',
341
+ 'error'
342
+ );
343
+ }
344
+ }
345
+
346
+ if ( 'true' === $input['query_present'] ) {
347
+ $valid['query_present'] = TRUE;
348
+ } else {
349
+ if ( 'false' === $input['query_present'] ) {
350
+ $valid['query_present'] = FALSE;
351
+ }
352
+ }
353
+
354
+ /* Handle Alias tab
355
+
356
+ Always handle Delete first, to allow Replacement (Delete then Add)
357
+ */
358
+ if ( isset ( $input['del_alias_entry'] ) ) {
359
+ foreach ( $input['del_alias_entry'] as $del_alias_entry ) {
360
+ $int_key = (int) $del_alias_entry;
361
+ unset( $aliases[ $int_key ] );
362
+ /* Now go through all the URL-based Settings,
363
+ and delete the Prep for the deleted Alias.
364
+
365
+ $int_key is the array integer key of the just-deleted
366
+ Alias, as that will also be the array key for each of the
367
+ Settings ['prep'] arrays.
368
+ */
369
+ foreach ( $prefix_types as $form_prefix => $settings_prefix ) {
370
+ foreach ( $valid[ $settings_prefix ] as $key => $url_entry ) {
371
+ unset( $valid[ $settings_prefix ][ $key ]['prep'][ $int_key ] );
372
+ }
373
+ }
374
+ }
375
+ }
376
+ $alias_url = jr_mt_sanitize_url( $input['add_alias'] );
377
+ if ( !empty( $alias_url ) ) {
378
+ /* URL has been trimmed but Case has not been altered
379
+ */
380
+ if ( ( ( 0 !== substr_compare( $alias_url, 'http://', 0, 7, TRUE ) )
381
+ && ( 0 !== substr_compare( $alias_url, 'https://', 0, 8, TRUE ) )
382
+ )
383
+ || ( FALSE === ( $parse_url = parse_url( $alias_url ) ) ) ) {
384
+ add_settings_error(
385
+ 'jr_mt_settings',
386
+ 'jr_mt_badurlerror',
387
+ "Alias URL specified is invalid: <code>$url</code>",
388
+ 'error'
389
+ );
390
+ } else {
391
+ $url_ok = TRUE;
392
+ foreach ( array( 'user', 'pass', 'query', 'fragment' ) as $component ) {
393
+ if ( isset( $parse_url[ $component ] ) ) {
394
+ $url_ok = FALSE;
395
+ break;
396
+ }
397
+ }
398
+ if ( $url_ok ) {
399
+ /* Be sure there is NOT a trailing slash
400
+ */
401
+ $alias_url = rtrim( $alias_url, '/\\' );
402
+ $aliases[] = array(
403
+ 'url' => $alias_url,
404
+ 'prep' => jr_mt_prep_url( $alias_url ),
405
+ 'home' => FALSE
406
+ );
407
+ /* Now go through all the URL-based Settings,
408
+ and add a Prep for the new Alias.
409
+
410
+ First, determine the array integer key of the newly-added
411
+ Alias, as that will also be the array key for each of the
412
+ Settings ['prep'] arrays.
413
+ */
414
+ end( $aliases );
415
+ $prep_key = key( $aliases );
416
+
417
+ foreach ( $prefix_types as $form_prefix => $settings_prefix ) {
418
+ foreach ( $valid[ $settings_prefix ] as $key => $url_entry ) {
419
+ $valid[ $settings_prefix ][ $key ]['prep'][ $prep_key ] = jr_mt_prep_url(
420
+ $alias_url . '/' . $valid[ $settings_prefix ][ $key ]['rel_url']
421
+ );
422
+ }
423
+ }
424
+ } else {
425
+ add_settings_error(
426
+ 'jr_mt_settings',
427
+ 'jr_mt_badurlerror',
428
+ 'Alias URL cannot contain user, password, query ("?") or fragment ("#"): <code>'
429
+ . "$url</code>",
430
+ 'error'
431
+ );
432
+ }
433
+ }
434
+ }
435
+
436
+ $errors = get_settings_errors();
437
+ if ( empty( $errors ) ) {
438
+ add_settings_error(
439
+ 'jr_mt_settings',
440
+ 'jr_mt_saved',
441
+ 'Settings Saved',
442
+ 'updated'
443
+ );
444
+ }
445
+ $valid['query'] = $query;
446
+ $valid['remember'] = $remember;
447
+ $valid['override'] = $override;
448
+ $valid['aliases'] = $aliases;
449
+ return $valid;
450
+ }
451
+
452
+ ?>
includes/admin.php ADDED
@@ -0,0 +1,1148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* Exit if .php file accessed directly
3
+ */
4
+ if ( !defined( 'ABSPATH' ) ) {
5
+ exit;
6
+ }
7
+
8
+ global $jr_mt_kwvalsep;
9
+ /* Everything is converted to lower-case, so upper-case letter makes a good keyword-value separator
10
+ */
11
+ $jr_mt_kwvalsep = 'A';
12
+
13
+ /* Go to Settings page to get Settings checked/fixed/initialized.
14
+
15
+ But don't display on Settings page itself.
16
+ */
17
+ if ( ( !isset( $_GET['page'] ) || ( 'jr_mt_settings' !== $_GET['page'] ) )
18
+ && ( ( FALSE === ( $internal_settings = get_option( 'jr_mt_internal_settings' ) ) )
19
+ || ( !isset( $internal_settings['v7init'] ) ) )
20
+ && ( FALSE !== get_option( 'jr_mt_settings' ) ) ) {
21
+ /* If (public) Settings do not exist, this is a new install or
22
+ re-install after deleting the plugin.
23
+ No warning is needed because the plugin will not do anything,
24
+ and the admin will naturally go the Settings to set some Theme Selections.
25
+ */
26
+ add_action( 'all_admin_notices', 'jr_mt_v7init_required' );
27
+ /**
28
+ * Warn that Private Site is turned OFF by default
29
+ *
30
+ * Put Warning on top of every Admin page (visible to Admins only)
31
+ * until Admin visits plugin's Settings page.
32
+ *
33
+ */
34
+ function jr_mt_v7init_required() {
35
+ global $jr_mt_plugin_data;
36
+ if ( current_user_can( 'manage_options' ) ) {
37
+ echo '<div class="updated"><p><b>' . $jr_mt_plugin_data['Name'] . ' plugin: Version '. $jr_mt_plugin_data['Version'] . ' update requires visit to <a href="'
38
+ . admin_url( 'options-general.php?page=jr_mt_settings' )
39
+ . '">Settings page</a> to check and update its Settings.</b></p></div>';
40
+ }
41
+ }
42
+ }
43
+
44
+ add_action( 'admin_enqueue_scripts', 'jr_mt_admin_enqueue_scripts' );
45
+ function jr_mt_admin_enqueue_scripts() {
46
+ global $jr_mt_plugin_data;
47
+ wp_enqueue_script( 'jr_mt_tabs', plugins_url() . '/' . dirname( jr_mt_plugin_basename() ) . '/js/tabs.js', array(), $jr_mt_plugin_data['Version'] );
48
+ }
49
+
50
+ /**
51
+ * Settings page for plugin
52
+ *
53
+ * Display and Process Settings page for this plugin.
54
+ *
55
+ */
56
+ function jr_mt_settings_page() {
57
+ global $jr_mt_plugin_data, $jr_mt_plugins_cache;
58
+ $jr_mt_plugins_cache = get_plugins();
59
+ add_thickbox();
60
+ echo '<div class="wrap">';
61
+ echo '<h2>' . $jr_mt_plugin_data['Name'] . '</h2>';
62
+
63
+ /* Required because it is only called automatically for Admin Pages in the Settings section
64
+ */
65
+ settings_errors( 'jr_mt_settings' );
66
+
67
+ /* Return to Same Tab where button was pushed.
68
+
69
+ TODO: This should be converted to use wp_localize_script()
70
+ as described on page 356 of "Professional WordPress Plugin Development" 2011.
71
+ */
72
+ $name = 'jr_mt_' . get_current_user_id() . '_tab';
73
+ if ( FALSE === ( $tab = get_transient( $name ) ) ) {
74
+ $tab = 1;
75
+ } else {
76
+ delete_transient( $name );
77
+ }
78
+ echo '<script type="text/javascript">window.onload = function() { jrMtTabs('
79
+ . $tab . ', 6 ); }</script>';
80
+
81
+ $theme_obj = wp_get_theme();
82
+ $theme = $theme_obj->Name;
83
+ $theme_version = $theme_obj->Version;
84
+ global $jr_mt_options_cache;
85
+
86
+ $current_wp_version = get_bloginfo( 'version' );
87
+
88
+ global $jr_mt_plugins_cache;
89
+
90
+ $compatible = TRUE;
91
+
92
+ // Check for incompatible plugins that have been activated: BuddyPress and Theme Test Drive
93
+ global $jr_mt_incompat_plugins;
94
+ foreach ( $jr_mt_plugins_cache as $rel_path => $plugin_data ) {
95
+ if ( in_array( $plugin_data['Name'], $jr_mt_incompat_plugins, TRUE ) && is_plugin_active( $rel_path ) ) {
96
+ if ( $compatible ) {
97
+ echo '<h3>Plugin Conflict Error Detected</h3>';
98
+ $compatible = FALSE;
99
+ }
100
+ echo '<p>This Plugin (' . $jr_mt_plugin_data['Name'] . ') cannot be used when the <b>' . $plugin_data['Name']
101
+ . '</b> plugin is Activated. If you wish to use the ' . $jr_mt_plugin_data['Name']
102
+ . ' plugin, please deactivate the ' . $plugin_data['Name']
103
+ . ' plugin (not just when viewing this Settings page, but whenever the '
104
+ . $jr_mt_plugin_data['Name'] . ' plugin is activated).</p>';
105
+ }
106
+ }
107
+
108
+ if ( $compatible ) {
109
+ ?>
110
+ <style type="text/css">
111
+ <!--
112
+ ul.jrmtpoints { margin-left: 1em;
113
+ list-style: disc;}
114
+ -->
115
+ </style>
116
+ <h2 class="nav-tab-wrapper">
117
+ <a href="#" class="nav-tab nav-tab-active" id="jr-mt-tabs1"
118
+ onClick="jrMtTabs( 1, 6 );">Settings</a><a href="#" class="nav-tab" id="jr-mt-tabs2"
119
+ onClick="jrMtTabs( 2, 6 );">Site Aliases</a><a href="#" class="nav-tab" id="jr-mt-tabs3"
120
+ onClick="jrMtTabs( 3, 6 );">Advanced Settings</a><a href="#" class="nav-tab" id="jr-mt-tabs4"
121
+ onClick="jrMtTabs( 4, 6 );">Theme Options</a><a href="#" class="nav-tab" id="jr-mt-tabs5"
122
+ onClick="jrMtTabs( 5, 6 );">System Information</a><a href="#" class="nav-tab" id="jr-mt-tabs6"
123
+ onClick="jrMtTabs( 6, 6 );">Help</a>
124
+ </h2>
125
+ <div id="jr-mt-settings1">
126
+ <h3>Settings</h3>
127
+ <p>
128
+ This is the main Settings tab.
129
+ You should also review the
130
+ <a href="#" onClick="jrMtTabs( 2, 6 );">Site Aliases tab</a>:
131
+ </p>
132
+ <ul class="jrmtpoints">
133
+ <li>
134
+ when first using this plugin,
135
+ </li>
136
+ <li>
137
+ when upgrading from Version 5 (or earlier) of this plugin,
138
+ and
139
+ </li>
140
+ <li>
141
+ whenever you change the
142
+ <b>
143
+ Site Address (URL)
144
+ </b>
145
+ defined on the
146
+ <a href="options-general.php">
147
+ General Settings</a>
148
+ Admin panel.
149
+ </li>
150
+ </ul>
151
+ <p>
152
+ Additional Settings are available on the
153
+ <a href="#" onClick="jrMtTabs( 3, 6 );">Advanced Settings tab</a>,
154
+ but they can cause problems
155
+ in certain WordPress configurations,
156
+ so should be used with care.
157
+ </p>
158
+ <p>
159
+ Checking Settings...
160
+ </p>
161
+ <ul class="jrmtpoints">
162
+ <?php
163
+
164
+ unregister_setting( 'jr_mt_settings', 'jr_mt_settings', 'jr_mt_validate_settings' );
165
+
166
+ global $wp;
167
+ $default_internal_settings = array(
168
+ 'version' => $jr_mt_plugin_data['Version'],
169
+ 'permalink' => get_option( 'permalink_structure' ),
170
+ /* Store $wp->public_query_vars for when they are needed before 'setup_theme' Action
171
+
172
+ Note: $wp is not valid until 'setup_theme' Action.
173
+ */
174
+ 'query_vars' => $wp->public_query_vars
175
+ );
176
+ if ( is_array( $internal_settings_original = get_option( 'jr_mt_internal_settings' ) ) ) {
177
+ $internal_settings = $internal_settings_original;
178
+ /* When plugin is installed (i.e. - no Settings),
179
+ Previous Version is set to Current Version
180
+ because no Version Conversion is required.
181
+ */
182
+ if ( ( !isset( $internal_settings['version'] ) ) || ( !is_string( $internal_settings['version'] ) ) ) {
183
+ $internal_settings['version'] = $default_internal_settings['version'];
184
+ }
185
+ $internal_settings['query_vars'] = $default_internal_settings['query_vars'];
186
+ } else {
187
+ $internal_settings = $default_internal_settings;
188
+ jr_mt_messages( 'First use (or after plugin deleted): initialize Internal ("invisible") Settings' );
189
+ }
190
+ $previous_version = $internal_settings['version'];
191
+ /* Update to Current Version (which may be the same as Previous Version)
192
+ */
193
+ $internal_settings['version'] = $default_internal_settings['version'];
194
+
195
+ $internal_settings['v7init'] = TRUE;
196
+
197
+ if ( $internal_settings !== $internal_settings_original ) {
198
+ if ( update_option( 'jr_mt_internal_settings', $internal_settings ) ) {
199
+ jr_mt_messages( 'Internal ("invisible") Settings have changed and were successfully updated' );
200
+ } else {
201
+ jr_mt_messages( 'Internal ("invisible") Settings have changed but could not be updated' );
202
+ }
203
+ }
204
+
205
+ /* Check if any Settings were not properly converted from prior versions,
206
+ the Site URL has changed, or the settings are otherwise corrupted.
207
+ Do things in the following order, to avoid issues:
208
+ - check every setting exists and is of the right type
209
+ - check for still being in Version 4 settings; use upgradev5, if so
210
+ - check for still being in Version 5 settings; do my own conversion, if so
211
+ - check for pre-Version 7 format for ['prep']['query'] elements; convert
212
+ - check for "=" in ['prep']['query'] keyword or value
213
+ - remove if first char of value or last char of keyword
214
+ - delete setting if found anywhere else, and report as corrupt
215
+ - be sure ['aliases'][]['home'] is TRUE for correct URL (Site URL); if not:
216
+ - create any missing ['url'*][]['rel_url'] from ['url'*][]['url'] and
217
+ ['aliases'][]['url'] from old ['aliases'][]['home']
218
+ - change to FALSE
219
+ - set correct ['aliases'][]['home'] to TRUE, even if it means adding alias entries
220
+ - rebuild all ['url'*][]['prep']
221
+ - re-create all ['url'*][]['url'] from ['url'*][]['rel_url'] and new Site URL
222
+ - ['url'*][]['id'] is integer - convert to string
223
+ - Missing ['url'*][]['rel_url'] - create it from ['url'*][]['url'] and Site URL
224
+ - ['url'*][]['prep'] is not array - rebuild all ['url'*][]['prep']
225
+ - "?" in ['url'*][]['url'] but no query in ['url'*][]['prep'][] - rebuild this ['url'*][]['prep']
226
+ - Deleted Themes
227
+ */
228
+ if ( is_array( $settings_original = get_option( 'jr_mt_settings' ) ) ) {
229
+ $settings = $settings_original;
230
+ global $jr_mt_url_types;
231
+ $default_settings = jr_mt_default_settings();
232
+ /* Check for unconverted Version 4 Settings
233
+ */
234
+ if ( ( !isset( $settings['url'] ) )
235
+ || version_compare( $previous_version, '5', '<' ) ) {
236
+ require_once( jr_mt_path() . 'includes/upgradev5.php' );
237
+ $settings = jr_mt_convert_ids( $settings );
238
+ jr_mt_messages( 'Conversion completed to Version 5 format from Version ' . $previous_version );
239
+ }
240
+ /* Check for unconverted Version 5 Settings
241
+ */
242
+ if ( ( !isset( $settings['aliases'] ) )
243
+ || version_compare( $previous_version, '6', '<' ) ) {
244
+ $settings['aliases'] = $default_settings['aliases'];
245
+ require_once( jr_mt_path() . 'includes/upgradev6.php' );
246
+ $settings = jr_mt_convert_url_arrays( $settings );
247
+ jr_mt_messages( 'Conversion completed to Version 6 format from Version ' . $previous_version );
248
+ }
249
+ /* Check Settings for missing or wrong type entries,
250
+ including Themes that are not currently installed.
251
+ */
252
+ $jr_mt_all_themes = jr_mt_all_themes();
253
+ /* Check: 'all_pages', 'all_posts', 'site_home', 'current'
254
+ */
255
+ foreach ( array( 'all_pages', 'all_posts', 'site_home', 'current' ) as $key ) {
256
+ if ( ( !isset( $settings[ $key ] ) ) || ( !is_string( $settings[ $key ] ) ) ) {
257
+ $settings[ $key ] = $default_settings[ $key ];
258
+ jr_mt_messages( 'Home, Everything or All Pages/Posts Setting corrupt: reset to default (WordPress Active Theme)' );
259
+ } else {
260
+ if ( ( '' !== $settings[ $key ] ) && ( !isset( $jr_mt_all_themes[ $settings[ $key ] ] ) ) ) {
261
+ $settings[ $key ] = $default_settings[ $key ];
262
+ jr_mt_messages( 'Home, Everything or All Pages/Posts Setting deleted: specified Theme no longer exists' );
263
+ }
264
+ }
265
+ }
266
+ /* Check ['query_present']
267
+ */
268
+ if ( ( !isset( $settings['query_present'] ) ) || ( !is_bool( $settings['query_present'] ) ) ) {
269
+ $settings['query_present'] = $default_settings['query_present'];
270
+ jr_mt_messages( '"When to add Sticky Query to a URL" Setting corrupt: reset to default' );
271
+ }
272
+ /* Check ['aliases']
273
+ */
274
+ if ( ( !isset( $settings['aliases'] ) ) || ( !is_array( $settings['aliases'] ) ) ) {
275
+ $settings['aliases'] = $default_settings['aliases'];
276
+ jr_mt_messages( 'No Site Aliases defined; set to Default Aliases, if any' );
277
+ /* Relies on ['url'*] being valid, so do after it.
278
+ */
279
+ $rebuild_prep = TRUE;
280
+ } else {
281
+ foreach ( $settings['aliases'] as $alias ) {
282
+ if ( ( !is_string( $alias['url'] ) )
283
+ || ( !is_array( $alias['prep'] ) )
284
+ || !is_bool( $alias['home'] ) ) {
285
+ $settings['aliases'] = $default_settings['aliases'];
286
+ jr_mt_messages( 'Site Aliases settings are corrupt; reset to Default Aliases, if any' );
287
+ $rebuild_prep = TRUE;
288
+ break;
289
+ }
290
+ }
291
+ }
292
+ /* Check [url*]
293
+ */
294
+ foreach ( $jr_mt_url_types as $url_type ) {
295
+ if ( !isset( $settings[ $url_type ] ) ) {
296
+ $settings[ $url_type ] = $default_settings[ $url_type ];
297
+ jr_mt_messages( 'URL setting(s) re-initialized' );
298
+ } else {
299
+ if ( !is_array( $settings[ $url_type ] ) ) {
300
+ $settings[ $url_type ] = $default_settings[ $url_type ];
301
+ jr_mt_messages( 'URL setting(s) deleted because they are corrupt' );
302
+ } else {
303
+ foreach ( $settings[ $url_type ] as $index => $url_array ) {
304
+ if ( ( !isset( $url_array['url'] ) )
305
+ || ( !isset( $url_array['prep'] ) )
306
+ || ( !isset( $url_array['theme'] ) )
307
+ || ( !is_string( $url_array['url'] ) )
308
+ || ( !is_string( $url_array['theme'] ) )
309
+ || ( !isset( $jr_mt_all_themes[ $url_array['theme'] ] ) ) ) {
310
+ unset( $settings[ $url_type ][ $index ] );
311
+ jr_mt_messages( 'URL setting deleted: either it was corrupt or specified Theme that no longer exists' );
312
+ } else {
313
+ /* Be sure all ['prep'] are arrays.
314
+ If any are not, rebuild all ['prep'] entries.
315
+ */
316
+ if ( is_array( $url_array['prep'] ) ) {
317
+ /* Be sure that all ['prep'] entries have a ['query'] entry when the
318
+ URL has a Query in it, denoted by a "?".
319
+ If any not found, Rebuild all the ['prep'] entries.
320
+ */
321
+ if ( FALSE !== strpos( $url_array['url'], '?' ) ) {
322
+ foreach ( $url_array['prep'] as $prep_entry ) {
323
+ if ( isset( $prep_entry['query'] ) && is_array( $prep_entry['query'] ) ) {
324
+ /* Check for unconverted and corrupt Queries in ['prep']['query'] Settings
325
+
326
+ A Keyword ending in "=" or a Value beginning with "=" gets converted.
327
+ A "=" anywhere else means Corruption.
328
+ */
329
+ foreach ( $prep_entry['query'] as $keyword => $value_array ) {
330
+ if ( is_array( $value_array ) ) {
331
+ foreach ( $value_array as $value => $equalsign ) {
332
+ /* There must be an Equals Sign if there is a Value
333
+ */
334
+ if ( is_bool( $equalsign ) && ( $equalsign || ( '' === $value ) ) ) {
335
+ foreach ( array(
336
+ '=', '?', '&', ' ', '#', '/', '\\', '[', ']'
337
+ ) as $char ) {
338
+ if ( FALSE !== strpos( $keyword . $value, $char ) ) {
339
+ unset( $settings[ $url_type ][ $index ] );
340
+ jr_mt_messages( 'URL setting deleted: illegal character found in Query keyword or value' );
341
+ break 4;
342
+ }
343
+ }
344
+ } else {
345
+ $rebuild_prep = TRUE;
346
+ break 3;
347
+ }
348
+ }
349
+ } else {
350
+ $rebuild_prep = TRUE;
351
+ break 2;
352
+ }
353
+ }
354
+ } else {
355
+ $rebuild_prep = TRUE;
356
+ break;
357
+ }
358
+ }
359
+ }
360
+ } else {
361
+ $rebuild_prep = TRUE;
362
+ }
363
+
364
+ /* Convert any integer Page/Post/Attachment ID to a string
365
+ so it will match the type of a Query value in PHP/HTTP
366
+ */
367
+ if ( isset( $url_array['id'] ) && is_int( $url_array['id'] ) ) {
368
+ $settings[ $url_type ][ $index ]['id'] = ( string ) $url_array['id'];
369
+ jr_mt_messages( 'Integer type Page/Post/Attachment ID found: converted to String type' );
370
+ }
371
+ if ( isset( $url_array['id_kw'] )
372
+ && ( ( !is_string( $url_array['id_kw'] ) )
373
+ || ( !in_array( $url_array['id_kw'], array( 'page_id', 'p', 'attachment_id' ), TRUE ) ) ) ) {
374
+ unset( $settings[ $url_type ][ $index ]['id_kw'] );
375
+ }
376
+ if ( isset( $url_array['rel_url'] )
377
+ && ( !is_string( $url_array['rel_url'] ) ) ) {
378
+ unset( $settings[ $url_type ][ $index ]['rel_url'] );
379
+ }
380
+ }
381
+ }
382
+ }
383
+ }
384
+ }
385
+ /* Check ['query']
386
+ */
387
+ if ( ( !isset( $settings['query'] ) ) || ( !is_array( $settings['query'] ) ) ) {
388
+ $settings['query'] = $default_settings['query'];
389
+ jr_mt_messages( 'Query setting(s) deleted because they are corrupt' );
390
+ } else {
391
+ foreach ( $settings['query'] as $keyword => $value_array ) {
392
+ if ( is_array( $value_array ) ) {
393
+ foreach ( $value_array as $value => $theme ) {
394
+ if ( ( !is_string( $theme ) )
395
+ || ( !isset( $jr_mt_all_themes[ $theme ] ) ) ) {
396
+ unset( $settings['query'][ $keyword ][ $value ] );
397
+ jr_mt_messages( 'Query setting deleted: either it was corrupt or specified Theme that no longer exists' );
398
+ /* All the checking for Empty parents (e.g. - $settings['query'][ $keyword ])
399
+ and matching remember/query elements is done later.
400
+ */
401
+ }
402
+ }
403
+ if ( empty( $settings['query'][ $keyword ] ) ) {
404
+ unset( $settings['query'][ $keyword ] );
405
+ }
406
+ } else {
407
+ unset( $settings['query'][ $keyword ] );
408
+ jr_mt_messages( 'Query setting deleted because it is corrupt' );
409
+ }
410
+ }
411
+ /* Check: 'remember', 'override'
412
+ */
413
+ foreach ( array( 'remember', 'override' ) as $key ) {
414
+ if ( is_array( $settings[ $key ] )
415
+ && isset( $settings[ $key ]['query'] )
416
+ && is_array( $settings[ $key ]['query'] ) ) {
417
+ foreach ( $settings[ $key ] as $query_constant => $query_array ) {
418
+ if ( 'query' !== $query_constant ) {
419
+ unset( $settings[ $key ][ $query_constant ] );
420
+ jr_mt_messages( 'Sticky/Override setting(s) deleted because they are corrupt' );
421
+ }
422
+ }
423
+ foreach ( $settings[ $key ]['query'] as $keyword => $value_array ) {
424
+ if ( is_array( $value_array ) ) {
425
+ foreach ( $value_array as $value => $bool ) {
426
+ if ( ( !is_bool( $bool ) )
427
+ || ( !isset( $settings['query'][ $keyword ][ $value ] ) ) ) {
428
+ unset( $settings[ $key ]['query'][ $keyword ][ $value ] );
429
+ jr_mt_messages( 'Sticky/Override setting(s) deleted because they are corrupt' );
430
+ }
431
+ }
432
+ if ( empty( $settings[ $key ]['query'][ $keyword ] ) ) {
433
+ unset( $settings[ $key ]['query'][ $keyword ] );
434
+ }
435
+ } else {
436
+ unset( $settings[ $key ]['query'][ $keyword ] );
437
+ jr_mt_messages( 'Sticky/Override setting(s) deleted because they are corrupt' );
438
+ }
439
+ }
440
+ } else {
441
+ $settings[ $key ] = $default_settings[ $key ];
442
+ jr_mt_messages( 'Sticky/Override setting(s) deleted because they are corrupt' );
443
+ }
444
+ }
445
+ }
446
+
447
+ /* Check for missing ['rel_url'] and build it
448
+ */
449
+ $settings = jr_mt_missing_rel_url( $settings, JR_MT_HOME_URL );
450
+
451
+ /* Check if Site URL has changed by comparing corresponding ['url'] of ['home']
452
+ setting in Aliases array with current Site URL.
453
+ */
454
+ $site_url_changed = FALSE;
455
+ if ( is_array( $settings['aliases'] ) ) {
456
+ foreach ( $settings['aliases'] as $index => $alias ) {
457
+ if ( $alias['home'] ) {
458
+ if ( !jr_mt_same_url( $alias['prep'], JR_MT_HOME_URL ) ) {
459
+ /* Site URL has changed.
460
+ */
461
+ $site_url_changed = TRUE;
462
+ $old_site_url = $alias['url'];
463
+ break;
464
+ }
465
+ }
466
+ }
467
+ if ( $site_url_changed ) {
468
+ $settings = jr_mt_rebuild_display_url( $settings, $old_site_url );
469
+
470
+ /* See if there is an Alias entry for the new Site URL.
471
+ If not, add one, and perhaps another with/without www.
472
+ */
473
+ $settings = jr_mt_rebuild_alias_home( $settings );
474
+
475
+ jr_mt_messages( 'Site Address (URL) has changed: any URLs and Aliases in settings have been updated' );
476
+
477
+ /* Rebuild ['prep']
478
+ */
479
+ $rebuild_prep = TRUE;
480
+ }
481
+ } else {
482
+ $settings['aliases'] = jr_mt_init_aliases();
483
+ jr_mt_messages( 'No Site Aliases defined; set to Default Aliases, if any' );
484
+ }
485
+
486
+ /* Rebuild all ['prep'] entries, if required.
487
+ */
488
+ if ( isset( $rebuild_prep ) ) {
489
+ $settings = jr_mt_rebuild_prep( $settings );
490
+ jr_mt_messages( 'URL settings, if any, have had their URL matching structures rebuilt' );
491
+ }
492
+ } else {
493
+ $settings = jr_mt_default_settings();
494
+ jr_mt_messages( 'First use (or after plugin deleted): initialize Plugin Settings', 'immediate' );
495
+ }
496
+ if ( $settings !== $settings_original ) {
497
+ if ( update_option( 'jr_mt_settings', $settings ) ) {
498
+ jr_mt_messages( 'Plugin Settings have changed and were successfully updated', 'immediate' );
499
+ } else {
500
+ jr_mt_messages( 'Plugin Settings have changed but could not be updated', 'immediate' );
501
+ }
502
+ }
503
+ jr_mt_messages( NULL, 'display' );
504
+ jr_mt_messages( 'Check complete', 'immediate' );
505
+ ?>
506
+ </ul>
507
+ <p>
508
+ While every attempt has been made,
509
+ in the Settings Check above,
510
+ to ensure that the plugin's
511
+ Setting are valid,
512
+ if you experience any unexpected behaviour,
513
+ you should try to re-create the Settings from scratch.
514
+ First, re-initialize all Settings to their defaults,
515
+ by deactivating, deleting, installing and reactivating this plugin;
516
+ then visit this Settings page again,
517
+ as this is where the Settings are initialized.
518
+ </p>
519
+ <?php
520
+ jr_mt_admin_init();
521
+
522
+ echo '<form action="options.php" method="POST">';
523
+ $permalink = get_option( 'permalink_structure' );
524
+ if ( isset( $internal_settings['permalink'] ) ) {
525
+ if ( $internal_settings['permalink'] !== $permalink ) {
526
+ /* Permalink Structure has been changed.
527
+ */
528
+ if ( empty( $settings['url'] ) && empty( $settings['url_prefix'] ) && empty( $settings['url_asterisk'] ) ) {
529
+ $update = TRUE;
530
+ } else {
531
+ ?>
532
+ <p>
533
+ Permalink Structure has been changed.
534
+ In the
535
+ <b>
536
+ Current Theme Selection Entries
537
+ </b>
538
+ Section just below,
539
+ please review all
540
+ URL=,
541
+ URL Prefix=
542
+ and
543
+ URL Prefix*=
544
+ entries,
545
+ as they may need to be changed to reflect the new Permalink Structure.
546
+ <br />
547
+ <input type="checkbox" id="permalink" name="jr_mt_settings[permalink]" value="true" />
548
+ Dismiss Warning
549
+ </p>
550
+ <?php
551
+ $update = FALSE;
552
+ }
553
+ } else {
554
+ $update = FALSE;
555
+ }
556
+ } else {
557
+ /* Permalink Internal Setting for Plugin not set,
558
+ so initialize it to current Permalink Structure.
559
+ */
560
+ $update = TRUE;
561
+ }
562
+ if ( $update ) {
563
+ $internal_settings['permalink'] = $permalink;
564
+ update_option( 'jr_mt_internal_settings', $internal_settings );
565
+ }
566
+ ?>
567
+ <h3>Overview</h3>
568
+ <p>This Plugin allows you to selectively display Themes on your web site
569
+ other than the Theme shown as
570
+ <b>
571
+ Active
572
+ </b>
573
+ on
574
+ <b>
575
+ Appearance-Themes
576
+ </b>
577
+ in the WordPress Admin panels.
578
+ </p>
579
+ <p>
580
+ Below,
581
+ Theme Selection entries can be created
582
+ where each Entry specifies which of the installed themes shown on the Appearance-Themes Admin panel will be applied to:
583
+ <ul class="jrmtpoints">
584
+ <li>The Site Home</li>
585
+ <li>An exact URL of any non-Admin page on this WordPress Site</li>
586
+ <li>One or more URLs that begin with the partial URL you specify ("URL Prefix")</li>
587
+ <li>One or more URLs that begin with the wildcard URL you specify ("URL Prefix*")</li>
588
+ <li>Any URL containing a Specific Query Keyword (<code>?keyword</code> or <code>&keyword</code>)</li>
589
+ <li>Any URL containing a Specific Query Keyword/Value pair (<code>?keyword=value</code> or <code>&keyword=value</code>)</li>
590
+ <li>For the same site visitor, all non-Admin pages after a <b>Sticky</b> Query Keyword/Value pair is specified in any URL (Advanced Settings tab)</li>
591
+ <li>All Pages (Advanced Settings tab)</li>
592
+ <li>All Posts (Advanced Settings tab)</li>
593
+ <li>Everything else, except what is specified above (Advanced Settings tab)</li>
594
+ </ul>
595
+ </p>
596
+ <h3>Important Notes</h3>
597
+ <?php
598
+ if ( function_exists('is_multisite') && is_multisite() ) {
599
+ 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.";
600
+ }
601
+ echo '<p>';
602
+ echo "The Active Theme, defined to WordPress in the Appearance-Themes admin panel, is <b>$theme</b>.";
603
+ if ( trim( $settings['current'] ) ) {
604
+ echo " But it is being overridden by the Theme for Everything setting (see Advanced Settings tab), which set the plugin's default Theme to <b>";
605
+ echo wp_get_theme( $settings['current'] )->Name;
606
+ 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 Active Theme wherever you want it to appear. Or, if you specify, on the Advanced Settings tab, 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.';
607
+ } else {
608
+ 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, on the Advanced Settings tab, a different Theme for All Pages, All Posts or Everything, and wish to use the Active Theme for one or more specific Pages, Posts or other non-Admin pages.';
609
+ }
610
+ echo '</p>';
611
+
612
+ if ( jr_mt_plugin_update_available() ) {
613
+ echo '<p>A new version of this Plugin (' . $jr_mt_plugin_data['Name'] . ') is available from the WordPress Repository.'
614
+ . ' Updating as quickly as possible is strongly recommend because new versions fix problems that users like you have already reported.'
615
+ . ' <a class="thickbox" title="' . $jr_mt_plugin_data['Name'] . '" href="' . network_admin_url()
616
+ . 'plugin-install.php?tab=plugin-information&plugin=' . $jr_mt_plugin_data['slug']
617
+ . '&section=changelog&TB_iframe=true&width=640&height=768">Click here</a> for more details.</p>';
618
+ }
619
+ ?>
620
+ <p>
621
+ If a newly-added Theme Selection does not seem to be working,
622
+ especially if the associated web page does not display properly,
623
+ try deactivating any plugins that provide Caching.
624
+ You may find that you have to flush the plugin's Cache whenever you add or change a Theme Selection setting.
625
+ Also note that some Caching plugins only cache for visitors who are not logged in,
626
+ so be sure to check your site after logging out.
627
+ </p>
628
+ <p>
629
+ Need more help?
630
+ Please click on the
631
+ <a href="#" onClick="jrMtTabs( 6, 6 );">Help tab</a>
632
+ above
633
+ for more information.
634
+ </p>
635
+ <hr />
636
+ <?php
637
+
638
+ // Plugin Settings are displayed and entered here:
639
+ settings_fields( 'jr_mt_settings' );
640
+ do_settings_sections( 'jr_mt_settings_page' );
641
+ echo '<p><input name="jr_mt_settings[tab3]" type="submit" value="Save All Changes" class="button-primary" /></p></form>';
642
+ }
643
+
644
+ ?>
645
+ </div>
646
+ <div id="jr-mt-settings4" style="display: none;">
647
+ <h3>
648
+ Theme Options and Template Selection
649
+ </h3>
650
+ <p>
651
+ This tab provides information on changing Theme Options
652
+ (Widgets, Sidebars, Menus, Background, Header, etc.)
653
+ for all the different Themes used on a WordPress site.
654
+ </p>
655
+ <p>
656
+ Information on changing the Template for each Page or Post
657
+ is found near the bottom of this tab.
658
+ </p>
659
+ <h3>
660
+ Changing Theme Options
661
+ </h3>
662
+ <p>
663
+ For the Active Theme, nothing changes when using the jonradio Multiple Themes plugin.
664
+ Options for the Active Theme,
665
+ including Widgets, Sidebars, Menus, Background, Header and other Customizations supported by the Theme,
666
+ can be modified in the Admin panel using the Appearance menu items on the left sidebar.
667
+ Some Themes also provide their own menu items in the left sidebar of the Admin panel,
668
+ and these will still appear for the Active Theme when using this plugin.
669
+ </p>
670
+ <p>
671
+ It is more difficult to modify Options for installed Themes that are not the WordPress Active Theme.
672
+ Building this functionality into this plugin is in the plans for a future Version,
673
+ but it is not clear just how practical that is, so the best that can be said is:
674
+ <i>
675
+ Maybe</i>.
676
+ </p>
677
+ <p>
678
+ For now, there are three approaches that can be used to change Options for an installed Theme that is not the Active Theme.
679
+ The first works best if only one Theme has a lot of Options that need to be changed frequently:
680
+ </p>
681
+ <ol>
682
+ <li>
683
+ Make that Theme the Active Theme defined in the Appearance-Themes WordPress admin panel;
684
+ </li>
685
+ <li>
686
+ If that meant changing the Active Theme,
687
+ the previous Active Theme can be selected on the plugin's
688
+ <b>
689
+ Advanced Settings
690
+ </b>
691
+ tab
692
+ in the
693
+ <b>
694
+ Select Theme for Everything
695
+ </b>
696
+ field
697
+ and it will be used everywhere except where you have specified
698
+ another Theme in the Theme Selection entries for this plugin.
699
+ </li>
700
+ </ol>
701
+ <p>
702
+ For other situations,
703
+ two multi-step Methods are available,
704
+ and are described in the two Sections below.
705
+ Both Methods work for most Theme Options,
706
+ with the following exceptions:
707
+ </p>
708
+ <ol>
709
+ <li>
710
+ Menus really work well with Method #1,
711
+ but are severely restricted with Method #2;
712
+ </li>
713
+ <li>
714
+ Widgets normally only work with Method #2;
715
+ </li>
716
+ <li>
717
+ Using both Methods may cause conflicts;
718
+ </li>
719
+ <li>
720
+ No matter which Method you choose,
721
+ you may lose previously-set Theme Options.
722
+ A Backup and Recovery of your WordPress Database
723
+ would be required to avoid such a loss.
724
+ </li>
725
+ </ol>
726
+ <h4>
727
+ <u>
728
+ Method #1</u>:
729
+ Set the Theme Options with Live Preview.
730
+ </h4>
731
+ <p>
732
+ Note: Widgets cannot be placed using this Method.
733
+ </p>
734
+ <ol>
735
+ <li>
736
+ Go to Appearance-Themes in the WordPress Admin panels.
737
+ </li>
738
+ <li>
739
+ Mouse over the Theme that you wish to change
740
+ and click the Live Preview button that appears.
741
+ </li>
742
+ <li>
743
+ Use the left sidebar to modify the Theme Options.
744
+ Note that
745
+ <b>
746
+ Navigation
747
+ </b>
748
+ will not appear in the Live Preview sidebar until a Menu has been defined in Appearance-Menus.
749
+ Navigation is where you would set the custom menu(s) to be used for the Theme you are currently previewing.
750
+ </li>
751
+ <li>
752
+ Click the Save & Activate button.
753
+ </li>
754
+ <li>
755
+ Go immediately to Appearance-Themes in the WordPress Admin panels.
756
+ </li>
757
+ <li>
758
+ Mouse over the Theme that had previously been the Active Theme
759
+ and click the Activate button that appears
760
+ to reactivate the Active Theme.
761
+ </li>
762
+ </ol>
763
+ <h4>
764
+ <u>
765
+ Method #2</u>:
766
+ Use the Theme Test Drive plugin.
767
+ </h4>
768
+ <p>
769
+ 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.
770
+ </p>
771
+ <p>
772
+ The jonradio Multiple Themes plugin (i.e. - this plugin) must be Deactivated,
773
+ and the Theme Test Drive plugin installed and activated.
774
+ This enables each Theme to be selected with the Theme Test Drive plugin,
775
+ allowing the Theme's Options to be set
776
+ <i>
777
+ as if
778
+ </i>
779
+ it were the Active Theme.
780
+ </p>
781
+ <ol>
782
+ <li>
783
+ Deactivate the jonradio Multiple Themes plugin.
784
+ </li>
785
+ <li>
786
+ Install the Theme Test Drive plugin found at
787
+ <a target="_blank" href="http://wordpress.org/plugins/theme-test-drive/">http://wordpress.org/plugins/theme-test-drive/</a>.
788
+ </li>
789
+ <li>
790
+ Activate the Theme Test Drive plugin.
791
+ </li>
792
+ <li>
793
+ Go to
794
+ <b>
795
+ Appearance-Theme Test Drive
796
+ </b>
797
+ in the WordPress Admin panels.
798
+ </li>
799
+ <li>
800
+ In the Usage section, select a Theme whose Options you wish to change.
801
+ </li>
802
+ <li>
803
+ Push the Enable Theme Drive button at the bottom of the Admin panel.
804
+ </li>
805
+ <li>
806
+ 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
807
+ using the Appearance submenu
808
+ in the WordPress Admin panels,
809
+ just as you would for the Active Theme.
810
+ </li>
811
+ <li>
812
+ If more than one Theme has Options that need changing, repeat Steps 4-8 for each Theme
813
+ (except the Active Theme,
814
+ which should be only changed
815
+ <i>
816
+ without
817
+ </i>
818
+ the Theme Test Drive plugin activated).
819
+ </li>
820
+ <li>
821
+ Deactivate the Theme Test Drive plugin.
822
+ </li>
823
+ <li>
824
+ Activate this plugin (jonradio Multiple Themes).
825
+ </li>
826
+ <li>
827
+ Changes to the Options for the Active Theme can now be made normally, just as you would without either plugin.
828
+ </li>
829
+ <li>
830
+ Both the alternate and Active Themes should now display all Theme options properly when selected through the jonradio Multiple Themes plugin.
831
+ </li>
832
+ </ol>
833
+ <h3>
834
+ Changing Templates
835
+ </h3>
836
+ <p>
837
+ Many Themes provide more than one Template.
838
+ For each Page or Post, you can select the Template you want to use for that Page or Post.
839
+ </p>
840
+ <p>
841
+ For the Active Theme, nothing changes when using the jonradio Multiple Themes plugin.
842
+ 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.
843
+ Or the Template field in Quick Edit.
844
+ </p>
845
+ <p>
846
+ It is more difficult to change Templates for Pages or Posts defined with the jonradio Multiple Themes plugin to use Installed Themes that are not the Active Theme.
847
+ Building this functionality into this plugin is in the plans for a future Version.
848
+ </p>
849
+ <p>
850
+ Use the Theme Test Drive plugin.
851
+ The jonradio Multiple Themes plugin (i.e. - this plugin) must be Deactivated, and the Theme Test Drive plugin installed and activated,
852
+ so that each Theme can be selected with the Theme Test Drive plugin,
853
+ allowing the Theme's Template to be set for each Page or Post using that Theme
854
+ <i>
855
+ as if
856
+ </i>
857
+ it were the Active Theme.
858
+ </p>
859
+ <ol>
860
+ <li>
861
+ Deactivate the jonradio Multiple Themes plugin.
862
+ </li>
863
+ <li>
864
+ Install the Theme Test Drive plugin found at
865
+ <a target="_blank" href="http://wordpress.org/plugins/theme-test-drive/">http://wordpress.org/plugins/theme-test-drive/</a>.
866
+ </li>
867
+ <li>
868
+ Activate the Theme Test Drive plugin.
869
+ </li>
870
+ <li>
871
+ Go to
872
+ <b>
873
+ Appearance-Theme Test Drive
874
+ </b>
875
+ in the WordPress Admin panels.
876
+ </li>
877
+ <li>
878
+ In the Usage section, select a Theme whose Templates need to be changed for a Post or Page.
879
+ </li>
880
+ <li>
881
+ Push the Enable Theme Drive button at the bottom of the Admin panel.
882
+ </li>
883
+ <li>
884
+ Go to Posts-All Posts or Pages-All Pages in the WordPress Admin panels.
885
+ </li>
886
+ <li>
887
+ For each Page or Post where a Template needs to be changed for this Theme,
888
+ mouse over the Page or Post title and click on Quick Edit.
889
+ </li>
890
+ <li>
891
+ Change the Template field.
892
+ </li>
893
+ <li>
894
+ Click the Update button.
895
+ </li>
896
+ <li>
897
+ Repeat Steps 8-10 for each Page or Post that requires a change to Template for this Theme.
898
+ </li>
899
+ <li>
900
+ If more than one Theme has Pages or Posts with Templates that need to be changed,
901
+ repeat Steps 4-11 for each Theme
902
+ (except the Active Theme,
903
+ where Template changes should only be made
904
+ <i>
905
+ without
906
+ </i>
907
+ the Theme Test Drive plugin activated).
908
+ </li>
909
+ <li>
910
+ Deactivate the Theme Test Drive plugin.
911
+ </li>
912
+ <li>
913
+ Activate this plugin (jonradio Multiple Themes).
914
+ </li>
915
+ <li>
916
+ Changing Templates for the Active Theme can now be made normally, just as you would without either plugin.
917
+ </li>
918
+ <li>
919
+ Both the alternate and Active Themes should now display the correct Template when selected through the jonradio Multiple Themes plugin.
920
+ </li>
921
+ </ol>
922
+ </div>
923
+ <div id="jr-mt-settings5" style="display: none;">
924
+ <h3>
925
+ System Information
926
+ </h3>
927
+ <p>
928
+ WordPress DEBUG mode is currently turned
929
+ <?php
930
+ if ( TRUE === WP_DEBUG ) {
931
+ echo 'on';
932
+ } else {
933
+ echo 'off';
934
+ }
935
+ echo ". It is controlled by the <code>define('WP_DEBUG', true);</code> statement near the bottom of <code>"
936
+ . ABSPATH
937
+ . 'wp-config.php</code></p>';
938
+ $posix = function_exists( 'posix_uname' );
939
+ echo '<p>You are currently running:<ul class="jrmtpoints">'
940
+ . "<li>The {$jr_mt_plugin_data['Name']} plugin Version {$jr_mt_plugin_data['Version']}</li>"
941
+ . '<ul class="jrmtpoints">' . "<li>The Path to the plugin's directory is <code>" . rtrim( jr_mt_path(), '/' ) . '</code></li>'
942
+ . "<li>The URL to the plugin's directory is <code>" . plugins_url() . "/{$jr_mt_plugin_data['slug']}</code></li></ul>"
943
+ . "<li>The Active Theme is $theme Version $theme_version</li>"
944
+ . '<ul class="jrmtpoints">'
945
+ . "<li>The Path to the Active Theme's stylesheet directory is <code>" . get_stylesheet_directory() . '</code></li>'
946
+ . "<li>The Path to the Active Theme's template directory is <code>" . get_template_directory() . '</code></li></ul>'
947
+ . '<li>Site Address (URL) is <code>' . JR_MT_HOME_URL . '</code></li>'
948
+ . '<li>WordPress Address (URL) is <code>' . site_url() . '</code></li>';
949
+ $permalink = get_option( 'permalink_structure' );
950
+ if ( empty( $permalink ) ) {
951
+ $permalink = 'Default (Query <code>/?p=123</code>)';
952
+ } else {
953
+ $permalink = "<code>$permalink</code>";
954
+ }
955
+ echo "<li>The current Permalink Structure is $permalink";
956
+ echo "<li>WordPress Version $current_wp_version</li>";
957
+ echo '<ul class="jrmtpoints"><li>WordPress language is set to ' , get_bloginfo( 'language' ) . '</li></ul>';
958
+ echo '<li>' . php_uname( 's' ) . ' operating system, Release/Version ' . php_uname( 'r' ) . ' / ' . php_uname( 'v' ) . '</li>';
959
+ if ( $posix ) {
960
+ $array = posix_getpwuid( posix_getuid() );
961
+ $user = $array['name'];
962
+ echo "<li>Real operating system User ID that runs WordPress is $user</li>";
963
+ $array = posix_getpwuid( posix_geteuid() );
964
+ $user = $array['name'];
965
+ echo "<li>Effective operating system User ID that runs WordPress is $user</li>";
966
+ }
967
+ echo '<li>' . php_uname( 'm' ) . ' computer hardware</li>';
968
+ echo '<li>Host name ' . php_uname( 'n' ) . '</li>';
969
+ echo '<li>php Version ' . phpversion() . '</li>';
970
+ echo '<ul class="jrmtpoints"><li>php memory_limit ' . ini_get('memory_limit') . '</li>';
971
+ if ( !$posix ) {
972
+ echo '<li>POSIX functions are not available</li>';
973
+ }
974
+ echo '</ul><li>Zend engine Version ' . zend_version() . '</li>';
975
+ echo '<li>Web Server software is ' . getenv( 'SERVER_SOFTWARE' ) . '</li>';
976
+ if ( function_exists( 'apache_get_version' ) && ( FALSE !== $apache = apache_get_version() ) ) {
977
+ echo '<ul class="jrmtpoints"><li>Apache Version' . "$apache</li></ul>";
978
+ }
979
+ global $wpdb;
980
+ echo '<li>MySQL Version ' . $wpdb->get_var( 'SELECT VERSION();', 0, 0 ) . '</li>';
981
+
982
+ echo '</ul></p>';
983
+
984
+ $paths = array(
985
+ '/..',
986
+ '/',
987
+ '/wp-content/',
988
+ '/wp-content/plugins/',
989
+ '/wp-content/plugins/' . dirname( jr_mt_plugin_basename() ),
990
+ '/wp-content/plugins/' . dirname( jr_mt_plugin_basename() ) . '/readme.txt'
991
+ );
992
+ echo '<h3>File Permissions</h3><p>All of the Paths shown below are relative to the WordPress Site Path <code>'
993
+ . ABSPATH
994
+ . '</code><br />The first ("/..") is the Parent Directory <code>'
995
+ . dirname( ABSPATH )
996
+ . '/</code> and the second ("/") is the WordPress Site Path itself.</p><table class="widefat"><thead><tr><th>Path</th><th>Type</th><th>Read</th><th>Write</th>';
997
+ if ( $posix ) {
998
+ echo '<th>Owner</th><th>Group</th>';
999
+ }
1000
+ echo '</tr></thead><tbody>';
1001
+ foreach ( $paths as $path ) {
1002
+ $full_path = ABSPATH . jr_mt_substr( $path, 1 );
1003
+ if ( is_dir( $full_path ) ) {
1004
+ $type = 'Directory';
1005
+ } else {
1006
+ $type = 'File';
1007
+ }
1008
+ if ( is_readable( $full_path ) ) {
1009
+ $read = 'Yes';
1010
+ } else {
1011
+ $read = 'No';
1012
+ }
1013
+ if ( is_writeable( $full_path ) ) {
1014
+ $write = 'Yes';
1015
+ } else {
1016
+ $write = 'No';
1017
+ }
1018
+ if ( $posix ) {
1019
+ if ( FALSE === ( $uid = fileowner( $full_path ) ) ) {
1020
+ $user = '-';
1021
+ $group = '-';
1022
+ } else {
1023
+ $array = posix_getpwuid( $uid );
1024
+ $user = $array['name'];
1025
+ $array = posix_getgrgid( filegroup( $full_path ) );
1026
+ $group = $array['name'];
1027
+ }
1028
+ }
1029
+ echo "<tr><td>$path</td><td>$type</td><td>$read</td><td>$write</td>";
1030
+ if ( $posix ) {
1031
+ echo "<td>$user</td><td>$group</td>";
1032
+ }
1033
+ echo '<tr>';
1034
+ }
1035
+ echo '</tbody></table>';
1036
+ ?>
1037
+ </div>
1038
+ <div id="jr-mt-settings6" style="display: none;">
1039
+ <h3>
1040
+ An Alternative to This Plugin
1041
+ </h3>
1042
+ <p>
1043
+ WordPress was not designed with the idea in mind of multiple Themes on a single Site.
1044
+ Which is why this plugin struggles to provide full multi-theme capabilities.
1045
+ </p>
1046
+ <p>
1047
+ An alternative to this plugin
1048
+ is a
1049
+ <a href="http://codex.wordpress.org/Create_A_Network">WordPress Network</a>,
1050
+ also known as Multisite.
1051
+ Each WordPress Site within a WordPress Network can have a different Theme.
1052
+ WordPress was built to fully support Multiple Themes used in this way.
1053
+ </p>
1054
+ <p>
1055
+ What is less obvious,
1056
+ is that a WordPress Network of Sites
1057
+ can be designed to appear as if it is a single integrated web site.
1058
+ For example,
1059
+ using the Subdirectory option of a WordPress Network:
1060
+ </p>
1061
+ <ol>
1062
+ <li>
1063
+ Site 1 could be
1064
+ <code>example.com</code>,
1065
+ the web site's home page,
1066
+ and any other web pages with the same Theme;
1067
+ </li>
1068
+ <li>
1069
+ Site 2 could be
1070
+ <code>example.com/forum</code>,
1071
+ the discussion forum portion of your web site
1072
+ with a different Theme;
1073
+ </li>
1074
+ <li>
1075
+ Site 3 could be
1076
+ <code>example.com/news</code>
1077
+ for a News section with its own Theme;
1078
+ and
1079
+ </li>
1080
+ <li>
1081
+ Site 4 could be
1082
+ <code>example.com/store</code>
1083
+ with a fourth Theme for a Store.
1084
+ </li>
1085
+ </ol>
1086
+ <p>
1087
+ Admittedly,
1088
+ extra effort will be required to make a WordPress Network look like a single web site,
1089
+ especially if you rely on automatically-created Menus.
1090
+ Menu entries will have to be manually created to point to other Sites within the WordPress Network.
1091
+ </p>
1092
+ <h3>
1093
+ Need Help?
1094
+ </h3>
1095
+ <p>
1096
+ Need help with this plugin?
1097
+ Check the
1098
+ <a href="#" onClick="jrMtTabs( 4, 6 );">Theme Options</a>
1099
+ and
1100
+ <a href="#" onClick="jrMtTabs( 5, 6 );">System Information</a>
1101
+ tabs above,
1102
+ and the
1103
+ <a target="_blank" href="http://wordpress.org/plugins/jonradio-multiple-themes/">Description</a>,
1104
+ <a target="_blank" href="http://wordpress.org/plugins/jonradio-multiple-themes/faq/">FAQ</a>,
1105
+ <a target="_blank" href="http://wordpress.org/plugins/jonradio-multiple-themes/installation/">Installation</a>
1106
+ and
1107
+ <a target="_blank" href="http://wordpress.org/support/plugin/jonradio-multiple-themes">Support</a>
1108
+ tabs
1109
+ in the <a target="_blank" href="http://wordpress.org/plugins/jonradio-multiple-themes/">WordPress Directory entry for this plugin</a>.
1110
+ All of this information is based on the many support questions that jonradio has answered both on-line and via e-mail since this plugin was first released in 2012.
1111
+ </p>
1112
+ <p>
1113
+ Please be sure to check them all out if you have any unanswered questions.
1114
+ If you cannot find the answers to all of your questions there,
1115
+ simply post your question in the
1116
+ <a target="_blank" href="http://wordpress.org/support/plugin/jonradio-multiple-themes">Support Forum</a>
1117
+ or
1118
+ <a target="_blank" href="http://zatzlabs.com/contact-us/">contact jonradio directly</a>.
1119
+ </p>
1120
+ <p>
1121
+ For information on other jonradio plugins,
1122
+ including Contact and Donation information,
1123
+ <a target="_blank" href="http://zatzlabs.com/plugins/">click here</a>.
1124
+ </p>
1125
+ <h3>
1126
+ Want to Help?
1127
+ </h3>
1128
+ <p>
1129
+ As well as <a target="_blank" href="http://zatzlabs.com/plugins/">Donations</a>,
1130
+ you can also help by
1131
+ <a target="_blank" href="http://wordpress.org/support/view/plugin-reviews/jonradio-multiple-themes">Reviewing this plugin</a>
1132
+ for the WordPress Plugin Directory,
1133
+ and telling other people that it works for your particular combination of Plugin version and WordPress version
1134
+ in the Compability section of the
1135
+ <a target="_blank" href="http://wordpress.org/plugins/jonradio-multiple-themes/">WordPress Directory entry for this plugin</a>.
1136
+ </p>
1137
+ </div>
1138
+
1139
+ </div>
1140
+ <?php
1141
+ /* </div> ends the <div class="wrap"> at the beginning
1142
+ */
1143
+ }
1144
+
1145
+ require_once( jr_mt_path() . 'includes/admin-sections.php' );
1146
+ require_once( jr_mt_path() . 'includes/admin-validate.php' );
1147
+
1148
+ ?>
includes/functions.php ADDED
@@ -0,0 +1,693 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* Exit if .php file accessed directly
4
+ */
5
+ if ( !defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ global $jr_mt_path;
10
+ $jr_mt_path = plugin_dir_path( JR_MT_FILE );
11
+ /**
12
+ * Return Plugin's full directory path with trailing slash
13
+ *
14
+ * Local XAMPP install might return:
15
+ * C:\xampp\htdocs\wpbeta\wp-content\plugins\jonradio-multiple-themes/
16
+ *
17
+ */
18
+ function jr_mt_path() {
19
+ global $jr_mt_path;
20
+ return $jr_mt_path;
21
+ }
22
+
23
+ global $jr_mt_plugin_basename;
24
+ $jr_mt_plugin_basename = plugin_basename( JR_MT_FILE );
25
+ /**
26
+ * Return Plugin's Basename
27
+ *
28
+ * For this plugin, it would be:
29
+ * jonradio-multiple-themes/jonradio-multiple-themes.php
30
+ *
31
+ */
32
+ function jr_mt_plugin_basename() {
33
+ global $jr_mt_plugin_basename;
34
+ return $jr_mt_plugin_basename;
35
+ }
36
+
37
+ if ( !function_exists( 'get_plugin_data' ) ) {
38
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
39
+ }
40
+
41
+ global $jr_mt_plugin_data;
42
+ $jr_mt_plugin_data = get_plugin_data( JR_MT_FILE );
43
+ $jr_mt_plugin_data['slug'] = basename( dirname( JR_MT_FILE ) );
44
+
45
+ global $jr_mt_options_cache;
46
+ $all_options = wp_load_alloptions();
47
+ $jr_mt_options_cache['stylesheet'] = $all_options['stylesheet'];
48
+ $jr_mt_options_cache['template'] = $all_options['template'];
49
+
50
+ /* Handle this Odd Situation:
51
+ For WordPress 4.0 and all previous versions,
52
+ wp_get_themes() returns array() when this plugin is Network Activated.
53
+ Waiting until Action 'plugins_loaded' overcomes this problem,
54
+ but potentially creates other problems.
55
+ */
56
+ if ( is_plugin_active_for_network( $jr_mt_plugin_basename ) ) {
57
+ add_action( JR_MT_WP_GET_THEMES_ACTION, 'jr_mt_wp_get_themes_fix', JR_MT_RUN_FIRST );
58
+ function jr_mt_wp_get_themes_fix() {
59
+ DEFINE( 'JR_MT_WP_GET_THEMES_WORKS', TRUE );
60
+ /* Force the next request for Stylesheet or Template
61
+ to process the Theme Selection logic,
62
+ even if previous requests have cached the Theme.
63
+ */
64
+ unset( $GLOBALS['jr_mt_theme'] );
65
+ if ( is_admin() ) {
66
+ global $jr_mt_all_themes_cache;
67
+ $jr_mt_all_themes_cache = wp_get_themes();
68
+ update_option( 'jr_mt_all_themes', $jr_mt_all_themes_cache );
69
+ }
70
+ }
71
+ } else {
72
+ DEFINE( 'JR_MT_WP_GET_THEMES_WORKS', TRUE );
73
+ }
74
+ function jr_mt_all_themes() {
75
+ if ( defined( 'JR_MT_WP_GET_THEMES_WORKS' ) ) {
76
+ global $jr_mt_all_themes_cache;
77
+ if ( isset( $jr_mt_all_themes_cache ) ) {
78
+ $return = $jr_mt_all_themes_cache;
79
+ } else {
80
+ $return = wp_get_themes();
81
+ }
82
+ } else {
83
+ /* Probably not valid,
84
+ typically empty array.
85
+ Better to store and retrieve from Settings myself.
86
+ */
87
+ if ( FALSE === ( $return = get_option( 'jr_mt_all_themes' ) ) ) {
88
+ $return = wp_get_themes();
89
+ }
90
+ }
91
+ return $return;
92
+ }
93
+
94
+ /**
95
+ * Check for missing Settings and set them to defaults
96
+ *
97
+ * Ensures that the Named Setting exists, and populates it with defaults for any missing values.
98
+ * Safe to use on every execution of a plugin because it only does an expensive Database Write
99
+ * when it finds missing Settings.
100
+ *
101
+ * Does not delete any key not found in $defaults.
102
+ *
103
+ * @param string $name Name of Settings as looked up with get_option()
104
+ * @param array $defaults Each default Settings value in [key] => value format
105
+ * @return bool/Null Return value from update_option(), or NULL if update_option() not called
106
+ */
107
+ function jr_mt_missing_settings( $name, $defaults ) {
108
+ $updated = FALSE;
109
+ if ( FALSE === ( $settings = get_option( $name ) ) ) {
110
+ $settings = $defaults;
111
+ $updated = TRUE;
112
+ } else {
113
+ foreach ( $defaults as $key => $value ) {
114
+ if ( !isset( $settings[$key] ) ) {
115
+ $settings[$key] = $value;
116
+ $updated = TRUE;
117
+ }
118
+ }
119
+ }
120
+ if ( $updated ) {
121
+ $return = update_option( $name, $settings );
122
+ } else {
123
+ $return = NULL;
124
+ }
125
+ return $return;
126
+ }
127
+
128
+ /* As well as dealing with the low probability that a single mb_ function has been disabled in a php.ini,
129
+ this also supports older versions of PHP as mb_ functions were introduced one by one over a number of php versions.
130
+ */
131
+ if ( function_exists( 'mb_substr' ) ) {
132
+ function jr_mt_substr() {
133
+ $args = func_get_args();
134
+ if ( isset( $args[2] ) ) {
135
+ return mb_substr( $args[0], $args[1], $args[2] );
136
+ } else {
137
+ return mb_substr( $args[0], $args[1] );
138
+ }
139
+ }
140
+ } else {
141
+ function jr_mt_substr() {
142
+ $args = func_get_args();
143
+ if ( isset( $args[2] ) ) {
144
+ return substr( $args[0], $args[1], $args[2] );
145
+ } else {
146
+ return substr( $args[0], $args[1] );
147
+ }
148
+ }
149
+ }
150
+ if ( function_exists( 'mb_strlen' ) ) {
151
+ function jr_mt_strlen( $string ) {
152
+ return mb_strlen( $string );
153
+ }
154
+ } else {
155
+ function jr_mt_strlen( $string ) {
156
+ return strlen( $string );
157
+ }
158
+ }
159
+ if ( function_exists( 'mb_strtolower' ) ) {
160
+ function jr_mt_strtolower( $string ) {
161
+ return mb_strtolower( $string );
162
+ }
163
+ } else {
164
+ function jr_mt_strtolower( $string ) {
165
+ return strtolower( $string );
166
+ }
167
+ }
168
+
169
+ /**
170
+ * Return WordPress Current Theme, as defined in Appearance Admin panels
171
+ *
172
+ * Obtains Folder Name of Current Theme, from 'template' option of wp_load_alloptions().
173
+ *
174
+ * @param string $option parameter to select current template or stylesheet
175
+ * @return string type Folder Name of Current Theme
176
+ */
177
+ function jr_mt_current_theme( $option ) {
178
+ global $jr_mt_options_cache;
179
+ return $jr_mt_options_cache[$option];
180
+ }
181
+
182
+ /**
183
+ * What Themes are defined to Plugin?
184
+ *
185
+ * @return arr - a list of Themes (folder names) defined in Settings of Plugin, plus Active WordPress Theme
186
+ **/
187
+ function jr_mt_themes_defined() {
188
+ $themes = array( jr_mt_current_theme( 'stylesheet' ), jr_mt_current_theme( 'template' ) );
189
+ $settings = get_option( 'jr_mt_settings' );
190
+ foreach ( $settings as $key => $value ) {
191
+ switch ( $key ) {
192
+ case 'url':
193
+ case 'url_prefix':
194
+ case 'url_asterisk':
195
+ foreach ( $value as $arr ) {
196
+ $themes[] = $arr['theme'];
197
+ }
198
+ break;
199
+ case 'query':
200
+ foreach ( $value as $keyword => $arr1 ) {
201
+ foreach ( $arr1 as $value => $theme ) {
202
+ $themes[] = $theme;
203
+ }
204
+ }
205
+ break;
206
+ case 'all_pages':
207
+ case 'all_posts':
208
+ case 'site_home':
209
+ case 'current':
210
+ if ( !empty( $value ) ) {
211
+ $themes[] = $value;
212
+ }
213
+ break;
214
+ }
215
+ }
216
+ return array_unique( $themes );
217
+ }
218
+
219
+ /**
220
+ * Do two URLs point at the same location on a web site?
221
+ *
222
+ * Preps URL, if string
223
+ *
224
+ * @param string/array $url1 URL to compare, a string, or an array in special format created by companion function
225
+ * @param string/array $url2 URL to compare, a string, or an array in special format created by companion function
226
+ * @return bool bool TRUE if URL matches prefix; FALSE otherwise
227
+ */
228
+ function jr_mt_same_url( $url1, $url2 ) {
229
+ if ( is_string( $url1 ) ) {
230
+ $url1 = jr_mt_prep_url( $url1 );
231
+ }
232
+ if ( is_string( $url2 ) ) {
233
+ $url2 = jr_mt_prep_url( $url2 );
234
+ }
235
+ return ( $url1 == $url2 );
236
+ }
237
+
238
+ /**
239
+ * Does a specified Prefix URL match the given URL?
240
+ *
241
+ * Preps URL, if string.
242
+ * Note: parameters MUST be in the right order
243
+ *
244
+ * @param string/array $prefix front part of a URL to compare, a string, or an array in special format created by companion function
245
+ * @param string/array $url full URL to compare, a string, or an array in special format created by companion function
246
+ * @return bool bool TRUE if Prefix matches first part of URL; FALSE otherwise
247
+ */
248
+ function jr_mt_same_prefix_url( $prefix, $url ) {
249
+ if ( is_string( $prefix ) ) {
250
+ $prefix = jr_mt_prep_url( $prefix );
251
+ }
252
+ if ( is_string( $url ) ) {
253
+ $url = jr_mt_prep_url( $url );
254
+ }
255
+ if ( $url['host'] === $prefix['host'] ) {
256
+ if ( $url['port'] === $prefix['port'] ) {
257
+ if ( $url['path'] === $prefix['path'] ) {
258
+ /* Host and Path both exactly match for URL and Prefix specified.
259
+ */
260
+ if ( array() === $prefix['query'] ) {
261
+ $match = TRUE;
262
+ } else {
263
+ /* Now the hard part: determining a legitimate prefix match for Query
264
+ */
265
+ foreach ( $prefix['query'] as $prefix_keyword => $prefix_value_array ) {
266
+ foreach ( $prefix_value_array as $prefix_value => $prefix_equalsign ) {
267
+ $one_match = FALSE;
268
+ foreach ( $url['query'] as $url_keyword => $url_value_array ) {
269
+ foreach( $url_value_array as $url_value => $url_equalsign ) {
270
+ if ( jr_mt_substr( $url_keyword, 0, jr_mt_strlen( $prefix_keyword ) ) === ( string ) $prefix_keyword ) {
271
+ if ( $prefix_equalsign ) {
272
+ if ( $url_equalsign ) {
273
+ if ( jr_mt_substr( $url_value, 0, jr_mt_strlen( $prefix_value ) ) === ( string ) $prefix_value ) {
274
+ $one_match = TRUE;
275
+ }
276
+ }
277
+ } else {
278
+ $one_match = TRUE;
279
+ }
280
+ }
281
+ }
282
+ }
283
+ }
284
+ /* All Prefix Queries must match.
285
+ */
286
+ if ( FALSE === $one_match ) {
287
+ return FALSE;
288
+ }
289
+ }
290
+ $match = TRUE;
291
+ }
292
+ } else {
293
+ /* Paths must exactly match if Prefix specifies Query
294
+ */
295
+ if ( array() === $prefix['query'] ) {
296
+ /* No Query in Prefix, so check Path for Prefix match
297
+ */
298
+ $match = ( $prefix['path'] === jr_mt_substr( $url['path'], 0, jr_mt_strlen( $prefix['path'] ) ) );
299
+ } else {
300
+ $match = FALSE;
301
+ }
302
+ }
303
+ } else {
304
+ /* Perhaps unnecessary restriction:
305
+ If Hosts match, then so much Ports.
306
+ */
307
+ $match = FALSE;
308
+ }
309
+ } else {
310
+ if ( ( 0 === $prefix['port'] ) && ( '' === $prefix['path'] ) && ( array() === $prefix['query'] ) ) {
311
+ /* No Path or Query in Prefix, so check Host for Prefix match
312
+ */
313
+ $match = ( $prefix['host'] === jr_mt_substr( $url['host'], 0, jr_mt_strlen( $prefix['host'] ) ) );
314
+ } else {
315
+ /* Hosts must exactly match if Prefix specifies Path or Query
316
+ */
317
+ $match = FALSE;
318
+ }
319
+ }
320
+ return $match;
321
+ }
322
+
323
+ function jr_mt_same_prefix_url_asterisk( $prefix, $url ) {
324
+ if ( is_string( $prefix ) ) {
325
+ $prefix = jr_mt_prep_url( $prefix );
326
+ }
327
+ if ( is_string( $url ) ) {
328
+ $url = jr_mt_prep_url( $url );
329
+ }
330
+ $path_prefix = explode( '/', $prefix['path'] );
331
+ $path_url = explode( '/', $url['path'] );
332
+ foreach ( $path_prefix as $i => $directory ) {
333
+ if ( '*' === $directory ) {
334
+ $path_url[ $i ] = '*';
335
+ }
336
+ }
337
+ $url['path'] = implode( '/', $path_url );
338
+ return jr_mt_same_prefix_url( $prefix, $url );
339
+ }
340
+
341
+ /**
342
+ * Standardize a URL into an array of values that can be accurately compared with another
343
+ *
344
+ * Preps URL, by removing any UTF Left-to-right Mark (LRM), usually found as a suffix,
345
+ * translating the URL to lower-case, removing prefix http[s]//:,
346
+ * any embedded index.php and any trailing slash or #bookmark,
347
+ * and breaks up ?keyword=value queries into array elements.
348
+ *
349
+ * Structure/Elements of Array returned:
350
+ * [host] - domain.com - all subdomains, including www., are included
351
+ * [path] - dir/file.ext
352
+ * [query] - any Queries (e.g. - "?kw=val&kw2=val2") broken up as follows:
353
+ * [$keyword] => [$value] => $equalsign
354
+ * $value - blank if not present
355
+ * $equalsign - bool indicating if = was present in URL
356
+ * Format prior to Version 7.0:
357
+ * [$keyword] => $value with preceding equals sign, only if equals sign was present
358
+ * To simplify processing of this Array, zero length strings and empty arrays are used,
359
+ * rather than NULL entries or missing array elements.
360
+ *
361
+ * @param string $url URL to create an array from, in special format for accurate comparison
362
+ * @return array array of standardized attributes of the URL (see structure above)
363
+ */
364
+ function jr_mt_prep_url( $url ) {
365
+ /* Handle troublesome %E2%80%8E UTF Left-to-right Mark (LRM) suffix first.
366
+ */
367
+ if ( FALSE === strpos( $url, '%E2%80%8E' ) ) {
368
+ if ( FALSE === strpos( rawurlencode( $url ), '%E2%80%8E' ) ) {
369
+ $url_clean = $url;
370
+ } else {
371
+ $url_clean = rawurldecode( str_replace( '%E2%80%8E', '', rawurlencode( $url ) ) );
372
+ /* mb_str_replace() does not exist because str_replace() is binary-safe.
373
+ */
374
+ }
375
+ } else {
376
+ $url_clean = str_replace( '%E2%80%8E', '', $url );
377
+ }
378
+ $url_clean = str_replace( '\\', '/', trim( $url_clean ) );
379
+
380
+ /* parse_url(), especially before php Version 5.4.7,
381
+ has a history of problems when Scheme is not present,
382
+ especially for LocalHost as a Host,
383
+ so add a prefix of http:// if :// is not found
384
+ */
385
+ if ( FALSE === strpos( $url_clean, '://' ) ) {
386
+ $url_clean = "http://$url_clean";
387
+ }
388
+
389
+ $parse_array = parse_url( jr_mt_strtolower( $url_clean ) );
390
+ /* Get rid of URL components that do not matter to us in our comparison of URLs
391
+ */
392
+ foreach ( array( 'scheme', 'user', 'pass', 'fragment' ) as $component ) {
393
+ unset ( $parse_array[ $component ] );
394
+ }
395
+ /* Remove standard HTTP Port 80 and HTTPS Port 443, if present.
396
+ */
397
+ if ( ( !isset( $parse_array['port'] ) ) || ( 80 === $parse_array['port'] ) || ( 443 === $parse_array['port'] ) ) {
398
+ $parse_array['port'] = 0;
399
+ }
400
+ if ( isset( $parse_array['path'] ) ) {
401
+ /* Remove any index.php occurences in path, since these can be spurious in IIS
402
+ and perhaps other environments.
403
+ */
404
+ $parse_array['path'] = str_replace( 'index.php', '', $parse_array['path'] );
405
+ /* Remove leading and trailing slashes from path
406
+ */
407
+ $parse_array['path'] = rtrim( $parse_array['path'], "/\\" );
408
+ } else {
409
+ $parse_array['path'] = '';
410
+ }
411
+ /* Take /?keyword=value&keyword=value URL query parameters
412
+ and break them up into array( keyword => value => equals?, keyword => value => equals? )
413
+ */
414
+ if ( isset( $parse_array['query'] ) ) {
415
+ $parms = explode( '&', $parse_array['query'] );
416
+ $parse_array['query'] = array();
417
+ foreach( $parms as $parm ) {
418
+ if ( FALSE === strpos( $parm, '=' ) ) {
419
+ $parse_array['query'][ $parm ][''] = FALSE;
420
+ } else {
421
+ $kwv = explode( '=', $parm );
422
+ $parse_array['query'][ $kwv[0] ][ $kwv[1] ] = TRUE;
423
+ }
424
+ /* Remember the presence of the Equals Sign ("=") in each Query
425
+ to differentiate between a URL Prefix with a Query Keyword followed by
426
+ an Equals Sign, and one without. For example, "address" would match
427
+ address2=abc, while "address=" would not.
428
+ */
429
+ }
430
+ } else {
431
+ $parse_array['query'] = array();
432
+ }
433
+ return $parse_array;
434
+ }
435
+
436
+ /** Build Query Array
437
+
438
+ $array[keyword] = array( value, value, ... )
439
+ Sets both keyword and value to lower-case as
440
+ that is how they are stored in Settings.
441
+
442
+ Supports only & separator, not proposed semi-colon separator.
443
+
444
+ Handles duplicate keywords in all four of these forms:
445
+ kw=val1&kw=val2 kw[]=val1&kw[]=val2 kw=val1&kw=val1 kw[]=val1&kw[]=val1
446
+ but nothing else, e.g. - kw=val1,val2 is not valid;
447
+ it returns "val1,val2" as the Value.
448
+ Also handles kw1&kw2
449
+
450
+ Tests of parse_str() in PHP 5.5.9 proved that semi-colon and comma
451
+ are not supported. But, neither is kw=val1,kw=val2 which is why
452
+ this function is written without the use of parse_str.
453
+ */
454
+ function jr_mt_query_array() {
455
+ /* Remove array entry indicators ("[]") as we properly handle duplicate keywords,
456
+ and covert to lower-case for comparison purposes.
457
+ */
458
+ $queries = array();
459
+ if ( !empty( $_SERVER['QUERY_STRING'] ) ) {
460
+ $query = explode( '&', jr_mt_strtolower( str_replace( '[]', '', $_SERVER['QUERY_STRING'] ) ) );
461
+ foreach ( $query as $kwval ) {
462
+ $query_entry = explode( '=', $kwval );
463
+ if ( !isset( $query_entry[1] ) ) {
464
+ $query_entry[1] = '';
465
+ }
466
+ $queries[ $query_entry[0] ][] = $query_entry[1];
467
+ }
468
+ }
469
+ return $queries;
470
+ }
471
+
472
+ /* Check for numeric IP Addresse, both IPv4 and IPv6
473
+ */
474
+ function jr_mt_is_ip( $domain_name ) {
475
+ if ( FALSE !== strpos( $domain_name, ':' ) ) {
476
+ /* IPv6
477
+ */
478
+ $return = TRUE;
479
+ } else {
480
+ if ( 4 === count( $ip_array = explode( '.', $domain_name ) ) ) {
481
+ foreach ( $ip_array as $ip ) {
482
+ if ( ctype_digit( $ip ) ) {
483
+ /* IPv4: maximum = 255
484
+ */
485
+ if ( $ip > 255 ) {
486
+ $return = FALSE;
487
+ break;
488
+ }
489
+ } else {
490
+ $return = FALSE;
491
+ break;
492
+ }
493
+ }
494
+ $return = !isset( $return );
495
+ } else {
496
+ $return = FALSE;
497
+ }
498
+ }
499
+ return $return;
500
+ }
501
+
502
+ /* Initialize the Aliases array in the Settings.
503
+
504
+ First entry will be the Site Address (URL) field value from WordPress General Settings.
505
+ Most of the time, Create an Alias of that URL,
506
+ based on adding or removing www. in the domain name.
507
+ Including Subdomains, which do not normally have www. defined
508
+ as an Alias, but you never know!
509
+ But not for numeric IP addresses, or localhost.
510
+
511
+ Returns an array containing one or two arrays, each in this format:
512
+ ['url'] => URL
513
+ ['prep'] => URL array created by jr_mt_prep_url()
514
+ ['home'] => TRUE if this is Site Address (URL) field value from WordPress General Settings,
515
+ which is stored here to determine when the WordPress General Setting is changed.
516
+ */
517
+ function jr_mt_init_aliases() {
518
+ $return = array(
519
+ array(
520
+ 'url' => JR_MT_HOME_URL,
521
+ 'prep' => jr_mt_prep_url( JR_MT_HOME_URL ),
522
+ 'home' => TRUE
523
+ )
524
+ );
525
+
526
+ if ( FALSE !== ( $url_parsed = parse_url( JR_MT_HOME_URL ) ) ) {
527
+ $host = $url_parsed['host'];
528
+ if ( 0 !== strcasecmp( $host, 'localhost' ) ) {
529
+ /* Check for numeric IP Addresse, both IPv4 and IPv6
530
+ */
531
+ if ( !jr_mt_is_ip( $host ) ) {
532
+ if ( 0 === strncasecmp( $host, 'www.', 4 ) ) {
533
+ $url_parsed['host'] = jr_mt_substr( $host, 4 );
534
+ } else {
535
+ $url_parsed['host'] = 'www.' . $host;
536
+ }
537
+ $url = jr_mt_unparse_url( $url_parsed );
538
+ $return[] = array(
539
+ 'url' => $url,
540
+ 'prep' => jr_mt_prep_url( $url ),
541
+ 'home' => FALSE
542
+ );
543
+ }
544
+ }
545
+ }
546
+ return $return;
547
+ }
548
+
549
+ function jr_mt_unparse_url( $parse_array ) {
550
+ if ( function_exists( 'http_build_url' ) ) {
551
+ $url = http_build_url( '', $parse_array );
552
+ } else {
553
+ /* From: https://github.com/jakeasmith/http_build_url
554
+ Version: 0.1.3
555
+ Version created about July 2014, retrieved November 4, 2014
556
+ */
557
+ $url = $parse_array['scheme'] . '://';
558
+
559
+ if ( isset( $parse_array['user'] ) ) {
560
+ $url .= $parse_array['user'];
561
+
562
+ if ( isset( $parse_array['pass'] ) ) {
563
+ $url .= ':' . $parse_array['pass'];
564
+ }
565
+
566
+ $url .= '@';
567
+ }
568
+
569
+ if ( isset( $parse_array['host'] ) ) {
570
+ $url .= $parse_array['host'];
571
+ }
572
+
573
+ if ( isset( $parse_array['port'] ) ) {
574
+ $url .= ':' . $parse_array['port'];
575
+ }
576
+
577
+ if ( !empty( $parse_array['path'] ) ) {
578
+ $url .= $parse_array['path'];
579
+ }
580
+
581
+ if ( isset( $parse_array['query'] ) ) {
582
+ $url .= '?' . $parse_array['query'];
583
+ }
584
+
585
+ if ( isset( $parse_array['fragment'] ) ) {
586
+ $url .= '#' . $parse_array['fragment'];
587
+ }
588
+ }
589
+ return $url;
590
+ }
591
+
592
+ /* Given a URL and a list of Site Aliases,
593
+ either as strings or in "prep format" (arrays),
594
+ return either:
595
+ - (string) the first Site Alias that matches;
596
+ - (string) the relative URL, relative to the Site Alias; and
597
+ - (array) the relative URL in "prep format"
598
+ OR
599
+ - FALSE on failure.
600
+ */
601
+ function jr_mt_make_relative( $url, $aliases ) {
602
+ if ( is_string( $url ) ) {
603
+ $url = jr_mt_prep_url( $url );
604
+ }
605
+ $return = FALSE;
606
+ foreach ( $aliases as $alias ) {
607
+ if ( jr_mt_same_prefix_url( $alias, $url ) ) {
608
+ $return = array(
609
+ 'alias' => $alias,
610
+ 'rel_url' => $rel_url,
611
+ 'rel_url_prep' => $rel_url_prep
612
+ );
613
+ break;
614
+ }
615
+ }
616
+ return $return;
617
+ }
618
+
619
+ /* Which Site Alias is the "Best Match"?
620
+
621
+ We already know that more than one Site Alias matches
622
+ all of the current URL for the full length of the Site Alias.
623
+ For example, if example.com and example.com/wp both matched,
624
+ example.com/wp would be the "best" match, in the sense of longest match.
625
+
626
+ $alias_array - in settings['alias'] format
627
+ $matches - array of keys to $alias_array, of matching Aliases
628
+ return - key of best match
629
+ */
630
+ function jr_mt_best_match_alias( $alias_array, $matches ) {
631
+ /* For each component, if they differ,
632
+ Best is determined as follows, in the following order:
633
+ Host - longest string is Best
634
+ Port - non-zero is Best
635
+ Path - longest string is Best.
636
+ */
637
+ $best = $matches;
638
+ $max = -1;
639
+ foreach ( $best as $key ) {
640
+ $len = strlen( $alias_array[ $key ]['prep']['host'] );
641
+ if ( $len > $max ) {
642
+ $max = $len;
643
+ }
644
+ }
645
+ foreach ( $best as $index => $key ) {
646
+ if ( $max > strlen( $alias_array[ $key ]['prep']['host'] ) ) {
647
+ unset ( $best[ $index ] );
648
+ }
649
+ }
650
+ foreach ( $best as $key ) {
651
+ if ( 0 !== $alias_array[ $key ]['prep']['port'] ) {
652
+ foreach ( $best as $index => $key ) {
653
+ if ( 0 === $alias_array[ $key ]['prep']['port'] ) {
654
+ unset( $best[ $index ] );
655
+ }
656
+ }
657
+ break;
658
+ }
659
+ }
660
+ $max = -1;
661
+ foreach ( $best as $key ) {
662
+ if ( empty( $alias_array[ $key ]['prep']['path'] ) ) {
663
+ $len = 0;
664
+ } else {
665
+ $len = strlen( $alias_array[ $key ]['prep']['path'] );
666
+ }
667
+ if ( $len > $max ) {
668
+ $max = $len;
669
+ }
670
+ }
671
+ foreach ( $best as $index => $key ) {
672
+ if ( empty( $alias_array[ $key ]['prep']['path'] ) ) {
673
+ $len = 0;
674
+ } else {
675
+ $len = strlen( $alias_array[ $key ]['prep']['path'] );
676
+ }
677
+ if ( $max > $len ) {
678
+ unset ( $best[ $index ] );
679
+ }
680
+ }
681
+ /* If there is more than one Site Alias left
682
+ in the $best array, then it should mean
683
+ there are duplicate entries,
684
+ but that makes no sense.
685
+ So, just return the first one in the array.
686
+
687
+ reset() returns the first array element,
688
+ not the key.
689
+ */
690
+ return reset( $best );
691
+ }
692
+
693
+ ?>
includes/index.html ADDED
File without changes
includes/old-wp.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* Exit if .php file accessed directly
4
+ */
5
+ if ( !defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ /* A Version of WordPress older than the first one supported by the Plugin
10
+ is being run.
11
+ */
12
+
13
+ add_action( 'all_admin_notices', 'jr_mt_all_admin_notice' );
14
+ // Runs after admin_menu hook
15
+ add_action( 'admin_notices', 'jr_mt_all_admin_notice' ); // for older versions
16
+
17
+ function jr_mt_all_admin_notice() {
18
+ // Only displayed in Admin panels:
19
+ echo '<div class="error">Deactivated the <b>jonradio Multiple Themes</b> plugin: requires WordPress Version 3.4 or newer; you are running Version '
20
+ . get_bloginfo( 'version' ) . '</div>';
21
+ deactivate_plugins( JR_MT_FILE );
22
+ }
23
+
24
+ ?>
includes/select-theme.php ADDED
@@ -0,0 +1,581 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* Exit if .php file accessed directly
3
+ */
4
+ if ( !defined( 'ABSPATH' ) ) {
5
+ exit;
6
+ }
7
+
8
+ /* Disable until old Version Settings conversion done properly,
9
+ typically by displaying the plugin's Settings page in Admin panels.
10
+ */
11
+ if ( ( FALSE === ( $settings = get_option( 'jr_mt_settings' ) ) ) || ( !is_array( $settings ) ) ) {
12
+ return;
13
+ }
14
+ foreach ( array( 'all_pages', 'all_posts', 'site_home', 'current',
15
+ 'url', 'url_prefix', 'url_asterisk',
16
+ 'query', 'remember', 'override',
17
+ 'query_present', 'aliases' ) as $key ) {
18
+ if ( !isset( $settings[ $key ] ) ) {
19
+ return;
20
+ }
21
+ }
22
+ foreach ( array( 'url', 'url_prefix', 'url_asterisk', 'query', 'remember', 'override', 'aliases' ) as $key ) {
23
+ if ( !is_array( $settings[ $key ] ) ) {
24
+ return;
25
+ }
26
+ }
27
+ foreach ( array( 'all_pages', 'all_posts', 'site_home', 'current' ) as $key ) {
28
+ if ( !is_string( $settings[ $key ] ) ) {
29
+ return;
30
+ }
31
+ }
32
+ if ( ( FALSE === ( $internal_settings = get_option( 'jr_mt_internal_settings' ) ) )
33
+ || ( !is_array( $internal_settings ) ) ) {
34
+ return;
35
+ }
36
+
37
+
38
+ /* Select the relevant Theme
39
+ These hooks must be available immediately
40
+ as some Themes check them very early.
41
+ Also must be available in Admin for p2.
42
+ */
43
+ add_filter( 'pre_option_stylesheet', 'jr_mt_stylesheet' );
44
+ add_filter( 'pre_option_template', 'jr_mt_template' );
45
+
46
+ if ( !is_admin() ) {
47
+ /* Be sure Plugins (non-internal) Settings are present in some shape or form
48
+ for public web site.
49
+ Admin is handled on plugin's Settings page.
50
+ */
51
+ if ( !is_array( get_option( 'jr_mt_settings' ) ) ) {
52
+ update_option( 'jr_mt_settings', jr_mt_default_settings() );
53
+ }
54
+
55
+ /* Hooks below shown in order of execution */
56
+
57
+ /* Only do this if All Posts or All Pages setting is present.
58
+ */
59
+ if ( get_option( 'permalink_structure' ) && jr_mt_all_posts_pages() ) {
60
+ /* 'setup_theme' is the earliest Action that I could find where url_to_postid( $url )
61
+ is valid. get_post() works by then, too.
62
+ */
63
+ add_action( 'setup_theme', 'jr_mt_page_conditional', JR_MT_RUN_FIRST );
64
+ function jr_mt_page_conditional() {
65
+ /* In case any requests for Theme came before this hook,
66
+ make sure that Theme Selection is repeated the next time
67
+ it is needed.
68
+ Because url_to_postid() and possibly get_post() don't work until now.
69
+
70
+ Note: in PHP, you cannot directly unset a global variable,
71
+ hence the cryptic code below.
72
+ */
73
+ unset( $GLOBALS['jr_mt_theme'] );
74
+ DEFINE( 'JR_MT_PAGE_CONDITIONAL', TRUE );
75
+ }
76
+ }
77
+
78
+ add_action( 'wp_loaded', 'jr_mt_wp_loaded', JR_MT_RUN_LAST );
79
+ function jr_mt_wp_loaded() {
80
+ /* Purpose of this hook is to output any required Cookie before it is too late
81
+ (after the <html> or any other HTML is generated).
82
+ There is no performance impact because this effectively pre-caches values
83
+ for use later.
84
+ This timing is also used to enqueue JavaScript related to the Sticky feature.
85
+ */
86
+ global $jr_mt_theme;
87
+ if ( !isset( $jr_mt_theme ) ) {
88
+ $settings = get_option( 'jr_mt_settings' );
89
+ if ( !empty( $settings['remember']['query'] ) ) {
90
+ jr_mt_template();
91
+ }
92
+ }
93
+
94
+ DEFINE( 'JR_MT_TOO_LATE_FOR_COOKIES', TRUE );
95
+ }
96
+ }
97
+
98
+ function jr_mt_stylesheet() {
99
+ return jr_mt_theme( 'stylesheet' );
100
+ }
101
+
102
+ function jr_mt_template() {
103
+ return jr_mt_theme( 'template' );
104
+ }
105
+
106
+ function jr_mt_theme( $option ) {
107
+ /* The hooks that (indirectly) call this function are called repeatedly by WordPress,
108
+ so do the checking once and store the values in a global array.
109
+ $jt_mt_theme['stylesheet'] - Stylesheet Name of Theme chosen
110
+ $jt_mt_theme['template'] - Template Name of Theme chosen
111
+
112
+ Very important note:
113
+ - get_option( 'jr_mt_settings' ) ['ids']['theme'] is the Theme Subdirectory Name,
114
+ as opposed to the Template or Stylesheet Name for the Theme.
115
+ - likewise, the variable local variable $theme
116
+ These three different values for each Theme must be clearly separated, as all three usually
117
+ match, but do not have to, e.g. - Child Themes.
118
+ */
119
+ global $jr_mt_theme;
120
+ if ( !isset( $jr_mt_theme ) ) {
121
+ $jr_mt_theme = array();
122
+ }
123
+ if ( !isset( $jr_mt_theme[$option] ) ) {
124
+ $theme = jr_mt_chosen();
125
+ $jr_mt_all_themes = jr_mt_all_themes();
126
+ /* Check to be sure that Theme is still installed.
127
+ If not:
128
+ return Everywhere theme if set and it exists,
129
+ otherwise, FALSE to indicate WordPress Active Theme.
130
+ */
131
+ if ( ( FALSE !== $theme ) && ( !isset( $jr_mt_all_themes[ $theme ] ) ) ) {
132
+ $settings = get_option( 'jr_mt_settings' );
133
+ $everything = $settings['current'];
134
+ if ( ( '' !== $everything ) && ( isset( $jr_mt_all_themes[ $everything ] ) ) ) {
135
+ $theme = $everything;
136
+ } else {
137
+ $theme = FALSE;
138
+ }
139
+ }
140
+ if ( FALSE === $theme ) {
141
+ // Get both at once, to save a repeat of this logic later:
142
+ $jr_mt_theme['stylesheet'] = jr_mt_current_theme( 'stylesheet' );
143
+ $jr_mt_theme['template'] = jr_mt_current_theme( 'template' );
144
+ } else {
145
+ $jr_mt_theme['stylesheet'] = $jr_mt_all_themes[ $theme ]->stylesheet;
146
+ $jr_mt_theme['template'] = $jr_mt_all_themes[ $theme ]->template;
147
+ }
148
+ if ( !is_admin() ) {
149
+ jr_mt_cookie( 'all', 'clean' );
150
+ }
151
+ }
152
+ $theme = $jr_mt_theme[$option];
153
+ return $theme;
154
+ }
155
+
156
+ /**
157
+ * Returns FALSE for Current Theme
158
+ *
159
+ */
160
+ function jr_mt_chosen() {
161
+ $settings = get_option( 'jr_mt_settings' );
162
+
163
+ /* $queries - array of [keyword] => array( value, value, ... )
164
+ in the current URL.
165
+ */
166
+ $queries = jr_mt_query_array();
167
+
168
+ /* P2 free Theme special processing:
169
+ for both Admin and Public site,
170
+ check for P2 keyword p2ajax=,
171
+ and select P2 theme, if present.
172
+ */
173
+ if ( isset( $queries['p2ajax'] ) && array_key_exists( 'p2', jr_mt_all_themes() ) ) {
174
+ return 'p2';
175
+ }
176
+ /* Otherwise, Admin gets current ("Active") WordPress Theme
177
+ */
178
+ if ( is_admin() ) {
179
+ return FALSE;
180
+ }
181
+
182
+ /* KnowHow ThemeForest Paid Theme special processing:
183
+ if s= is present, and 'knowhow' is either the active WordPress Theme
184
+ or is specified in any Settings, then automatically select the KnowHow theme.
185
+ */
186
+ if ( isset( $queries['s'] ) && in_array( 'knowhow', jr_mt_themes_defined(), TRUE ) ) {
187
+ return 'knowhow';
188
+ }
189
+
190
+ /* Non-Admin page, i.e. - Public Site, etc.
191
+
192
+ Begin by checking for any Query keywords specified by the Admin in Settings,
193
+ complicated by the fact that Override entries take precedence.
194
+ */
195
+ if ( !empty( $settings['query'] ) ) {
196
+ if ( !empty( $_SERVER['QUERY_STRING'] ) ) {
197
+ /* Check Override entries
198
+ */
199
+ foreach ( $settings['override']['query'] as $override_keyword => $override_value_array ) {
200
+ if ( isset( $queries[ $override_keyword ] ) ) {
201
+ foreach ( $override_value_array as $override_value_untyped => $bool ) {
202
+ $override_value = ( string ) $override_value_untyped;
203
+ if ( in_array( $override_value, $queries[ $override_keyword ], TRUE ) ) {
204
+ $override_found[] = array( $override_keyword, $override_value );
205
+ }
206
+ }
207
+ }
208
+ }
209
+ if ( !isset( $overrides_found ) ) {
210
+ /* Look for both keyword=value settings and keyword=* settings,
211
+ with keyword=value taking precedence (sorted out later).
212
+ */
213
+ foreach ( $settings['query'] as $query_settings_keyword => $value_array ) {
214
+ if ( isset( $queries[ $query_settings_keyword ] ) ) {
215
+ foreach ( $value_array as $query_settings_value_untyped => $theme ) {
216
+ $query_settings_value = ( string ) $query_settings_value_untyped;
217
+ if ( in_array( $query_settings_value, $queries[ $query_settings_keyword ], TRUE ) ) {
218
+ $query_found[] = array( $query_settings_keyword, $query_settings_value );
219
+ }
220
+ }
221
+ if ( isset( $value_array['*'] ) ) {
222
+ $keyword_found[] = $query_settings_keyword;
223
+ }
224
+ }
225
+ }
226
+ }
227
+ }
228
+ }
229
+
230
+ /* Handle Overrides:
231
+ First, for Override keyword=value query in URL.
232
+ Second, for previous Override detected by PHP cookie.
233
+ */
234
+ if ( isset( $override_found ) ) {
235
+ /* If sticky, create JavaScript Sticky Cookie,
236
+ and PHP Sticky Cookie.
237
+ No matter what:
238
+ return Theme from the first Override found.
239
+ */
240
+ $keyword = $override_found[0][0];
241
+ $value = $override_found[0][1];
242
+ if ( isset( $settings['remember']['query'][ $keyword ][ $value ] ) ) {
243
+ jr_mt_js_sticky_query( $keyword, $value );
244
+ jr_mt_cookie( 'php', 'put', "$keyword=$value" );
245
+ }
246
+ return $settings['query'][ $keyword ][ $value ];
247
+ } else {
248
+ /* Is there a previous Override Query for this Site Visitor?
249
+ If so, use it, but only if it is still valid.
250
+ */
251
+ if ( FALSE !== ( $cookie = jr_mt_cookie( 'php', 'get' ) ) ) {
252
+ list( $keyword, $value ) = explode( '=', $cookie );
253
+ if ( isset( $settings['override']['query'][ $keyword ][ $value ] ) ) {
254
+ /* If sticky, create JavaScript Sticky Cookie,
255
+ and renew PHP Sticky Cookie.
256
+ No matter what:
257
+ Return Theme
258
+ */
259
+ if ( isset( $settings['remember']['query'][ $keyword ][ $value ] ) ) {
260
+ jr_mt_js_sticky_query( $keyword, $value );
261
+ jr_mt_cookie( 'php', 'put', "$keyword=$value" );
262
+ }
263
+ return $settings['query'][ $keyword ][ $value ];
264
+ }
265
+ }
266
+ }
267
+
268
+ /* Handle Non-Overrides:
269
+ keyword=value query in URL with matching setting entry.
270
+ */
271
+ if ( isset( $query_found ) ) {
272
+ $query_keyword_found = $query_found[0][0];
273
+ $query_value_found = $query_found[0][1];
274
+ /* Probably makes sense to give preference to the Sticky ones
275
+ */
276
+ foreach ( $query_found as $query_kwval_array ) {
277
+ if ( isset( $settings['remember']['query'][ $query_kwval_array[0] ][ $query_kwval_array[1] ] ) ) {
278
+ $query_keyword_found = $query_kwval_array[0];
279
+ $query_value_found = $query_kwval_array[1];
280
+ /* Create JavaScript Sticky Cookie,
281
+ and PHP Sticky Cookie.
282
+ */
283
+ jr_mt_js_sticky_query( $query_keyword_found, $query_value_found );
284
+ jr_mt_cookie( 'php', 'put', "$query_keyword_found=$query_value_found" );
285
+ break;
286
+ }
287
+ }
288
+ /* Return Theme
289
+ */
290
+ return $settings['query'][ $query_keyword_found ][ $query_value_found ];
291
+ }
292
+
293
+ /* Handle Keyword wildcards:
294
+ keyword=* setting entry that matches keyword in URL query.
295
+ */
296
+ if ( isset( $keyword_found ) ) {
297
+ return $settings['query'][ $keyword_found[0] ]['*'];
298
+ }
299
+
300
+ /* Now look at URL entries: $settings['url'] and ['url_prefix']
301
+
302
+ Version 6.0 Logic Design to maximize performance on high traffic sites without Caching:
303
+ For current URL, determine Site Alias in use
304
+ - Best Match - from an array of matching Site Aliases, determine "Best", some measure of Longest
305
+ Prep current URL for matching
306
+ Check for match in "URL" plugin entries that have been pre-prepped with this Site Alias
307
+ Check for match in "URL Prefix" plugin entries that have been pre-prepped with this Site Alias
308
+ Check for match in "URL Prefix with Asterisk" plugin entries that have been pre-prepped with this Site Alias
309
+ */
310
+
311
+ $prep_url = jr_mt_prep_url( $current_url = parse_url( JR_MT_HOME_URL, PHP_URL_SCHEME ) . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] );
312
+ $match = array();
313
+ foreach ( $settings['aliases'] as $key => $alias_array ) {
314
+ if ( jr_mt_same_prefix_url( $alias_array['prep'], $prep_url ) ) {
315
+ $match[] = $key;
316
+ }
317
+ }
318
+ if ( empty( $match ) ) {
319
+ /* Maybe not the best thing to do,
320
+ but if Site Alias is not defined,
321
+ always use Current Theme.
322
+ */
323
+ return FALSE;
324
+ }
325
+ $site_alias_key = jr_mt_best_match_alias( $settings['aliases'], $match );
326
+ foreach ( $settings['url'] as $settings_array ) {
327
+ if ( jr_mt_same_url( $settings_array['prep'][ $site_alias_key ], $prep_url ) ) {
328
+ return $settings_array['theme'];
329
+ }
330
+ }
331
+ foreach ( $settings['url_prefix'] as $settings_array ) {
332
+ if ( jr_mt_same_prefix_url( $settings_array['prep'][ $site_alias_key ], $prep_url ) ) {
333
+ return $settings_array['theme'];
334
+ }
335
+ }
336
+ foreach ( $settings['url_asterisk'] as $settings_array ) {
337
+ if ( jr_mt_same_prefix_url_asterisk( $settings_array['prep'][ $site_alias_key ], $prep_url ) ) {
338
+ return $settings_array['theme'];
339
+ }
340
+ }
341
+
342
+ /* Must check for Home near the end as queries override
343
+
344
+ Home is determined in an odd way:
345
+ (1) Remove all Queries
346
+ (2) Match against Site Address (URL) specified in Admin General Settings
347
+ (3) Check if any non-Permalink keywords are present, such as p= or page_id=
348
+ and cause a non-match if present
349
+ */
350
+ if ( '' !== $settings['site_home'] ) {
351
+ /* Check for Home Page,
352
+ with or without Query.
353
+ */
354
+ $prep_url_no_query = $prep_url;
355
+ $prep_url_no_query['query'] = array();
356
+ if ( jr_mt_same_url( JR_MT_HOME_URL, $prep_url_no_query ) ) {
357
+ $home = TRUE;
358
+ $internal_settings = get_option( 'jr_mt_internal_settings' );
359
+ if ( ( isset( $internal_settings['query_vars'] ) )
360
+ && ( is_array( $internal_settings['query_vars'] ) ) ) {
361
+ foreach ( $prep_url['query'] as $keyword => $value ) {
362
+ /* Check for any non-Permalink Query Keyword
363
+ */
364
+ if ( in_array( $keyword, $internal_settings['query_vars'], TRUE ) ) {
365
+ $home = FALSE;
366
+ break;
367
+ }
368
+ }
369
+ }
370
+ if ( $home ) {
371
+ return $settings['site_home'];
372
+ } else {
373
+ /* Check for Settings specifying the current Page, Post or Attachment
374
+ specified with kw=val Query default Permalinks.
375
+ */
376
+ foreach ( $settings['url'] as $settings_array ) {
377
+ if ( isset( $settings_array['id_kw'] )
378
+ && ( isset( $prep_url['query'][ $settings_array['id_kw'] ] ) )
379
+ && ( $prep_url['query'][ $settings_array['id_kw'] ] === $settings_array['id'] )
380
+ ) {
381
+ return $settings_array['theme'];
382
+ }
383
+ }
384
+ }
385
+ }
386
+ }
387
+ /* All Pages and All Posts settings are checked second to last,
388
+ just before Everything Else.
389
+
390
+ url_to_postid() only works after JR_MT_PAGE_CONDITIONAL is set.
391
+ But alternate means can be used with default Permalinks.
392
+
393
+ First, see if any All Pages or All Posts setting exists.
394
+ */
395
+ if ( jr_mt_all_posts_pages() ) {
396
+ if ( defined( 'JR_MT_PAGE_CONDITIONAL' ) ) {
397
+ if ( 0 !== ( $id = url_to_postid( $current_url ) ) ) {
398
+ if ( NULL !== ( $post = get_post( $id ) ) ) {
399
+ $type = $post->post_type;
400
+ if ( 'post' === $type ) {
401
+ if ( '' !== $settings['all_posts'] ) {
402
+ return $settings['all_posts'];
403
+ }
404
+ } else {
405
+ if ( 'page' === $type ) {
406
+ if ( '' !== $settings['all_pages'] ) {
407
+ return $settings['all_pages'];
408
+ }
409
+ }
410
+ }
411
+ }
412
+ }
413
+ } else {
414
+ $permalink = get_option( 'permalink_structure' );
415
+ if ( empty( $permalink ) ) {
416
+ if ( '' !== $settings['all_posts'] ) {
417
+ if ( isset( $queries['p'] ) ) {
418
+ return $settings['all_posts'];
419
+ }
420
+ }
421
+
422
+ if ( '' !== $settings['all_pages'] ) {
423
+ if ( isset( $queries['page_id'] ) ) {
424
+ return $settings['all_pages'];
425
+ }
426
+ }
427
+ }
428
+ }
429
+ }
430
+ /* This is the Theme for Everything Advanced Setting.
431
+ A Setting of Blank uses WordPress Current Theme value,
432
+ i.e. - the Setting is not set.
433
+ */
434
+ if ( '' === $settings['current'] ) {
435
+ return FALSE;
436
+ } else {
437
+ return $settings['current'];
438
+ }
439
+ }
440
+
441
+ /** Cookie to JavaScript with Sticky Query and related info.
442
+
443
+ Replace Existing or Create New (if no existing) Cookie
444
+ to remember what Sticky Keyword=Value to use on this Browser on this Visitor Computer.
445
+ Cookie is an encoding of this array:
446
+ - keyword=value query to append to URL
447
+ - FALSE if Setting "Append if no question mark ("?") found in URL", or
448
+ TRUE if Setting "Append if no Override keyword=value found in URL"
449
+ - an array of all sticky or override queries (empty array if FALSE)
450
+
451
+ Version 6.0 - this code has not been upgraded to support Site Aliases!
452
+ */
453
+ function jr_mt_js_sticky_query( $keyword, $value ) {
454
+ add_action( 'wp_enqueue_scripts', 'jr_mt_wp_enqueue_scripts' );
455
+ function jr_mt_wp_enqueue_scripts() {
456
+ global $jr_mt_plugin_data;
457
+ wp_enqueue_script( 'jr_mt_sticky', plugins_url() . '/' . dirname( jr_mt_plugin_basename() ) . '/js/sticky.js', array(), $jr_mt_plugin_data['Version'] );
458
+ /* JavaScript needs some values passed in HTML,
459
+ so add that hook here, too.
460
+ */
461
+ add_action( 'wp_footer', 'jr_mt_wp_footer' );
462
+ }
463
+ function jr_mt_wp_footer() {
464
+ echo '<div style="display: none;"><div id="jr-mt-home-url" title="'
465
+ . jr_mt_prep_comp_url( JR_MT_HOME_URL )
466
+ . '"></div><div id="jr-mt-site-admin" title="'
467
+ . jr_mt_prep_comp_url( admin_url() )
468
+ . '"></div></div>';
469
+ }
470
+ /** Prepare URL for JavaScript compares
471
+
472
+ Remove http[s]//: from beginning
473
+ Convert rest of URL to lower-case
474
+ Remove www. from beginning, if present
475
+ Convert any backslashes to forward slashes
476
+ Remove any trailing slash(es).
477
+ */
478
+ function jr_mt_prep_comp_url( $url ) {
479
+ $comp_url = jr_mt_strtolower( jr_mt_substr( $url, 3 + strpos( $url, '://' ) ) );
480
+ if ( 'www.' === jr_mt_substr( $comp_url, 0, 4 ) ) {
481
+ $comp_url = jr_mt_substr( $comp_url, 4 );
482
+ }
483
+ return rtrim( str_replace( '\\', '/', $comp_url ), '/' );
484
+ }
485
+
486
+ $settings = get_option( 'jr_mt_settings' );
487
+
488
+ if ( $settings['query_present'] ) {
489
+ foreach ( $settings['override']['query'] as $override_keyword => $override_value_array ) {
490
+ foreach ( $override_value_array as $override_value => $theme ) {
491
+ $override[] = "$override_keyword=$override_value";
492
+ }
493
+ }
494
+ } else {
495
+ $override = array();
496
+ }
497
+
498
+ jr_mt_cookie( 'js', 'put', strtr( rawurlencode( json_encode(
499
+ array( "$keyword=$value", $settings['query_present'], $override ) ) ),
500
+ array( '%21' => '!', '%2A' => '*', '%27' => "'", '%28' => '(', '%29' => ')' ) )
501
+ );
502
+ }
503
+
504
+ /* All Cookie Handling occurs here.
505
+ $action - 'get', 'put', 'del'
506
+ */
507
+ function jr_mt_cookie( $lang, $action, $cookie_value = '' ) {
508
+ switch ( $lang ) {
509
+ case 'js':
510
+ $cookie_name = 'jr-mt-remember-query';
511
+ $raw = TRUE;
512
+ $expiry = '+36 hours';
513
+ $function = 'setrawcookie';
514
+ break;
515
+ case 'php':
516
+ $cookie_name = 'jr_mt_php_override_query';
517
+ $raw = FALSE;
518
+ $expiry = '+1 year';
519
+ $function = 'setcookie';
520
+ break;
521
+ }
522
+ if ( 'get' === $action ) {
523
+ if ( isset( $_COOKIE[ $cookie_name ] ) ) {
524
+ return $_COOKIE[ $cookie_name ];
525
+ } else {
526
+ return FALSE;
527
+ }
528
+ } else {
529
+ global $jr_mt_cookie_track;
530
+ if ( defined( 'JR_MT_TOO_LATE_FOR_COOKIES' ) ) {
531
+ return FALSE;
532
+ }
533
+ /* Determine Path off Domain to WordPress Address, not Site Address, for Cookie Path value.
534
+ Using home_url().
535
+ */
536
+ $cookie_path = parse_url( JR_MT_HOME_URL, PHP_URL_PATH ) . '/';
537
+ switch ( $action ) {
538
+ case 'put':
539
+ if ( empty( $cookie_value ) ) {
540
+ return FALSE;
541
+ } else {
542
+ return ( $jr_mt_cookie_track[ $lang ] = $function( $cookie_name, $cookie_value, strtotime( $expiry ), $cookie_path, $_SERVER['SERVER_NAME'] ) );
543
+ }
544
+ break;
545
+ case 'del':
546
+ /* Don't clutter up output to browser with a Cookie Delete request if a Cookie does not exist.
547
+ */
548
+ if ( isset( $_COOKIE[ $cookie_name ] ) ) {
549
+ return ( $jr_mt_cookie_track[ $lang ] = setrawcookie( $cookie_name, '', strtotime( '-2 days' ), $cookie_path, $_SERVER['SERVER_NAME'] ) );
550
+ }
551
+ break;
552
+ case 'clean':
553
+ if ( 'all' === $lang ) {
554
+ $clean_langs = array( 'php', 'js' );
555
+ } else {
556
+ $clean_langs = array( $lang );
557
+ }
558
+ foreach ( $clean_langs as $clean_lang ) {
559
+ if ( !isset( $jr_mt_cookie_track[ $clean_lang ] ) ) {
560
+ jr_mt_cookie( $clean_lang, 'del' );
561
+ }
562
+ }
563
+ break;
564
+ }
565
+ }
566
+ }
567
+
568
+ /** Will the url_to_postid() function be required?
569
+ *
570
+ * Only if:
571
+ * - Pretty Permalinks are being used, AND
572
+ * - ( All Posts setting is set, OR
573
+ * - All Pages setting is set )
574
+ * @return bool if add_action is required
575
+ */
576
+ function jr_mt_all_posts_pages() {
577
+ $settings = get_option( 'jr_mt_settings' );
578
+ return ( $settings['all_posts'] || $settings['all_pages'] );
579
+ }
580
+
581
+ ?>
includes/upgradev5.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* Exit if .php file accessed directly
4
+ */
5
+ if ( !defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ /**
10
+ * Convert pre-Version 5 ['ids'] Settings to new Version 5 format.
11
+ *
12
+ * Mainly, it involves converting Post ID to URL.
13
+ * 'setup_theme' is the earliest Action where
14
+ * all functions in jr_mt_convert_ids() work properly.
15
+ *
16
+ */
17
+ function jr_mt_convert_ids( $settings ) {
18
+ if ( is_array( $settings['ids'] ) ) {
19
+ foreach ( $settings['ids'] as $key => $ids_array ) {
20
+ /* Be sure that Theme has not been deleted.
21
+ */
22
+ $jr_mt_all_themes = jr_mt_all_themes();
23
+ if ( isset( $jr_mt_all_themes[ $ids_array['theme'] ] ) ) {
24
+ /* $key:
25
+ '' - Home entry
26
+ */
27
+ if ( '' === $key ) {
28
+ if ( '' === $settings['site_home'] ) {
29
+ $settings['site_home'] = $ids_array['theme'];
30
+ }
31
+ } else {
32
+ if ( isset( $ids_array['type'] ) ) {
33
+ switch ( $ids_array['type'] ) {
34
+ case 'admin':
35
+ /* Ignore as Admin pages are ignored
36
+ */
37
+ break;
38
+ case 'prefix':
39
+ /* URL Prefix
40
+ */
41
+ $url = JR_MT_HOME_URL . "/$key";
42
+ $settings['url_prefix'][] = array(
43
+ 'url' => $url,
44
+ 'prep' => jr_mt_prep_url( $url ),
45
+ 'theme' => $ids_array['theme']
46
+ );
47
+ break;
48
+ case '*':
49
+ /* URL Prefix with Asterisk
50
+ */
51
+ $url = JR_MT_HOME_URL . "/$key";
52
+ $settings['url_asterisk'][] = array(
53
+ 'url' => $url,
54
+ 'prep' => jr_mt_prep_url( $url ),
55
+ 'theme' => $ids_array['theme']
56
+ );
57
+ break;
58
+ case 'cat':
59
+ if ( is_wp_error( get_the_category_by_ID( $key ) ) ) {
60
+ /* Ignore non-existent Categories.
61
+ They were likely deleted.
62
+ */
63
+ jr_mt_messages( 'Setting deleted for non-existent Category with ID=' . $key );
64
+ } else {
65
+ $url = get_category_link( $key );
66
+ $settings['url'][] = array(
67
+ 'url' => $url,
68
+ 'prep' => jr_mt_prep_url( $url ),
69
+ 'theme' => $ids_array['theme']
70
+ );
71
+ }
72
+ break;
73
+ case 'archive':
74
+ /* From ?m=yyyymm query originally
75
+ */
76
+ $yyyymm = $ids_array['id'];
77
+ $year = intval( $yyyymm / 100 );
78
+ $month = $yyyymm % 100;
79
+ $url = get_month_link( $year, $month );
80
+ $settings['url'][] = array(
81
+ 'url' => $url,
82
+ 'prep' => jr_mt_prep_url( $url ),
83
+ 'theme' => $ids_array['theme']
84
+ );
85
+ break;
86
+ default:
87
+ if ( FALSE === $ids_array['id'] ) {
88
+ /* Exact URL
89
+ */
90
+ $url = JR_MT_HOME_URL . "/$key";
91
+ $settings['url'][] = array(
92
+ 'url' => $url,
93
+ 'prep' => jr_mt_prep_url( $url ),
94
+ 'theme' => $ids_array['theme']
95
+ );
96
+ } else {
97
+ /* Some Post type
98
+
99
+ get_permalink() can be used as early as Action Hook 'setup_theme',
100
+ but not in 'plugins_loaded' (Fatal Error).
101
+ */
102
+ if ( FALSE === ( $url = get_permalink( $key ) ) ) {
103
+ /* Ignore any non-existent IDs, typically deleted.
104
+ */
105
+ jr_mt_messages( 'Setting deleted for non-existent Post/Page/Attachment with ID=' . $key );
106
+ } else {
107
+ $settings['url'][] = array(
108
+ 'url' => $url,
109
+ 'prep' => jr_mt_prep_url( $url ),
110
+ 'theme' => $ids_array['theme']
111
+ );
112
+ }
113
+ }
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+ }
120
+ /* Maybe later:
121
+ unset( $settings['ids'] );
122
+ */
123
+ return $settings;
124
+ }
125
+
126
+ ?>
includes/upgradev6.php ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* Exit if .php file accessed directly
4
+ */
5
+ if ( !defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ /* Must be able to determine Page ID (Action setup_theme is the earliest)
10
+ */
11
+ function jr_mt_convert_url_arrays( $settings ) {
12
+ global $jr_mt_url_types;
13
+ foreach ( $jr_mt_url_types as $setting_key ) {
14
+ if ( isset( $settings[ $setting_key ] )
15
+ && is_array( $settings[ $setting_key ] ) ) {
16
+ foreach ( $settings[ $setting_key ] as $url_key => $url_array ) {
17
+ $url = $url_array['url'];
18
+ if ( jr_mt_same_prefix_url( JR_MT_HOME_URL, $url ) ) {
19
+ $new_url_array['url'] = $url_array['url'];
20
+ $new_url_array['theme'] = $url_array['theme'];
21
+ $rel_url = jr_mt_relative_url( $url, JR_MT_HOME_URL );
22
+ $new_url_array['rel'] = $rel_url;
23
+ /* Create the URL Prep array for each of the current Site Aliases,
24
+ including the Current Site URL
25
+ */
26
+ $new_url_array['prep'] = array();
27
+ foreach ( $settings['aliases'] as $index => $alias ) {
28
+ $new_url_array['prep'][] = jr_mt_prep_url( $alias['url'] . '/' . $rel_url );
29
+ }
30
+ /* Only for URL type Setting, not Prefix types.
31
+ */
32
+ if ( 'url' === $setting_key ) {
33
+ /* Try and figure out ID and WordPress Query Keyword for Type, if possible and relevant
34
+ */
35
+ if ( ( 0 === ( $id = url_to_postid( $url ) ) ) &&
36
+ ( version_compare( get_bloginfo( 'version' ), '4', '>=' ) ) ) {
37
+ $id = attachment_url_to_postid( $url );
38
+ }
39
+ if ( !empty( $id ) ) {
40
+ $new_url_array['id'] = ( string ) $id;
41
+ if ( NULL !== ( $post = get_post( $id ) ) ) {
42
+ switch ( $post->post_type ) {
43
+ case 'post':
44
+ $new_url_array['id_kw'] = 'p';
45
+ break;
46
+ case 'page':
47
+ $new_url_array['id_kw'] = 'page_id';
48
+ break;
49
+ case 'attachment':
50
+ $new_url_array['id_kw'] = 'attachment_id';
51
+ break;
52
+ }
53
+ }
54
+ }
55
+ }
56
+ $settings[ $setting_key ][ $url_key ] = $new_url_array;
57
+ } else {
58
+ /* Error:
59
+ Cannot convert, as URL is from a different Site Home URL,
60
+ so have to delete this URL entry.
61
+ */
62
+ unset( $settings[ $setting_key ][ $url_key ] );
63
+ jr_mt_messages( 'Setting deleted during Conversion to Version 6 format because Site URL has changed' );
64
+ }
65
+ }
66
+ }
67
+ }
68
+ return $settings;
69
+ }
70
+
71
+ ?>
index.html ADDED
File without changes
jonradio-multiple-themes.php ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 WordPress Pages, Posts or other non-Admin pages. Or Site Home.
6
+ Version: 7.0.1
7
+ Author: David Gewirtz
8
+ Author URI: http://zatzlabs.com/plugins/
9
+ License: GPLv2
10
+ */
11
+
12
+ /* Copyright 2015 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
+ DEFINE( 'JR_MT_HOME_URL', home_url() );
36
+ DEFINE( 'JR_MT_FILE', __FILE__ );
37
+
38
+ /* For Hooks, when it needs to run first or last.
39
+ */
40
+ DEFINE( 'JR_MT_RUN_FIRST', 1 );
41
+ DEFINE( 'JR_MT_RUN_SECOND', JR_MT_RUN_FIRST + 1 );
42
+ DEFINE( 'JR_MT_RUN_LAST', 999 );
43
+
44
+ DEFINE( 'JR_MT_WP_GET_THEMES_ACTION', 'plugins_loaded' );
45
+
46
+ global $jr_mt_url_types;
47
+ $jr_mt_url_types = array( 'url', 'url_prefix', 'url_asterisk' );
48
+
49
+ function jr_mt_default_settings() {
50
+ return array(
51
+ /* Settings structure:
52
+ code - get_option( 'jr_mt_settings' )
53
+ ['all_pages'] => zero length string or folder in Themes directory containing theme to use for All Pages
54
+ ['all_posts'] => zero length string or folder in Themes directory containing theme to use for All Posts
55
+ ['site_home'] => zero length string or folder in Themes directory containing theme to use for Home Page
56
+ ['current'] => zero length string or folder in Themes directory containing theme to override WordPress Current Theme
57
+ ['query']
58
+ [keyword]
59
+ [value] or ['*'] => folder in Themes directory containing theme to use
60
+ ['remember']
61
+ ['query']
62
+ [keyword]
63
+ [value] => TRUE
64
+ ['override']
65
+ ['query']
66
+ [keyword]
67
+ [value] => TRUE
68
+ ['query_present'] => TRUE or FALSE
69
+
70
+ Added in Version 5.0:
71
+ ['url'], ['url_prefix'] and ['url_asterisk'] - array with each entry:
72
+ ['url'] => URL
73
+ ['prep'][] => array of URL arrays created by jr_mt_prep_url(), with array index matching the array index of ['aliases']
74
+ ['rel_url'] => Relative URL based on Site Address (URL) that admin entered the URL
75
+ ['id'] => Post ID (Page, Post or Attachment), if known and if relevant
76
+ ['id_kw'] => 'page_id', 'p' or 'attachment_id'
77
+ ['theme'] => folder in Themes directory containing theme to use
78
+
79
+ Added in Version 6.0:
80
+ ['aliases'][] - array of Alias URLs that could replace 'home' in URL of this site,
81
+ with each entry:
82
+ ['url'] => URL
83
+ ['prep'] => URL array created by jr_mt_prep_url()
84
+ ['home'] => TRUE if this is Site Address (URL) field value from WordPress General Settings,
85
+ which is stored here to determine when the WordPress General Setting is changed
86
+
87
+ Prior to Version 5.0:
88
+ ['ids']
89
+ [id] - zero length string or WordPress ID of Page, Post, etc.
90
+ ['type'] => 'page' or 'post' or 'admin' or 'cat' or 'archive' or 'prefix' or other
91
+ ['theme'] => folder in Themes directory containing theme to use
92
+ ['id'] => FALSE or WordPress ID of Page, Post, etc.
93
+ ['page_url'] => relative URL WordPress page, post, admin, etc. or FALSE
94
+ ['rel_url'] => URL relative to WordPress home
95
+ ['url'] => original full URL, from Settings page entry by user
96
+ */
97
+ 'aliases' => jr_mt_init_aliases(),
98
+ 'all_pages' => '',
99
+ 'all_posts' => '',
100
+ 'site_home' => '',
101
+ 'current' => '',
102
+ 'query' => array(),
103
+ 'remember' => array( 'query' => array() ),
104
+ 'override' => array( 'query' => array() ),
105
+ 'query_present' => FALSE,
106
+ 'url' => array(),
107
+ 'url_prefix' => array(),
108
+ 'url_asterisk' => array()
109
+ );
110
+ }
111
+
112
+ /* Catch old unsupported version of WordPress before any damage can be done.
113
+ */
114
+ if ( version_compare( get_bloginfo( 'version' ), '3.4', '<' ) ) {
115
+ require_once( plugin_dir_path( JR_MT_FILE ) . 'includes/old-wp.php' );
116
+ } else {
117
+ /* Use $plugin_data['Name'] for the array of incompatible plugins
118
+ */
119
+ global $jr_mt_incompat_plugins;
120
+ $jr_mt_incompat_plugins = array( 'Theme Test Drive' ); // removed for V5: 'BuddyPress', 'Polylang'
121
+
122
+ require_once( plugin_dir_path( JR_MT_FILE ) . 'includes/functions.php' );
123
+
124
+ if ( is_admin() ) {
125
+ /* Add Link to the plugin's entry on the Admin "Plugins" Page, for easy access
126
+
127
+ Placed here to avoid the confusion of not displaying it during a Version conversion of Settings
128
+ */
129
+ add_filter( 'plugin_action_links_' . jr_mt_plugin_basename(), 'jr_mt_plugin_action_links', 10, 1 );
130
+
131
+ /**
132
+ * Creates Settings entry right on the Plugins Page entry.
133
+ *
134
+ * Helps the user understand where to go immediately upon Activation of the Plugin
135
+ * by creating entries on the Plugins page, right beside Deactivate and Edit.
136
+ *
137
+ * @param array $links Existing links for our Plugin, supplied by WordPress
138
+ * @param string $file Name of Plugin currently being processed
139
+ * @return string $links Updated set of links for our Plugin
140
+ */
141
+ function jr_mt_plugin_action_links( $links ) {
142
+ /* The "page=" query string value must be equal to the slug
143
+ of the Settings admin page.
144
+ */
145
+ array_unshift( $links, '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=jr_mt_settings' . '">Settings</a>' );
146
+ return $links;
147
+ }
148
+
149
+ // Admin Page
150
+
151
+ add_action( 'admin_menu', 'jr_mt_admin_hook' );
152
+ // Runs just before admin_init (in admin.php file)
153
+
154
+ /**
155
+ * Add Admin Menu item for plugin
156
+ *
157
+ * Plugin needs its own Page in the Settings section of the Admin menu.
158
+ *
159
+ */
160
+ function jr_mt_admin_hook() {
161
+ // Add Settings Page for this Plugin
162
+ global $jr_mt_plugin_data;
163
+ add_theme_page( $jr_mt_plugin_data['Name'], 'Multiple Themes plugin', 'switch_themes', 'jr_mt_settings', 'jr_mt_settings_page' );
164
+ add_options_page( $jr_mt_plugin_data['Name'], 'Multiple Themes plugin', 'switch_themes', 'jr_mt_settings', 'jr_mt_settings_page' );
165
+ }
166
+
167
+ add_action( 'admin_init', 'jr_mt_register_settings' );
168
+ function jr_mt_register_settings() {
169
+ register_setting( 'jr_mt_settings', 'jr_mt_settings', 'jr_mt_validate_settings' );
170
+ }
171
+ }
172
+
173
+ /* p2 runs in Admin, so must also execute this code in Admin, too.
174
+ */
175
+ require_once( jr_mt_path() . 'includes/select-theme.php' );
176
+
177
+ if ( is_admin() ) {
178
+ /* && isset( $_GET['page'] ) && ( 'jr_mt_settings' === $_GET['page'] )
179
+ should work, but redirects Save Changes to options.php
180
+ */
181
+ require_once( jr_mt_path() . 'includes/admin-functions.php' );
182
+ /* Admin panel
183
+ */
184
+ require_once( jr_mt_path() . 'includes/admin.php' );
185
+ }
186
+ }
187
+
188
+ /*
189
+ Research Notes:
190
+ 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:
191
+ - is_admin()
192
+ - is_user_logged_in()
193
+ - get_option("page_on_front") - ID of home page; zero if Reading Settings NOT set to a Static Page of a WordPress Page
194
+
195
+ */
196
+
197
+ ?>
js/index.html ADDED
File without changes
js/sticky.js ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ Whether pre-processed in PHP when passed, or within this JavaScript,
37
+ all comparisons are effectively case-insensitive, by converting
38
+ all values to lower-case.
39
+
40
+ Version 6.0 - this code has not been upgraded to support Site Aliases!
41
+ */
42
+ window.onload =
43
+ function ( ) {
44
+ var allCookies, keywordMatch, pos, valueStart, cookieArray, query, homeUrl, siteAdmin, appendSetting, overrideQueries, overrideQueriesEmpty, hrefs, i, max, href, colonSlashSlash, hrefCompare, addQuery, posQuestionMark, posNumberSign, hrefQueries,
45
+ cookieEquals = 'jr-mt-remember-query=',
46
+ cookieSplit = '; ';
47
+
48
+ /* Check if there are any Cookies at all.
49
+ */
50
+ if ( '' !== allCookies ) {
51
+ allCookies = cookieSplit + document.cookie + cookieSplit;
52
+ keywordMatch = cookieSplit + cookieEquals;
53
+ pos = allCookies.indexOf( keywordMatch );
54
+ /* Check if our cookie is present.
55
+ */
56
+ if ( -1 !== pos ) {
57
+ valueStart = pos + keywordMatch.length;
58
+ /* Extract Value of Cookie, which is found after the equals sign and before the semicolon
59
+ */
60
+ cookieArray = JSON.parse( decodeURIComponent( allCookies.substring( pos + keywordMatch.length, allCookies.indexOf( cookieSplit, pos + cookieSplit.length ) ) ) );
61
+ /* Assign Cookie array elements to meaningfully-named variables.
62
+ */
63
+ query = cookieArray[0];
64
+ appendSetting = cookieArray[1];
65
+ overrideQueries = cookieArray[2];
66
+ overrideQueriesEmpty = ( 0 === overrideQueries.length );
67
+
68
+ homeUrl = document.getElementById( 'jr-mt-home-url' )['title'];
69
+ siteAdmin = document.getElementById( 'jr-mt-site-admin' )['title'];
70
+
71
+ hrefs = document.getElementsByTagName ( 'a' );
72
+ for ( i = 0, max = hrefs.length; i < max; i++ ) {
73
+ href = hrefs [ i ] ['href'];
74
+ colonSlashSlash = href.indexOf( '://' );
75
+ /* Ignore Relative URLs: those without ://
76
+ */
77
+ if ( -1 !== colonSlashSlash ) {
78
+ hrefCompare = href.substring( colonSlashSlash + 3 ).toLowerCase();
79
+ if ( 'www.' === hrefCompare.substring( 0, 4 ) ) {
80
+ hrefCompare = hrefCompare.substring( 4 );
81
+ }
82
+ hrefCompare = hrefCompare.replace( /\\/g, '/' );
83
+ addQuery = '';
84
+ if ( hrefCompare.substring( 0, homeUrl.length ) === homeUrl ) {
85
+ if ( hrefCompare.substring( 0, siteAdmin.length ) !== siteAdmin ) {
86
+ posQuestionMark = href.indexOf( '?' );
87
+ posNumberSign = href.indexOf( '#' );
88
+ if ( -1 === posNumberSign ) {
89
+ posNumberSign = href.length;
90
+ }
91
+ /* Only add a Query if one does not already exist.
92
+ */
93
+ if ( -1 === posQuestionMark ) {
94
+ /* Query must be before the Fragment (#anchor),
95
+ when one exists.
96
+ */
97
+ addQuery = '?';
98
+ } else {
99
+ /* Query exists because "?" found in URL.
100
+ Check if setting set to add query when one already exists.
101
+ If not, don't touch this URL.
102
+ */
103
+ if ( appendSetting ) {
104
+ addQuery = '&';
105
+ hrefQueries = href.substring( posQuestionMark + 1, posNumberSign ).split( '&' );
106
+ /* Don't append Sticky query if it is already present in the URL
107
+ */
108
+ if ( -1 !== hrefQueries.indexOf( query ) ) {
109
+ addQuery = '';
110
+ } else {
111
+ if ( !overrideQueriesEmpty ) {
112
+ for ( j = 0, hrefQueriesLength = hrefQueries.length; j < hrefQueriesLength; j++ ) {
113
+ /* Don't append Sticky query if an Override query is present in URL
114
+ */
115
+ if ( -1 !== overrideQueries.indexOf( hrefQueries[ j ].toLowerCase() ) ) {
116
+ /* Override query already in URL.
117
+ */
118
+ addQuery = '';
119
+ break;
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+ }
126
+ }
127
+ }
128
+ if ( '' !== addQuery ) {
129
+ /* No override or sticky query already in URL, so safe to add current sticky query.
130
+ */
131
+ hrefs [ i ] ['href'] = href.substring( 0, posNumberSign ) + addQuery + query + href.substring( posNumberSign );
132
+ }
133
+ }
134
+ }
135
+ }
136
+ }
137
+ };
js/tabs.js ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Hide all but the Tab selected.
2
+ <div> is used in the HTML to enclose the HTML peculiar to a Tab,
3
+ with id=jr-mt-settingsn where the last "n" is a unique number from 1 to the number of Tabs.
4
+ onClick is used on a <a> to activate this function.
5
+
6
+ Bold only the Tab selected,
7
+ actually it is Bolder and Bold, instead of Bold and Normal.
8
+ */
9
+ function jrMtTabs( tab, ntabs ) {
10
+ for ( i = 1; i <= ntabs; i++ ) {
11
+ if ( i === tab ) {
12
+ show = 'block';
13
+ classes = 'nav-tab nav-tab-active';
14
+ } else {
15
+ show = 'none';
16
+ classes = 'nav-tab';
17
+ }
18
+ document.getElementById( 'jr-mt-settings' + i ).style.display = show;
19
+ document.getElementById( 'jr-mt-tabs' + i ).className = classes;
20
+ }
21
+ };
readme.txt ADDED
@@ -0,0 +1,442 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.1
7
+ Stable tag: 7.0.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 WordPress Pages, Posts or other non-Admin pages. Or Site Home.
12
+
13
+ == Description ==
14
+
15
+ **Version 7 adds exhaustive checking and correction of the plugin's Settings that may have become corrupted**
16
+
17
+ Settings provide many different ways to Select which Theme should appear where on your WordPress web site:
18
+
19
+ * Just for Site Home
20
+ * By URL (Version 5 adds support for Query keyword=value as part of a unique URL);
21
+ * By Prefix URL, matching all URLs that begin with the same characters ("Prefix URL");
22
+ * By Wildcard Prefix URL with one or more Asterisks ("*") representing arbritrary subdirectories in the URL;
23
+ * By Query Keyword found in any URL, not matter what the Value;
24
+ * By Query keyword=value found in any URL;
25
+ * By Sticky Query keyword=value that sets the Theme for a given Visitor until an Override Query keyword=value is found in a future URL (Advanced Setting requiring the Visitor's browser to accept Cookies; incompatible with certain plugins that block Cookies);
26
+ * Everywhere (Advanced Setting that overrides the WordPress Active Theme);
27
+ * All Pages (Advanced Setting that works with most, but not all, Themes and Plugins);
28
+ * All Posts (Advanced Setting that works with most, but not all, Themes and Plugins).
29
+
30
+ None of the Themes in the WordPress Theme Directory alter the appearance of the WordPress Admin panels. As a result, this plugin does not allow Theme Selection entries to specify URLs for WordPress Admin panels.
31
+
32
+ **Use with Paid Themes**: On-going full scale testing of Themes by this plugin's author is only possible if the Theme is found in the WordPress Theme Directory. Although (Version 5 of) this plugin should now work with all Themes, any problems encountered while using Paid Themes will be difficult to diagnose. As described in the FAQ tab, a WordPress Network (Multisite) is an alternative to this plugin, as a way to create a single web site with more than one Theme.
33
+
34
+ A similar situation exists with Paid Plugins.
35
+
36
+ **Use with Plugins that Cache**: You may find that you have to flush the Cache whenever you change Settings in the *jonradio Multiple Themes* plugin. Some Caching plugins only cache for visitors who are not logged in as users, so be sure to log out before testing the results of your *jonradio Multiple Themes* settings.
37
+
38
+ **Changing Theme Options (Widgets, Sidebars, Menus, Templates, Background, Header, etc.)?**: After installing and activating the plugin, see the plugin's Settings page and click on the **Theme Options** tab for important information on changing Options for Themes other than the Active Theme.
39
+
40
+ **How it Works**: The plugin does not change the Active Theme defined to WordPress in the Appearances-Themes Admin panel. Instead, it dynamically (and selectively) overrides that setting. Which means that simply deactivating (or deleting) this plugin will restore the way that Themes were displayed prior to installing this plugin. However, in some situations, it is possible to inadvertently alter Theme Options for the Active Theme when using either of the Methods described on the plugin's Setting page Theme Options tab.
41
+
42
+ == Installation ==
43
+
44
+ This section describes how to install the *jonradio Multiple Themes* plugin and get it working.
45
+
46
+ 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.
47
+ 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.
48
+ 1. Be sure that all Themes you plan to use have been installed.
49
+ 1. Select Themes to be used on the Settings or Advanced Settings tab of 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.
50
+ 1. If you need to change Theme Options (Widgets, Sidebars, Menus, Templates, Background, Header, etc.) for any Theme *other than* the Active Theme, see the plugin's Settings page and click on the **Theme Options** tab for important information.
51
+
52
+ == Frequently Asked Questions ==
53
+
54
+ = What if my Themes or other plugins don't seem to be working with the jonradio Multiple Themes plugin? =
55
+
56
+ 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").
57
+
58
+ 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.
59
+
60
+ = Will this plugin work with Paid Themes? =
61
+
62
+ With the massive rewrite of Theme Selection logic in Version 5 of this plugin, it should now work with all Paid Themes and Plugins. 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.
63
+
64
+ 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.
65
+
66
+ 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.
67
+
68
+ = How do I change the Theme Options (Widgets, Sidebars, Menus, Background, Header, etc.) used for each Theme? =
69
+
70
+ For the Active Theme, nothing changes when using the jonradio Multiple Themes plugin. For other Themes, selected using this plugin, changing Theme Options is explained, in detail, on the Theme Options tab of the plugin's Settings page.
71
+
72
+ = How do I change the Template for a specific Page or Post? =
73
+
74
+ For the Current Theme, nothing changes when using the jonradio Multiple Themes plugin. For a Page or Post where another Theme is displayed, as selected by this plugin's Settings, specifying the Template to be used is explained, in detail, on the Theme Options tab of the plugin's Settings page.
75
+
76
+ = How do I select a Theme for a Category of Posts? =
77
+
78
+ 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:
79
+
80
+ 1. In the WordPress Admin panels, go to Settings-Permalinks
81
+ 1. Specify a Permalinks structure that begins with /%category%/
82
+ 1. Push the Save Changes button
83
+ 1. Go to Settings-Multiple Themes plugin
84
+ 1. In the Section "For An Individual Page, Post or other non-Admin page", select the Theme for the Category of Posts
85
+ 1. Enter the URL of the Categories page, e.g. - http://domain.com/news/
86
+ 1. Click the checkbox "Select here if URL is a Prefix"
87
+ 1. Push the Save Changes button
88
+
89
+ = How do I Edit a Theme? =
90
+
91
+ WordPress includes a built-in Theme Editor. Select Editor in the Admin panel's Appearance menu items on the left sidebar.
92
+
93
+ 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.
94
+
95
+ 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.
96
+
97
+ 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.
98
+
99
+ = How do I use Elegant's epanel? =
100
+
101
+ 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.
102
+
103
+ To make changes to other Active Themes that you will be specifying with the jonradio Multiple Themes plugin:
104
+
105
+ 1. Deactivate jonradio Multiple Themes
106
+ 1. Install the Theme Test Drive plugin found at http://wordpress.org/extend/plugins/theme-test-drive/
107
+ 1. Activate the Theme Test Drive plugin
108
+ 1. Go to Appearance-Theme Test Drive
109
+ 1. In the Usage section, select an alternate Theme you will be using with jonradio Multiple Themes
110
+ 1. Push the Enable Theme Drive button at the bottom
111
+ 1. Click on the Appearance menu item on the left sidebar of the WordPress Admin panel to refresh the submenu
112
+ 1. Click on the submenu item titled with your Elegant theme's name followed by "Theme Options"
113
+ 1. Elegant's epanel will now appear
114
+ 1. Make all the changes for this Theme, being sure to push the Save button
115
+ 1. If you have more than one alternate Theme with Options you wish to change, repeat Steps 4-10 for each alternate Theme
116
+ 1. Deactivate the Theme Test Drive plugin
117
+ 1. Activate jonradio Multiple Themes
118
+ 1. Changes to the Options for the Current Theme can now be made normally, just as you would without either plugin
119
+ 1. Both the alternate and Current Themes should now display all Theme options properly when selected through the jonradio Multiple Themes plugin
120
+
121
+ Thanks to Elegant for allowing us to test copies of any of their Themes provided by their customers.
122
+
123
+ = What happens when I change Permalinks? =
124
+
125
+ Although it depends on what kind of change you make to your Permalink structure, you should expect to have to replace (delete and add) all of the plugin's Settings that specify a URL.
126
+
127
+ = I added a new entry but why doesn't it appear in the list of entries? =
128
+
129
+ You should have seen an explanatory error message after hitting the Save Changes button.
130
+
131
+ = How can I change the Theme for an entry? =
132
+
133
+ You will need to delete the entry and add it again, with the new Theme specified.
134
+
135
+ == Screenshots ==
136
+
137
+ 1. Top of Settings tab on Plugin's Settings page
138
+ 2. Bottom of Settings tab on Plugin's Settings page
139
+ 3. Advanced Settings tab on Plugin's Settings page
140
+ 4. Theme Options tab on Plugin's Settings page
141
+ 5. System Information tab on Plugin's Settings page
142
+ 6. New in V5 tab on Plugin's Settings page
143
+
144
+ == Changelog ==
145
+
146
+ = 7.0.1 =
147
+ * Fix Query Matching when Value is an Integer in Query Settings
148
+
149
+ = 7.0 =
150
+ * Check and cleanup Settings on every viewing of the Settings page, to maximize compatibility with previous versions
151
+ * Store PostID as String instead of Integer in URL Settings so it will match incoming URL with p=id, etc.
152
+ * Make sure that both Query Keyword and Value are never any Numeric type, but always String
153
+ * Correct numerous small bugs
154
+
155
+ = 6.0.2 =
156
+ * Fix bug that stripped off Queries in URL Settings
157
+
158
+ = 6.0.1 =
159
+ * Store $wp->public_query_vars in Internal Settings for use before 'init' action
160
+ * Tolerate missing $_SERVER['QUERY_STRING']
161
+
162
+ = 6.0 =
163
+ * Add URL Alias settings
164
+ * Move "Settings" link to beginning of links on Installed Plugins Admin page
165
+
166
+ = 5.0.3 =
167
+ * Remove Cleanup code for Settings for non-existent Themes, as it conflicts with delete/reinstall theme version upgrades, and certain caching plugins
168
+
169
+ = 5.0.2 =
170
+ * Remove /downgrade/ directory in case it caused the reported PCLZIP_ERR_BAD_FORMAT errors
171
+
172
+ = 5.0.1 =
173
+ * Fix All Pages and All Posts by complete rewrite of Theme Selection logic for those Advanced Settings
174
+
175
+ = 5.0 =
176
+ * Major rewrite of the Theme Selection logic
177
+ * Tabs added to the Settings page, for easier navigation
178
+ * Greatly expanded compatibility with other Plugins and Themes
179
+ * Allow ?keyword=value&keyword=value Queries in URL, URL Prefix and URL Prefix with Asterisk ("*") Theme Selection entries
180
+ * Accurate Theme Selection even for plugins and themes that request Stylesheet or Template information before WordPress is fully loaded
181
+ * Tabs for the Setting page written in JavaScript for instant switching between tabs and preservation of input data, e.g. - switch between Settings and Advanced Settings tabs without having to retype your changes when you switch back
182
+ * Theme Selection entries, if any, displayed in the order in which they are processed, to clarify which Theme will be displayed for any given URL
183
+ * Complete How-To details on Theme Option and Template selection right on the Settings page, replacing the FAQs in the WordPress Plugin Directory
184
+ * Automatic deletion of Theme Selection entries for Themes that have been deleted
185
+ * Enhanced performance with tighter code, and less of it, on the public side of your WordPress site
186
+ * Changing Permalinks invalidates more Theme Selection settings than in previous versions
187
+ * Changing the Theme for an Entry requires Deletion of the old Entry before or after adding the same Entry with the new Theme specified
188
+ * The new Theme Selection logic, based on URL Matching rather than Page, Post, Attachment, Category and Archive IDs, requires a conversion of some Settings from prior versions of the plugin. This conversion to the new format occurs automatically the first time that Version 5 runs. Old format settings are retained, transparently without being displayed on the Settings page, to allow downgrading to Version 4 from Version 5.
189
+
190
+ = 4.11.3 =
191
+ * Fix Array to String Warning on some Search plugins by rewriting jt_mt_themes_defined() which creates list of Themes referenced in plugin Settings
192
+ * Add More Diagnostic Information to Settings page
193
+ * Suggest "URL Prefix" setting when "URL" setting does not work, especially for WooCommerce
194
+ * Detect Memberium plugins and explain that Sticky will not work with Membership System V2 because it blocks Cookies
195
+ * Add Warning and change one confusing Error Message when Query is incorrectly included in URL of Page/Post entry
196
+
197
+ = 4.11.2 =
198
+ * Made all Query comparisons (URL match Setting) case insensitive
199
+ * Eliminate Connection Info prompt from Settings page that occurred for certain User Permissions
200
+ * Add File Permissions table to Settings
201
+
202
+ = 4.11.1 =
203
+ * Correct foreach() error
204
+
205
+ = 4.11 =
206
+ * Complete Rewrite of Sticky logic, adding additional Settings, including Override
207
+
208
+ = 4.10.1 =
209
+ * Sticky: add a unique Query to URL so that Caching plugins will cache separate copies for each Theme used on a particular page
210
+
211
+ = 4.10 =
212
+ * 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
213
+ * Enhance performance by eliminating processing related to each Type of Setting when no Setting entries of that Type exist
214
+
215
+ = 4.9 =
216
+ * Add an Asterisk ("*") to match any Subdirectory at a given level of the File Hierarchy, as another form of the Prefix URL option
217
+ * Reorganize Settings page
218
+
219
+ = 4.8 =
220
+ * Delay intercept of get_options 'stylesheet' and 'template' until 'plugins_loaded' (NextGen Gallery conflict)
221
+ * Check for illegal characters in Keyword and Value of Query portion of URL in Settings fields
222
+
223
+ = 4.7.3 =
224
+ * Add support for dot in URL Queries (keyword or value) by replacing parse_str()
225
+ * Removed subfolder /includes/debug/
226
+
227
+ = 4.7.2 =
228
+ * Do not execute select-theme.php on Admin panels, to eliminate error message whenever any plugin is uninstalled
229
+ * Handle URL Query Keyword[]=Value
230
+ * Add Polylang to list of incompatible plugins
231
+
232
+ = 4.7.1 =
233
+ * Handle PHP without mbstring extension
234
+
235
+ = 4.7 =
236
+ * Add option to select a Theme based on Query Keyword and Value pair in URL
237
+ * Redesign how Query entries are stored
238
+ * Full testing completed with WordPress Version 3.8
239
+
240
+ = 4.6 =
241
+ * Add option to select a Theme based on Query Keyword in URL
242
+ * Rearrange Settings page
243
+
244
+ = 4.5.2 =
245
+ * Eliminate Fatal Error if php zip_open() function is not available, when readme.txt is out of date
246
+
247
+ = 4.5.1 =
248
+ * Remove %E2%80%8E suffix from URLs being entered
249
+
250
+ = 4.5 =
251
+ * Check with get_page_by_path() and get_posts( array( 'name' => $page_url ) ) if url_to_postid() fails to find URL input
252
+
253
+ = 4.4 =
254
+ * 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
255
+ * Prevent Fatal Error for Versions of WordPress before 3.4, and Deactivate Plugin instead, because plugin requires at least 3.4 to function
256
+ * Security: require "switch_themes" Capability rather than "manage_options" Capability to access plugin's Settings page
257
+
258
+ = 4.3 =
259
+ * Add SSL support so that visitors can view the WordPress site with https:// URLs and Site URL can be https://
260
+
261
+ = 4.2 =
262
+ * Add option to override WordPress Current Theme
263
+ * Security enhancements to eliminate direct execution of .php files
264
+
265
+ = 4.1.1 =
266
+ * Handle situations where readme.txt file in plugin's directory cannot be read or written
267
+
268
+ = 4.1 =
269
+ * Support for non-alphanumeric characters in URLs, e.g. - languages using characters not in the English alphabet
270
+ * Support for Live Search feature of KnowHow Theme
271
+ * Display errors, not settings, on plugin's Admin page for activated BuddyPress or Theme Test Drive plugins, or old versions of WordPress
272
+ * Add error checking/messages and diagnostic information to plugin's Admin page
273
+
274
+ = 4.0.2 =
275
+ * Prevent Warning and Notice by initializing global $wp
276
+
277
+ = 4.0.1 =
278
+ * Prevent Fatal Error by initializing global $wp_rewrite
279
+
280
+ = 4 =
281
+ * Discovered url_to_postid() function, to address situations where Slug differed from Permalink, such as Posts with Year/Month folders
282
+
283
+ = 3.3.1 =
284
+ * Fix White Screen of Death on a Page selected by plugin
285
+
286
+ = 3.3 =
287
+ * Support Child Themes and any other situation where stylesheet and template names are not the same
288
+
289
+ = 3.2 =
290
+ * Correct Problem with P2 Theme, and its logged on verification at wp-admin/admin-ajax.php?p2ajax=true&action=logged_in_out&_loggedin={nonce}
291
+ * Add "Settings Saved" message to Admin page
292
+ * Tested with WordPress Version 3.5 beta
293
+
294
+ = 3.1 =
295
+ * Add Support for Prefixes, where all URLs beginning with the specified characters ("Prefix") can be assigned to a specified Theme
296
+
297
+ = 3.0 =
298
+ * Add Support for Categories and Archives when no Permalinks exist (support already existed Categories and Archives with Permalinks)
299
+ * Resolve several minor bugs
300
+
301
+ = 2.9 =
302
+ * Rewrite much of the Settings page and Plugin Directory documentation
303
+ * Add Support for IIS which returns incorrect values in $_SERVER['REQUEST_URI']
304
+ * Make it easier to select the Theme for the Site Home by providing a new Settings field
305
+ * 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
306
+ * Add version upgrade detection to add, remove and update Settings fields
307
+ * Move Settings link on Plugins page from beginning to end of links
308
+
309
+ = 2.0 =
310
+ * Address pecularities of wp_make_link_relative() related to root-based WordPress sites using Permalinks
311
+
312
+ = 1.1 =
313
+ * Fix foreach failing on some systems, based on PHP warning level
314
+
315
+ = 1.0 =
316
+ * Make plugin conform to WordPress plugin repository standards.
317
+ * Beta testing completed.
318
+
319
+ == Upgrade Notice ==
320
+
321
+ = 7.0.1 =
322
+ Correctly handle p= and page_id= in Query Settings
323
+
324
+ = 7.0 =
325
+ Checks all Settings whenever Settings page displayed
326
+
327
+ = 6.0.2 =
328
+ Correct bug that stripped Queries from URLs in Settings
329
+
330
+ = 6.0.1 =
331
+ Tolerate missing $_SERVER['QUERY_STRING'] and $wp->public_query_vars not set up yet
332
+
333
+ = 6.0 =
334
+ Support Domain Mapping, Parked Domains and other Site Alias usages
335
+
336
+ = 5.0.3 =
337
+ Remove cleanup of non-existent themes specified in Settings
338
+
339
+ = 5.0.2 =
340
+ Remove /downgrade/ directory that may have caused PCLZIP_ERR_BAD_FORMAT errors on some web hosts
341
+
342
+ = 5.0.1 =
343
+ Correct All Pages and All Posts (Advanced) Setting bug
344
+
345
+ = 5.0 =
346
+ Greatly expanded compatibility with other Plugins and Themes
347
+
348
+ = 4.11.2 =
349
+ Standardize to case insensitive Query comparisons and eliminate Connection Info prompt on Settings page
350
+
351
+ = 4.11.1 =
352
+ Fix foreach() error
353
+
354
+ = 4.11 =
355
+ Complete rewrite of Sticky logic
356
+
357
+ = 4.10.1 =
358
+ Make Sticky work with Caching plugins
359
+
360
+ = 4.10 =
361
+ Performance improvements and add Sticky Queries
362
+
363
+ = 4.9 =
364
+ Allow Prefix URLs to match all subdirectories with an Asterisk ("*")
365
+
366
+ = 4.8 =
367
+ Compatibility with NextGen Gallery plugin
368
+
369
+ = 4.7.3 =
370
+ Allow dots in URL Queries
371
+
372
+ = 4.7.2 =
373
+ Avoid Error Message during Uninstall of other Plugins
374
+
375
+ = 4.7.1 =
376
+ Avoid mb_ function errors for PHP without mbstring extension
377
+
378
+ = 4.7 =
379
+ Select Theme by Query Keyword/Value pair in URL
380
+
381
+ = 4.6 =
382
+ Select Theme by Query Keyword in URL
383
+
384
+ = 4.5.2 =
385
+ Fix zip_open Fatal Error
386
+
387
+ = 4.5.1 =
388
+ Fix %E2%80%8E suffix problem on input URLs
389
+
390
+ = 4.5 =
391
+ Handle URL input for non-standard Pages and Posts
392
+
393
+ = 4.4 =
394
+ Fix errors when new Network site created or old WordPress version used, and correct Setting page Permissions to "switch_themes"
395
+
396
+ = 4.3 =
397
+ Add SSL support for sites with https:// URLs
398
+
399
+ = 4.2 =
400
+ Add "Select Theme for Everything" feature and improve security
401
+
402
+ = 4.1.1 =
403
+ Resolve issues with readme.txt permissions introduced in Version 4.1's compatibility checking
404
+
405
+ = 4.1 =
406
+ Support non-English alphabet in URLs and Live Search feature in KnowHow Theme
407
+
408
+ = 4.0.2 =
409
+ Fix "Warning: in_array() expects parameter 2 to be array, null given in domain.com/wp-includes/rewrite.php on line 364"
410
+
411
+ = 4.0.1 =
412
+ 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"
413
+
414
+ = 4 =
415
+ Fix Posts not working in some Permalink setups, most notably Year/Month
416
+
417
+ = 3.3.1 =
418
+ Fix White Screen of Death on a Page, Post or other element selected by plugin
419
+
420
+ = 3.3 =
421
+ Remove Restriction that Stylesheet Name must match Template Name, which it does not with Child Themes
422
+
423
+ = 3.2 =
424
+ Add Support for P2 Theme and provide "Settings Saved" message
425
+
426
+ = 3.1 =
427
+ Allow Prefix URLs to be used to specify where a Theme will be displayed
428
+
429
+ = 3.0 =
430
+ Improve support for Categories and Archives, and eliminate all known bugs.
431
+
432
+ = 2.9 =
433
+ Improve Settings fields, correct display of wrong Current Theme in Appearance-Themes Admin panel, and add IIS Support.
434
+
435
+ = 2.0 =
436
+ Selecting Individual Pages and Posts on a WordPress site installed in the root and using Permalinks now works correctly.
437
+
438
+ = 1.1 =
439
+ Eliminate possibility of foreach error message if PHP warning level is set at a high level
440
+
441
+ = 1.0 =
442
+ Beta version 0.9 had not been tested when installed from the WordPress Plugin Repository
uninstall.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ $setting_names = array(
9
+ 'jr_mt_settings',
10
+ 'jr_mt_internal_settings',
11
+ 'jr_mt_all_themes'
12
+ );
13
+ if ( function_exists( 'is_multisite' ) && is_multisite() ) {
14
+ global $wpdb, $site_id;
15
+ $blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = $site_id" );
16
+ foreach ( $blogs as $blog_obj ) {
17
+ foreach ( $setting_names as $name ) {
18
+ delete_blog_option( $blog_obj->blog_id, $name );
19
+ }
20
+ }
21
+ } else {
22
+ foreach ( $setting_names as $name ) {
23
+ delete_option( $name );
24
+ }
25
+ }
26
+
27
+ ?>