Multiple Themes - Version 5.0.2

Version Description

  • Remove /downgrade/ directory in case it caused the reported PCLZIP_ERR_BAD_FORMAT errors
Download this release

Release Info

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

Version 5.0.2

includes/admin-functions.php ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* Exit if .php file accessed directly
4
+ */
5
+ if ( !defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ function jr_mt_theme_entry( $type, $theme = '', $display1 = NULL, $display2 = NULL ) {
10
+ $three_dots = '&#133;';
11
+ $before = '<li>Delete <input type="checkbox" id="del_entry" name="jr_mt_settings[del_entry][]" value="';
12
+ $after = '" /> &nbsp; ';
13
+ $theme_equals = 'Theme=' . wp_get_theme( $theme )->Name . '; ';
14
+ switch ( $type ) {
15
+ case 'Query':
16
+ echo $before
17
+ . 'query'
18
+ . '='
19
+ . $display1
20
+ . '='
21
+ . $display2
22
+ . $after
23
+ . $theme_equals;
24
+ if ( '*' !== $display2 ) {
25
+ $settings = get_option( 'jr_mt_settings' );
26
+ $sticky = isset( $settings['remember']['query'][ $display1 ][ $display2 ] );
27
+ $override = isset( $settings['override']['query'][ $display1 ][ $display2 ] );
28
+ if ( $sticky ) {
29
+ if ( $override ) {
30
+ echo 'Sticky/Override ';
31
+ } else {
32
+ echo 'Sticky ';
33
+ }
34
+ } else {
35
+ if ( $override ) {
36
+ echo 'Override ';
37
+ }
38
+ }
39
+ }
40
+ echo 'Query='
41
+ . '<code>'
42
+ . home_url()
43
+ . "/</code>$three_dots<code>/?"
44
+ . '<b><input type="text" readonly="readonly" disable="disabled" name="jr_mt_delkw" value="'
45
+ . $display1
46
+ . '" size="'
47
+ . jr_mt_strlen( $display1 )
48
+ . '" /></b>'
49
+ . '=';
50
+ if ( '*' === $display2 ) {
51
+ echo '</code>' . $three_dots;
52
+ } else {
53
+ echo '<b><input type="text" readonly="readonly" disable="disabled" name="jr_mt_delkwval" value="'
54
+ . $display2
55
+ . '" size="'
56
+ . jr_mt_strlen( $display2 )
57
+ . '" /></b></code>';
58
+ }
59
+ break;
60
+ case 'url':
61
+ case 'url_prefix':
62
+ case 'url_asterisk':
63
+ echo $before
64
+ . $type
65
+ . '='
66
+ . 'url'
67
+ . '='
68
+ . $display1
69
+ . $after
70
+ . $theme_equals
71
+ . $display2
72
+ . '=<code>' . $display1 . '</code>';
73
+ break;
74
+ case 'wordpress':
75
+ echo '<li><a href="'
76
+ . get_admin_url()
77
+ . 'themes.php" class="button-primary">Change</a> &nbsp; '
78
+ . 'Theme='
79
+ . wp_get_theme()->Name
80
+ . ', the Theme chosen as Active from Appearance-Themes in the WordPress Admin panels';
81
+ break;
82
+ default:
83
+ echo $before
84
+ . $type
85
+ . $after
86
+ . $theme_equals
87
+ . $display1;
88
+ if ( 'site_home' === $type ) {
89
+ echo ' (<code>' . home_url() . '</code>)';
90
+ }
91
+ echo ' setting (see Advanced Settings tab)';
92
+ break;
93
+ }
94
+ echo '</li>';
95
+ }
96
+
97
+ // $theme_name is the name of the Theme's folder within the Theme directory
98
+ function jr_mt_themes_field( $field_name, $theme_name, $setting, $excl_current_theme ) {
99
+ echo "<select id='$field_name' name='$setting" . "[$field_name]' size='1'>";
100
+ if ( empty( $theme_name ) ) {
101
+ $selected = 'selected="selected"';
102
+ } else {
103
+ $selected = '';
104
+ }
105
+ echo "<option value='' $selected></option>";
106
+ foreach ( jr_mt_all_themes() as $folder => $theme_obj ) {
107
+ if ( $excl_current_theme ) {
108
+ if ( ( jr_mt_current_theme( 'stylesheet' ) == $theme_obj['stylesheet'] ) && ( jr_mt_current_theme( 'template' ) == $theme_obj['template'] ) ) {
109
+ // Skip the Current Theme
110
+ continue;
111
+ }
112
+ }
113
+ if ( $theme_name === $folder ) {
114
+ $selected = 'selected="selected"';
115
+ } else {
116
+ $selected = '';
117
+ }
118
+ $name = $theme_obj->Name;
119
+ echo "<option value='$folder' $selected>$name</option>";
120
+ }
121
+ echo '</select>' . PHP_EOL;
122
+ }
123
+
124
+ /**
125
+ * Update available for Plugin?
126
+ *
127
+ * @return bool - TRUE if an update is available in the WordPress Repository,
128
+ * FALSE if no update is available or if the update_plugins transient is not available
129
+ * (which also results in an error message).
130
+ **/
131
+ function jr_mt_plugin_update_available() {
132
+ global $jr_mt_update_plugins;
133
+ if ( !isset( $jr_mt_update_plugins ) ) {
134
+ $transient = get_site_transient( 'update_plugins' );
135
+ if ( FALSE === $transient ) {
136
+ // Error
137
+ return FALSE;
138
+ } else {
139
+ $jr_mt_update_plugins = $transient;
140
+ }
141
+ }
142
+ if ( empty( $jr_mt_update_plugins->response ) ) {
143
+ return FALSE;
144
+ }
145
+ return array_key_exists( jr_mt_plugin_basename(), $jr_mt_update_plugins->response );
146
+ }
147
+
148
+ /**
149
+ * Prepare URL Query Value
150
+ *
151
+ * Sanitize and standardize a URL Query Value for storage in a database.
152
+ * Does not support ?keyword[]=value, i.e. - $value cannot be an Array.
153
+ *
154
+ * @param string $value URL Query Value to be sanitized and standardized; will fail if array
155
+ * @return string URL Query Value after being sanitized and standardized
156
+ */
157
+ function jr_mt_prep_query_value( $value ) {
158
+ return str_ireplace( '%e2%80%8e', '', jr_mt_strtolower( trim( $value ) ) );
159
+ }
160
+ function jr_mt_prep_query_keyword( $keyword ) {
161
+ return jr_mt_prep_query_value( $keyword );
162
+ }
163
+
164
+ ?>
includes/admin.php ADDED
@@ -0,0 +1,1715 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Exit if .php file accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
+
5
+ // Add Link to the plugin's entry on the Admin "Plugins" Page, for easy access
6
+ add_filter( 'plugin_action_links_' . jr_mt_plugin_basename(), 'jr_mt_plugin_action_links', 10, 1 );
7
+
8
+ /**
9
+ * Creates Settings entry right on the Plugins Page entry.
10
+ *
11
+ * Helps the user understand where to go immediately upon Activation of the Plugin
12
+ * by creating entries on the Plugins page, right beside Deactivate and Edit.
13
+ *
14
+ * @param array $links Existing links for our Plugin, supplied by WordPress
15
+ * @param string $file Name of Plugin currently being processed
16
+ * @return string $links Updated set of links for our Plugin
17
+ */
18
+ function jr_mt_plugin_action_links( $links ) {
19
+ // The "page=" query string value must be equal to the slug
20
+ // of the Settings admin page.
21
+ array_push( $links, '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=jr_mt_settings' . '">Settings</a>' );
22
+ return $links;
23
+ }
24
+
25
+
26
+ // Admin Page
27
+
28
+ add_action( 'admin_menu', 'jr_mt_admin_hook' );
29
+ // Runs just before admin_init (below)
30
+
31
+ /**
32
+ * Add Admin Menu item for plugin
33
+ *
34
+ * Plugin needs its own Page in the Settings section of the Admin menu.
35
+ *
36
+ */
37
+ function jr_mt_admin_hook() {
38
+ // Add Settings Page for this Plugin
39
+ global $jr_mt_plugin_data;
40
+ add_theme_page( $jr_mt_plugin_data['Name'], 'Multiple Themes plugin', 'switch_themes', 'jr_mt_settings', 'jr_mt_settings_page' );
41
+ add_options_page( $jr_mt_plugin_data['Name'], 'Multiple Themes plugin', 'switch_themes', 'jr_mt_settings', 'jr_mt_settings_page' );
42
+ /* Cleanup Settings before using them.
43
+ Presently, this just checks for Themes that are no longer installed,
44
+ but are referenced in the Settings.
45
+ Settings referencing such Themes are deleted.
46
+ */
47
+ require_once( jr_mt_path() . 'includes/settings-cleanup.php' );
48
+ }
49
+
50
+ global $jr_mt_kwvalsep;
51
+ /* Everything is converted to lower-case, so upper-case letter makes a good keyword-value separator
52
+ */
53
+ $jr_mt_kwvalsep = 'A';
54
+
55
+ add_action( 'admin_enqueue_scripts', 'jr_mt_admin_enqueue_scripts' );
56
+ function jr_mt_admin_enqueue_scripts() {
57
+ global $jr_mt_plugin_data;
58
+ wp_enqueue_script( 'jr_mt_tabs', plugins_url() . '/' . dirname( jr_mt_plugin_basename() ) . '/js/tabs.js', array(), $jr_mt_plugin_data['Version'] );
59
+ }
60
+
61
+ /**
62
+ * Settings page for plugin
63
+ *
64
+ * Display and Process Settings page for this plugin.
65
+ *
66
+ */
67
+ function jr_mt_settings_page() {
68
+ global $jr_mt_plugin_data, $jr_mt_plugins_cache;
69
+ $jr_mt_plugins_cache = get_plugins();
70
+ add_thickbox();
71
+ echo '<div class="wrap">';
72
+ echo '<h2>' . $jr_mt_plugin_data['Name'] . '</h2>';
73
+
74
+ // Required because it is only called automatically for Admin Pages in the Settings section
75
+ settings_errors( 'jr_mt_settings' );
76
+
77
+ $theme_obj = wp_get_theme();
78
+ $theme = $theme_obj->Name;
79
+ $theme_version = $theme_obj->Version;
80
+ global $jr_mt_options_cache;
81
+
82
+ $current_wp_version = get_bloginfo( 'version' );
83
+
84
+ global $jr_mt_plugins_cache;
85
+
86
+ $compatible = TRUE;
87
+
88
+ // Check for incompatible plugins that have been activated: BuddyPress and Theme Test Drive
89
+ global $jr_mt_incompat_plugins;
90
+ foreach ( $jr_mt_plugins_cache as $rel_path => $plugin_data ) {
91
+ if ( in_array( $plugin_data['Name'], $jr_mt_incompat_plugins ) && is_plugin_active( $rel_path ) ) {
92
+ if ( $compatible ) {
93
+ echo '<h3>Plugin Conflict Error Detected</h3>';
94
+ $compatible = FALSE;
95
+ }
96
+ echo '<p>This Plugin (' . $jr_mt_plugin_data['Name'] . ') cannot be used when the <b>' . $plugin_data['Name']
97
+ . '</b> plugin is Activated. If you wish to use the ' . $jr_mt_plugin_data['Name']
98
+ . ' plugin, please deactivate the ' . $plugin_data['Name']
99
+ . ' plugin (not just when viewing this Settings page, but whenever the '
100
+ . $jr_mt_plugin_data['Name'] . ' plugin is activated).</p>';
101
+ }
102
+ }
103
+
104
+ if ( $compatible ) {
105
+ $settings = get_option( 'jr_mt_settings' );
106
+ $internal_settings = get_option( 'jr_mt_internal_settings' );
107
+ ?>
108
+ <h2 class="nav-tab-wrapper">
109
+ <a href="#" class="nav-tab nav-tab-active" id="jr-mt-tabs1"
110
+ onClick="jrMtTabs( 1, 5 );">Settings</a><a href="#" class="nav-tab" id="jr-mt-tabs2"
111
+ onClick="jrMtTabs( 2, 5 );">Advanced Settings</a><a href="#" class="nav-tab" id="jr-mt-tabs3"
112
+ onClick="jrMtTabs( 3, 5 );">Theme Options</a><a href="#" class="nav-tab" id="jr-mt-tabs4"
113
+ onClick="jrMtTabs( 4, 5 );">System Information</a><a href="#" class="nav-tab" id="jr-mt-tabs5"
114
+ onClick="jrMtTabs( 5, 5 );">New in V5</a>
115
+ </h2>
116
+ <div id="jr-mt-settings1">
117
+ <h3>Settings</h3>
118
+ <p>
119
+ This is the main Settings tab.
120
+ Additional Settings are available on the
121
+ <a href="#" onClick="jrMtTabs( 2, 5 );">Advanced Settings tab</a>,
122
+ but they can cause problems,
123
+ so should be used with care.
124
+ </p>
125
+ <h3>Overview</h3>
126
+ <p>This Plugin allows you to selectively display Themes on your web site
127
+ other than the Theme shown as
128
+ <b>
129
+ Active
130
+ </b>
131
+ on
132
+ <b>
133
+ Appearance-Themes
134
+ </b>
135
+ in the WordPress Admin panels.
136
+ </p>
137
+ <p>
138
+ Below,
139
+ Theme Selection entries can be created
140
+ where each Entry specifies which of the installed themes shown on the Appearance-Themes Admin panel will be applied to:
141
+ <ul>
142
+ <li> &raquo; The Site Home</li>
143
+ <li> &raquo; An exact URL of any non-Admin page on this WordPress Site</li>
144
+ <li> &raquo; One or more URLs that begin with the partial URL you specify ("URL Prefix")</li>
145
+ <li> &raquo; One or more URLs that begin with the wildcard URL you specify ("URL Prefix*")</li>
146
+ <li> &raquo; Any URL containing a Specific Query Keyword (<code>?keyword</code> or <code>&keyword</code>)</li>
147
+ <li> &raquo; Any URL containing a Specific Query Keyword/Value pair (<code>?keyword=value</code> or <code>&keyword=value</code>)</li>
148
+ <li> &raquo; 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>
149
+ <li> &raquo; All Pages (Advanced Settings tab)</li>
150
+ <li> &raquo; All Posts (Advanced Settings tab)</li>
151
+ <li> &raquo; Everything else, except what is specified above (Advanced Settings tab)</li>
152
+ </ul>
153
+ </p>
154
+ <h3>Important Notes</h3>
155
+ <form action="options.php" method="POST">
156
+ <?php
157
+ $permalink = get_option( 'permalink_structure' );
158
+ if ( isset( $internal_settings['permalink'] ) ) {
159
+ if ( $internal_settings['permalink'] !== $permalink ) {
160
+ /* Permalink Structure has been changed.
161
+ */
162
+ if ( empty( $settings['url'] ) && empty( $settings['url_prefix'] ) && empty( $settings['url_asterisk'] ) ) {
163
+ $update = TRUE;
164
+ } else {
165
+ ?>
166
+ <p>
167
+ Permalink Structure has been changed.
168
+ In the
169
+ <b>
170
+ Current Theme Selection Entries
171
+ </b>
172
+ Section just below,
173
+ please review all
174
+ URL=,
175
+ URL Prefix=
176
+ and
177
+ URL Prefix*=
178
+ entries,
179
+ as they may need to be changed to reflect the new Permalink Structure.
180
+ <br />
181
+ <input type="checkbox" id="permalink" name="jr_mt_settings[permalink]" value="true" />
182
+ Dismiss Warning
183
+ </p>
184
+ <?php
185
+ $update = FALSE;
186
+ }
187
+ } else {
188
+ $update = FALSE;
189
+ }
190
+ } else {
191
+ /* Permalink Internal Setting for Plugin not set,
192
+ so initialize it to current Permalink Structure.
193
+ */
194
+ $update = TRUE;
195
+ }
196
+ if ( $update ) {
197
+ $internal_settings['permalink'] = $permalink;
198
+ update_option( 'jr_mt_internal_settings', $internal_settings );
199
+ }
200
+ if ( function_exists('is_multisite') && is_multisite() ) {
201
+ 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.";
202
+ }
203
+ echo '<p>';
204
+ echo "The Active Theme, defined to WordPress in the Appearance-Themes admin panel, is <b>$theme</b>.";
205
+ if ( trim( $settings['current'] ) ) {
206
+ 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>";
207
+ echo wp_get_theme( $settings['current'] )->Name;
208
+ 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.';
209
+ } else {
210
+ 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.';
211
+ }
212
+ echo '</p>';
213
+
214
+ if ( jr_mt_plugin_update_available() ) {
215
+ echo '<p>A new version of this Plugin (' . $jr_mt_plugin_data['Name'] . ') is available from the WordPress Repository.'
216
+ . ' Updating as quickly as possible is strongly recommend because new versions fix problems that users like you have already reported.'
217
+ . ' <a class="thickbox" title="' . $jr_mt_plugin_data['Name'] . '" href="' . network_admin_url()
218
+ . 'plugin-install.php?tab=plugin-information&plugin=' . $jr_mt_plugin_data['slug']
219
+ . '&section=changelog&TB_iframe=true&width=640&height=768">Click here</a> for more details.</p>';
220
+ }
221
+ ?>
222
+ <p>
223
+ If a newly-added Theme Selection does not seem to be working,
224
+ especially if the associated web page does not display properly,
225
+ try deactivating any plugins that provide Caching.
226
+ You may find that you have to flush the plugin's Cache whenever you add or change a Theme Selection setting.
227
+ Also note that some Caching plugins only cache for visitors who are not logged in,
228
+ so be sure to check your site after logging out.
229
+ </p>
230
+ <p>
231
+ Need more help?
232
+ Please scroll to the bottom of this Settings page for more information.
233
+ </p>
234
+ <hr />
235
+ <?php
236
+
237
+ // Plugin Settings are displayed and entered here:
238
+ settings_fields( 'jr_mt_settings' );
239
+ do_settings_sections( 'jr_mt_settings_page' );
240
+ echo '<p><input name="save" type="submit" value="Save All Changes" class="button-primary" /></p></form>';
241
+ }
242
+
243
+ ?>
244
+ </div>
245
+ <div id="jr-mt-settings3" style="display: none;">
246
+ <h3>
247
+ Theme Options and Template Selection
248
+ </h3>
249
+ <p>
250
+ This tab provides information on changing Theme Options
251
+ (Widgets, Sidebars, Menus, Background, Header, etc.)
252
+ for all the different Themes used on a WordPress site.
253
+ </p>
254
+ <p>
255
+ Information on changing the Template for each Page or Post
256
+ is found near the bottom of this tab.
257
+ </p>
258
+ <h3>
259
+ Changing Theme Options
260
+ </h3>
261
+ <p>
262
+ For the Active Theme, nothing changes when using the jonradio Multiple Themes plugin.
263
+ Options for the Active Theme,
264
+ including Widgets, Sidebars, Menus, Background, Header and other Customizations supported by the Theme,
265
+ can be modified in the Admin panel using the Appearance menu items on the left sidebar.
266
+ Some Themes also provide their own menu items in the left sidebar of the Admin panel,
267
+ and these will still appear for the Active Theme when using this plugin.
268
+ </p>
269
+ <p>
270
+ It is more difficult to modify Options for installed Themes that are not the WordPress Active Theme.
271
+ Building this functionality into this plugin is in the plans for a future Version,
272
+ but it is not clear just how practical that is, so the best that can be said is:
273
+ <i>
274
+ Maybe</i>.
275
+ </p>
276
+ <p>
277
+ For now, there are three approaches that can be used to change Options for an installed Theme that is not the Active Theme.
278
+ The first works best if only one Theme has a lot of Options that need to be changed frequently:
279
+ </p>
280
+ <ol>
281
+ <li>
282
+ Make that Theme the Active Theme defined in the Appearance-Themes WordPress admin panel;
283
+ </li>
284
+ <li>
285
+ If that meant changing the Active Theme,
286
+ the previous Active Theme can be selected on the plugin's
287
+ <b>
288
+ Advanced Settings
289
+ </b>
290
+ tab
291
+ in the
292
+ <b>
293
+ Select Theme for Everything
294
+ </b>
295
+ field
296
+ and it will be used everywhere except where you have specified
297
+ another Theme in the Theme Selection entries for this plugin.
298
+ </li>
299
+ </ol>
300
+ <p>
301
+ For other situations,
302
+ two multi-step Methods are available,
303
+ and are described in the two Sections below.
304
+ Both Methods work for most Theme Options,
305
+ with the following exceptions:
306
+ </p>
307
+ <ol>
308
+ <li>
309
+ Menus really work well with Method #1,
310
+ but are severely restricted with Method #2;
311
+ </li>
312
+ <li>
313
+ Widgets normally only work with Method #2;
314
+ </li>
315
+ <li>
316
+ Using both Methods may cause conflicts;
317
+ </li>
318
+ <li>
319
+ No matter which Method you choose,
320
+ you may lose previously-set Theme Options.
321
+ A Backup and Recovery of your WordPress Database
322
+ would be required to avoid such a loss.
323
+ </li>
324
+ </ol>
325
+ <h4>
326
+ <u>
327
+ Method #1</u>:
328
+ Set the Theme Options with Live Preview.
329
+ </h4>
330
+ <p>
331
+ Note: Widgets cannot be placed using this Method.
332
+ </p>
333
+ <ol>
334
+ <li>
335
+ Go to Appearance-Themes in the WordPress Admin panels.
336
+ </li>
337
+ <li>
338
+ Mouse over the Theme that you wish to change
339
+ and click the Live Preview button that appears.
340
+ </li>
341
+ <li>
342
+ Use the left sidebar to modify the Theme Options.
343
+ Note that
344
+ <b>
345
+ Navigation
346
+ </b>
347
+ will not appear in the Live Preview sidebar until a Menu has been defined in Appearance-Menus.
348
+ Navigation is where you would set the custom menu(s) to be used for the Theme you are currently previewing.
349
+ </li>
350
+ <li>
351
+ Click the Save & Activate button.
352
+ </li>
353
+ <li>
354
+ Go immediately to Appearance-Themes in the WordPress Admin panels.
355
+ </li>
356
+ <li>
357
+ Mouse over the Theme that had previously been the Active Theme
358
+ and click the Activate button that appears
359
+ to reactivate the Active Theme.
360
+ </li>
361
+ </ol>
362
+ <h4>
363
+ <u>
364
+ Method #2</u>:
365
+ Use the Theme Test Drive plugin.
366
+ </h4>
367
+ <p>
368
+ 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.
369
+ </p>
370
+ <p>
371
+ The jonradio Multiple Themes plugin (i.e. - this plugin) must be Deactivated,
372
+ and the Theme Test Drive plugin installed and activated.
373
+ This enables each Theme to be selected with the Theme Test Drive plugin,
374
+ allowing the Theme's Options to be set
375
+ <i>
376
+ as if
377
+ </i>
378
+ it were the Active Theme.
379
+ </p>
380
+ <ol>
381
+ <li>
382
+ Deactivate the jonradio Multiple Themes plugin.
383
+ </li>
384
+ <li>
385
+ Install the Theme Test Drive plugin found at
386
+ <a target="_blank" href="http://wordpress.org/plugins/theme-test-drive/">http://wordpress.org/plugins/theme-test-drive/</a>.
387
+ </li>
388
+ <li>
389
+ Activate the Theme Test Drive plugin.
390
+ </li>
391
+ <li>
392
+ Go to
393
+ <b>
394
+ Appearance-Theme Test Drive
395
+ </b>
396
+ in the WordPress Admin panels.
397
+ </li>
398
+ <li>
399
+ In the Usage section, select a Theme whose Options you wish to change.
400
+ </li>
401
+ <li>
402
+ Push the Enable Theme Drive button at the bottom of the Admin panel.
403
+ </li>
404
+ <li>
405
+ 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
406
+ using the Appearance submenu
407
+ in the WordPress Admin panels,
408
+ just as you would for the Active Theme.
409
+ </li>
410
+ <li>
411
+ If more than one Theme has Options that need changing, repeat Steps 4-8 for each Theme
412
+ (except the Active Theme,
413
+ which should be only changed
414
+ <i>
415
+ without
416
+ </i>
417
+ the Theme Test Drive plugin activated).
418
+ </li>
419
+ <li>
420
+ Deactivate the Theme Test Drive plugin.
421
+ </li>
422
+ <li>
423
+ Activate this plugin (jonradio Multiple Themes).
424
+ </li>
425
+ <li>
426
+ Changes to the Options for the Active Theme can now be made normally, just as you would without either plugin.
427
+ </li>
428
+ <li>
429
+ Both the alternate and Active Themes should now display all Theme options properly when selected through the jonradio Multiple Themes plugin.
430
+ </li>
431
+ </ol>
432
+ <h3>
433
+ Changing Templates
434
+ </h3>
435
+ <p>
436
+ Many Themes provide more than one Template.
437
+ For each Page or Post, you can select the Template you want to use for that Page or Post.
438
+ </p>
439
+ <p>
440
+ For the Active Theme, nothing changes when using the jonradio Multiple Themes plugin.
441
+ 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.
442
+ Or the Template field in Quick Edit.
443
+ </p>
444
+ <p>
445
+ 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.
446
+ Building this functionality into this plugin is in the plans for a future Version.
447
+ </p>
448
+ <p>
449
+ Use the Theme Test Drive plugin.
450
+ The jonradio Multiple Themes plugin (i.e. - this plugin) must be Deactivated, and the Theme Test Drive plugin installed and activated,
451
+ so that each Theme can be selected with the Theme Test Drive plugin,
452
+ allowing the Theme's Template to be set for each Page or Post using that Theme
453
+ <i>
454
+ as if
455
+ </i>
456
+ it were the Active Theme.
457
+ </p>
458
+ <ol>
459
+ <li>
460
+ Deactivate the jonradio Multiple Themes plugin.
461
+ </li>
462
+ <li>
463
+ Install the Theme Test Drive plugin found at
464
+ <a target="_blank" href="http://wordpress.org/plugins/theme-test-drive/">http://wordpress.org/plugins/theme-test-drive/</a>.
465
+ </li>
466
+ <li>
467
+ Activate the Theme Test Drive plugin.
468
+ </li>
469
+ <li>
470
+ Go to
471
+ <b>
472
+ Appearance-Theme Test Drive
473
+ </b>
474
+ in the WordPress Admin panels.
475
+ </li>
476
+ <li>
477
+ In the Usage section, select a Theme whose Templates need to be changed for a Post or Page.
478
+ </li>
479
+ <li>
480
+ Push the Enable Theme Drive button at the bottom of the Admin panel.
481
+ </li>
482
+ <li>
483
+ Go to Posts-All Posts or Pages-All Pages in the WordPress Admin panels.
484
+ </li>
485
+ <li>
486
+ For each Page or Post where a Template needs to be changed for this Theme,
487
+ mouse over the Page or Post title and click on Quick Edit.
488
+ </li>
489
+ <li>
490
+ Change the Template field.
491
+ </li>
492
+ <li>
493
+ Click the Update button.
494
+ </li>
495
+ <li>
496
+ Repeat Steps 8-10 for each Page or Post that requires a change to Template for this Theme.
497
+ </li>
498
+ <li>
499
+ If more than one Theme has Pages or Posts with Templates that need to be changed,
500
+ repeat Steps 4-11 for each Theme
501
+ (except the Active Theme,
502
+ where Template changes should only be made
503
+ <i>
504
+ without
505
+ </i>
506
+ the Theme Test Drive plugin activated).
507
+ </li>
508
+ <li>
509
+ Deactivate the Theme Test Drive plugin.
510
+ </li>
511
+ <li>
512
+ Activate this plugin (jonradio Multiple Themes).
513
+ </li>
514
+ <li>
515
+ Changing Templates for the Active Theme can now be made normally, just as you would without either plugin.
516
+ </li>
517
+ <li>
518
+ Both the alternate and Active Themes should now display the correct Template when selected through the jonradio Multiple Themes plugin.
519
+ </li>
520
+ </ol>
521
+ </div>
522
+ <div id="jr-mt-settings4" style="display: none;">
523
+ <h3>
524
+ System Information
525
+ </h3>
526
+ <?php
527
+ $posix = function_exists( 'posix_uname' );
528
+ echo '<p>You are currently running:<ul>';
529
+ echo "<li> &raquo; The {$jr_mt_plugin_data['Name']} plugin Version {$jr_mt_plugin_data['Version']}</li>";
530
+ echo "<li> &nbsp; &raquo;&raquo; The Path to the plugin's directory is <code>" . rtrim( jr_mt_path(), '/' ) . '</code></li>';
531
+ echo "<li> &nbsp; &raquo;&raquo; The URL to the plugin's directory is <code>" . plugins_url() . "/{$jr_mt_plugin_data['slug']}</code></li>";
532
+ echo "<li> &raquo; The Active Theme is $theme Version $theme_version</li>";
533
+ echo "<li> &nbsp; &raquo;&raquo; The Path to the Active Theme's stylesheet directory is <code>" . get_stylesheet_directory() . '</code></li>';
534
+ echo "<li> &nbsp; &raquo;&raquo; The Path to the Active Theme's template directory is <code>" . get_template_directory() . '</code></li>';
535
+ $permalink = get_option( 'permalink_structure' );
536
+ if ( empty( $permalink ) ) {
537
+ $permalink = 'Default (Query <code>/?p=123</code>)';
538
+ } else {
539
+ $permalink = "<code>$permalink</code>";
540
+ }
541
+ echo "<li> &raquo; The current Permalink Structure is $permalink";
542
+ echo "<li> &raquo; WordPress Version $current_wp_version</li>";
543
+ echo '<li> &nbsp; &raquo;&raquo; WordPress language is set to ' , get_bloginfo( 'language' ) . '</li>';
544
+ echo '<li> &raquo; ' . php_uname( 's' ) . ' operating system, Release/Version ' . php_uname( 'r' ) . ' / ' . php_uname( 'v' ) . '</li>';
545
+ if ( $posix ) {
546
+ $array = posix_getpwuid( posix_getuid() );
547
+ $user = $array['name'];
548
+ echo "<li> &raquo; Real operating system User ID that runs WordPress is $user</li>";
549
+ $array = posix_getpwuid( posix_geteuid() );
550
+ $user = $array['name'];
551
+ echo "<li> &raquo; Effective operating system User ID that runs WordPress is $user</li>";
552
+ }
553
+ echo '<li> &raquo; ' . php_uname( 'm' ) . ' computer hardware</li>';
554
+ echo '<li> &raquo; Host name ' . php_uname( 'n' ) . '</li>';
555
+ echo '<li> &raquo; php Version ' . phpversion() . '</li>';
556
+ echo '<li> &nbsp; &raquo;&raquo; php memory_limit ' . ini_get('memory_limit') . '</li>';
557
+ if ( !$posix ) {
558
+ echo '<li> &nbsp; &raquo;&raquo; POSIX functions are not available</li>';
559
+ }
560
+ echo '<li> &raquo; Zend engine Version ' . zend_version() . '</li>';
561
+ echo '<li> &raquo; Web Server software is ' . getenv( 'SERVER_SOFTWARE' ) . '</li>';
562
+ if ( function_exists( 'apache_get_version' ) && ( FALSE !== $apache = apache_get_version() ) ) {
563
+ echo "<li> &nbsp; &raquo;&raquo; Apache Version $apache</li>";
564
+ }
565
+ global $wpdb;
566
+ echo '<li> &raquo; MySQL Version ' . $wpdb->get_var( 'SELECT VERSION();', 0, 0 ) . '</li>';
567
+
568
+ echo '</ul></p>';
569
+
570
+ $paths = array(
571
+ '/..',
572
+ '/',
573
+ '/wp-content/',
574
+ '/wp-content/plugins/',
575
+ '/wp-content/plugins/' . dirname( jr_mt_plugin_basename() ),
576
+ '/wp-content/plugins/' . dirname( jr_mt_plugin_basename() ) . '/readme.txt'
577
+ );
578
+ echo '<h3>File Permissions</h3><p>All of the Paths shown below are relative to the WordPress Site Path <code>'
579
+ . ABSPATH
580
+ . '</code><br />The first is the Parent Directory <code>'
581
+ . dirname( ABSPATH )
582
+ . '/</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>';
583
+ if ( $posix ) {
584
+ echo '<th>Owner</th><th>Group</th>';
585
+ }
586
+ echo '</tr></thead><tbody>';
587
+ foreach ( $paths as $path ) {
588
+ $full_path = ABSPATH . substr( $path, 1 );
589
+ if ( is_dir( $full_path ) ) {
590
+ $type = 'Directory';
591
+ } else {
592
+ $type = 'File';
593
+ }
594
+ if ( is_readable( $full_path ) ) {
595
+ $read = 'Yes';
596
+ } else {
597
+ $read = 'No';
598
+ }
599
+ if ( is_writeable( $full_path ) ) {
600
+ $write = 'Yes';
601
+ } else {
602
+ $write = 'No';
603
+ }
604
+ if ( $posix ) {
605
+ if ( FALSE === ( $uid = fileowner( $full_path ) ) ) {
606
+ $user = '-';
607
+ $group = '-';
608
+ } else {
609
+ $array = posix_getpwuid( $uid );
610
+ $user = $array['name'];
611
+ $array = posix_getgrgid( filegroup( $full_path ) );
612
+ $group = $array['name'];
613
+ }
614
+ }
615
+ echo "<tr><td>$path</td><td>$type</td><td>$read</td><td>$write</td>";
616
+ if ( $posix ) {
617
+ echo "<td>$user</td><td>$group</td>";
618
+ }
619
+ echo '<tr>';
620
+ }
621
+ echo '</tbody></table>';
622
+ ?>
623
+ </div>
624
+ <div id="jr-mt-settings5" style="display: none;">
625
+ <p>
626
+ It is possible to downgrade from Version 5 to Version 4.12.
627
+ <a href="http://downloads.wordpress.org/plugin/jonradio-multiple-themes.4.12.zip">Click here</a>
628
+ to download Version 4.12.
629
+ </p>
630
+ <h3>
631
+ What's New in Version 5?
632
+ </h3>
633
+ <p>
634
+ Version 5.0 of the jonradio Multiple Themes plugin
635
+ saw a major rewrite of the Theme Selection logic,
636
+ the first since the plugin was originally written,
637
+ and the addition of Tabs to the Settings page,
638
+ for easier navigation.
639
+ </p>
640
+ <p>
641
+ Major improvements include:
642
+ </p>
643
+ <ol>
644
+ <li>
645
+ Greatly expanded compatibility with other Plugins and Themes;
646
+ </li>
647
+ <li>
648
+ Allow <code>?keyword=value&keyword=value</code> Queries
649
+ in URL, URL Prefix and URL Prefix with Asterisk ("*")
650
+ Theme Selection entries;
651
+ </li>
652
+ <li>
653
+ Accurate Theme Selection even for plugins and themes that request
654
+ Stylesheet or Template information before WordPress is fully loaded;
655
+ </li>
656
+ <li>
657
+ Tabs for the Setting page written in JavaScript
658
+ for instant switching between tabs
659
+ and preservation of input data,
660
+ e.g. - switch between Settings and Advanced Settings tabs
661
+ without having to retype your changes when you switch back;
662
+ </li>
663
+ <li>
664
+ Plugin's Theme Selection entries, if any,
665
+ displayed in the order in which they are processed,
666
+ to clarify which Theme will be displayed for any given URL;
667
+ </li>
668
+ <li>
669
+ Complete How-To details on
670
+ Theme Option and Template selection
671
+ right on the Settings page,
672
+ replacing the FAQs
673
+ in the WordPress Plugin Directory;
674
+ </li>
675
+ <li>
676
+ Automatic deletion of Theme Selection entries
677
+ for Themes that have been deleted;
678
+ </li>
679
+ <li>
680
+ Enhanced performance with tighter code,
681
+ and less of it,
682
+ on the public side of your WordPress site.
683
+ </li>
684
+ </ol>
685
+ <p>
686
+ The only disadvantages of the new Theme Selection methods used in Version 5 are:
687
+ </p>
688
+ <ol>
689
+ <li>
690
+ Changing Permalinks invalidates more Theme Selection settings than in previous versions;
691
+ </li>
692
+ <li>
693
+ Changing the Theme for an Entry
694
+ requires Deletion of the old Entry
695
+ before or after
696
+ adding the same Entry
697
+ with the new Theme specified;
698
+ </li>
699
+ <li>
700
+ The new Theme Selection logic,
701
+ based on URL Matching rather than Page, Post, Attachment, Category and Archive IDs,
702
+ requires a conversion of some Settings from prior versions of the plugin.
703
+ This conversion to the new format occurs automatically
704
+ the first time that Version 5 runs.
705
+ Old format settings are retained,
706
+ transparently without being displayed on the Settings page,
707
+ to allow downgrading to Version 4 from Version 5.
708
+ </li>
709
+ </ol>
710
+ </div>
711
+ <hr />
712
+ <h3>
713
+ Need Help?
714
+ </h3>
715
+ <p>
716
+ Need help with this plugin?
717
+ Check the
718
+ <a href="#" onClick="jrMtTabs( 3, 5 );">Theme Options</a>
719
+ and
720
+ <a href="#" onClick="jrMtTabs( 5, 5 );">New in V5</a>
721
+ tabs above,
722
+ and the
723
+ <a target="_blank" href="http://wordpress.org/plugins/jonradio-multiple-themes/">Description</a>,
724
+ <a target="_blank" href="http://wordpress.org/plugins/jonradio-multiple-themes/faq/">FAQ</a>,
725
+ <a target="_blank" href="http://wordpress.org/plugins/jonradio-multiple-themes/installation/">Installation</a>
726
+ and
727
+ <a target="_blank" href="http://wordpress.org/support/plugin/jonradio-multiple-themes">Support</a>
728
+ tabs
729
+ in the <a target="_blank" href="http://wordpress.org/plugins/jonradio-multiple-themes/">WordPress Directory entry for this plugin</a>.
730
+ 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.
731
+ </p>
732
+ <p>
733
+ Please be sure to check them all out if you have any unanswered questions.
734
+ If you cannot find the answers to all of your questions there,
735
+ simply post your question in the
736
+ <a target="_blank" href="http://wordpress.org/support/plugin/jonradio-multiple-themes">Support Forum</a>
737
+ or
738
+ <a target="_blank" href="http://zatzlabs.com/contact-us/">contact jonradio directly</a>
739
+ (be sure to mention which plugin your question pertains to).
740
+ </p>
741
+ <p>
742
+ For information on other jonradio plugins,
743
+ including Contact and Donation information,
744
+ <a target="_blank" href="http://zatzlabs.com/plugins/">click here</a>.
745
+ </p>
746
+ <h3>
747
+ Want to Help?
748
+ </h3>
749
+ <p>
750
+ As well as <a target="_blank" href="http://zatzlabs.com/plugins/">Donations</a>,
751
+ you can also help by
752
+ <a target="_blank" href="http://wordpress.org/support/view/plugin-reviews/jonradio-multiple-themes">Reviewing this plugin</a>
753
+ for the WordPress Plugin Directory,
754
+ and telling other people that it works for your particular combination of Plugin version and WordPress version
755
+ in the Compability section of the
756
+ <a target="_blank" href="http://wordpress.org/plugins/jonradio-multiple-themes/">WordPress Directory entry for this plugin</a>.
757
+ </p>
758
+ <?php
759
+ }
760
+
761
+ add_action( 'admin_init', 'jr_mt_admin_init' );
762
+
763
+ /**
764
+ * Register and define the settings
765
+ *
766
+ * Everything to be stored and/or can be set by the user
767
+ *
768
+ */
769
+ function jr_mt_admin_init() {
770
+ register_setting( 'jr_mt_settings', 'jr_mt_settings', 'jr_mt_validate_settings' );
771
+ $settings = get_option( 'jr_mt_settings' );
772
+ foreach ( array( 'query', 'url', 'url_prefix', 'url_asterisk' ) as $key ) {
773
+ if ( !empty( $settings[ $key ] ) ) {
774
+ $found = TRUE;
775
+ }
776
+ }
777
+ if ( isset( $found ) ) {
778
+ add_settings_section(
779
+ 'jr_mt_delete_settings_section',
780
+ 'Current Theme Selection Entries',
781
+ 'jr_mt_delete_settings_expl',
782
+ 'jr_mt_settings_page'
783
+ );
784
+ add_settings_field(
785
+ 'del_entry',
786
+ 'Theme Selection Entries:',
787
+ 'jr_mt_echo_delete_entry',
788
+ 'jr_mt_settings_page',
789
+ 'jr_mt_delete_settings_section'
790
+ );
791
+ }
792
+ add_settings_section(
793
+ 'jr_mt_site_home_section',
794
+ 'Site Home',
795
+ 'jr_mt_site_home_expl',
796
+ 'jr_mt_settings_page'
797
+ );
798
+ add_settings_field(
799
+ 'site_home',
800
+ 'Select Theme for Site Home<br /><code>' . home_url() . '</code>',
801
+ 'jr_mt_echo_site_home',
802
+ 'jr_mt_settings_page',
803
+ 'jr_mt_site_home_section'
804
+ );
805
+ add_settings_section(
806
+ 'jr_mt_single_settings_section',
807
+ '<input name="save" type="submit" value="Save All Changes" class="button-primary" /></h3><h3>For An Individual Page, Post or other non-Admin page;<br />or a group of pages, specified by URL Prefix, optionally with Asterisk(s)',
808
+ 'jr_mt_single_settings_expl',
809
+ 'jr_mt_settings_page'
810
+ );
811
+ 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' );
812
+ add_settings_field( 'add_theme', 'Theme', 'jr_mt_echo_add_theme', 'jr_mt_settings_page', 'jr_mt_single_settings_section' );
813
+ 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' );
814
+ add_settings_section( 'jr_mt_querykw_section',
815
+ 'For A Query Keyword on any Page, Post or other non-Admin page',
816
+ 'jr_mt_querykw_expl',
817
+ 'jr_mt_settings_page'
818
+ );
819
+ add_settings_field( 'add_querykw_theme', 'Theme', 'jr_mt_echo_add_querykw_theme', 'jr_mt_settings_page', 'jr_mt_querykw_section' );
820
+ add_settings_field( 'add_querykw_keyword', 'Query Keyword', 'jr_mt_echo_add_querykw_keyword', 'jr_mt_settings_page', 'jr_mt_querykw_section' );
821
+ add_settings_section( 'jr_mt_query_section',
822
+ 'For A Query Keyword=Value on any Page, Post or other non-Admin page',
823
+ 'jr_mt_query_expl',
824
+ 'jr_mt_settings_page'
825
+ );
826
+ add_settings_field( 'add_query_theme', 'Theme', 'jr_mt_echo_add_query_theme', 'jr_mt_settings_page', 'jr_mt_query_section' );
827
+ add_settings_field( 'add_query_keyword', 'Query Keyword', 'jr_mt_echo_add_query_keyword', 'jr_mt_settings_page', 'jr_mt_query_section' );
828
+ add_settings_field( 'add_query_value', 'Query Value', 'jr_mt_echo_add_query_value', 'jr_mt_settings_page', 'jr_mt_query_section' );
829
+ add_settings_section( 'jr_mt_sticky_section',
830
+ '<input name="save" type="submit" value="Save All Changes" class="button-primary" /></h3></div><div id="jr-mt-settings2" 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',
831
+ 'jr_mt_sticky_expl',
832
+ 'jr_mt_settings_page'
833
+ );
834
+ 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' );
835
+ add_settings_field( 'sticky_query', 'Keyword=Value Entries:', 'jr_mt_echo_sticky_query_entry', 'jr_mt_settings_page', 'jr_mt_sticky_section' );
836
+ add_settings_section( 'jr_mt_everything_section',
837
+ 'Theme for Everything',
838
+ 'jr_mt_everything_expl',
839
+ 'jr_mt_settings_page'
840
+ );
841
+ add_settings_field( 'current',
842
+ 'Select Theme for Everything, to Override WordPress Current Theme (<b>' . wp_get_theme()->Name . '</b>)',
843
+ 'jr_mt_echo_current',
844
+ 'jr_mt_settings_page',
845
+ 'jr_mt_everything_section'
846
+ );
847
+ add_settings_section( 'jr_mt_all_settings_section',
848
+ 'For All Pages and/or All Posts',
849
+ 'jr_mt_all_settings_expl',
850
+ 'jr_mt_settings_page'
851
+ );
852
+ $suffix = array(
853
+ 'Pages' => '<br />(Pages created with Add Page)',
854
+ 'Posts' => ''
855
+ );
856
+ foreach ( array( 'Pages', 'Posts' ) as $thing ) {
857
+ add_settings_field( 'all_' . strtolower( $thing ), "Select Theme for All $thing" . $suffix[$thing], 'jr_mt_echo_all_things', 'jr_mt_settings_page', 'jr_mt_all_settings_section',
858
+ array( 'thing' => $thing ) );
859
+ }
860
+ }
861
+
862
+ /**
863
+ * Section text for Section1
864
+ *
865
+ * Display an explanation of this Section
866
+ *
867
+ */
868
+ function jr_mt_delete_settings_expl() {
869
+ ?>
870
+ <p>
871
+ All Theme Selection entries are displayed below,
872
+ in the exact order in which they will be processed.
873
+ For example,
874
+ if a match is made with the first Entry,
875
+ the first Entry's Theme will be used,
876
+ no matter what Theme the Second and subsequent Entries specify.
877
+ </p>
878
+ <p>
879
+ You can delete any of these entries by filling in the check box beside the entry
880
+ and clicking any of the <b>Save All Changes</b> buttons.
881
+ To change the Theme for an entry,
882
+ you will need to delete the entry
883
+ and add the same entry with a different Theme in the relevant section
884
+ on this or the Advanced Settings tab.
885
+ </p>
886
+ <p>
887
+ To add or remove (or to learn about) the Sticky or Override setting for a Query,
888
+ see the Advanced Settings tab.
889
+ </p>
890
+ <?php
891
+ }
892
+
893
+ function jr_mt_echo_delete_entry() {
894
+ echo 'In order of Selection:<ol>';
895
+ $settings = get_option( 'jr_mt_settings' );
896
+ /* Display any Override entries first,
897
+ because they have the highest priority.
898
+ */
899
+ foreach ( $settings['override']['query'] as $override_keyword => $override_value_array ) {
900
+ foreach ( $override_value_array as $override_value => $bool ) {
901
+ jr_mt_theme_entry(
902
+ 'Query',
903
+ wp_get_theme( $settings['query'][ $override_keyword ][ $override_value ] )->Name,
904
+ $override_keyword,
905
+ $override_value
906
+ );
907
+ }
908
+ }
909
+ /* Display Non-Overrides:
910
+ first, keyword=value query in URL with matching setting entry.
911
+ */
912
+ foreach ( $settings['query'] as $keyword => $value_array ) {
913
+ foreach ( $value_array as $value => $theme ) {
914
+ /* Wildcard Keyword=* entries come later
915
+ */
916
+ if ( '*' !== $value ) {
917
+ if ( !isset( $settings['override']['query'][ $keyword ][ $value ] ) ) {
918
+ jr_mt_theme_entry(
919
+ 'Query',
920
+ wp_get_theme( $theme )->Name,
921
+ $keyword,
922
+ $value
923
+ );
924
+ }
925
+ }
926
+ }
927
+ }
928
+ /* Display Non-Overrides:
929
+ second, wildcard keyword=* query in URL with matching setting entry.
930
+ */
931
+ foreach ( $settings['query'] as $keyword => $value_array ) {
932
+ foreach ( $value_array as $value => $theme ) {
933
+ /* Wildcard Keyword=* entries
934
+ Overrides are not allowed, so no need to check.
935
+ */
936
+ if ( '*' === $value ) {
937
+ jr_mt_theme_entry(
938
+ 'Query',
939
+ wp_get_theme( $theme )->Name,
940
+ $keyword,
941
+ '*'
942
+ );
943
+ }
944
+ }
945
+ }
946
+ /* Display URL entries:
947
+ first, exact match URL entries;
948
+ second, prefix URL entries;
949
+ then, prefix URL entries with asterisk wildcards.
950
+ */
951
+ foreach ( array(
952
+ 'url' => 'URL',
953
+ 'url_prefix' => 'URL Prefix',
954
+ 'url_asterisk' => 'URL Prefix*'
955
+ ) as $key => $description ) {
956
+ foreach ( $settings[ $key ] as $settings_array ) {
957
+ jr_mt_theme_entry(
958
+ $key,
959
+ wp_get_theme( $settings_array['theme'] )->Name,
960
+ $settings_array['url'],
961
+ $description
962
+ );
963
+ }
964
+ }
965
+ /* Home Entry, then All Posts and Pages, and Everything Else
966
+ */
967
+ foreach ( array(
968
+ 'site_home' => 'Home',
969
+ 'all_posts' => 'All Posts',
970
+ 'all_pages' => 'All Pages',
971
+ 'current' => 'Everything Else'
972
+ ) as $key => $description ) {
973
+ if ( '' !== $settings[ $key ] ) {
974
+ jr_mt_theme_entry(
975
+ $key,
976
+ wp_get_theme( $settings[ $key ] )->Name,
977
+ $description
978
+ );
979
+ }
980
+ }
981
+ if ( '' === $settings['current'] ) {
982
+ jr_mt_theme_entry(
983
+ 'wordpress'
984
+ );
985
+ }
986
+ echo '</ol>';
987
+ }
988
+
989
+ /**
990
+ * Section text for Section2
991
+ *
992
+ * Display an explanation of this Section
993
+ *
994
+ */
995
+ function jr_mt_site_home_expl() {
996
+ ?>
997
+ <p>
998
+ In this section, you can select a different Theme for Site Home.
999
+ To remove a previously selected Theme, select the blank entry from the drop-down list.
1000
+ </p>
1001
+ <p>
1002
+ In the <i>next</i> section, you will be able to select a Theme, including the Current Theme, for individual Pages, Posts or
1003
+ any other non-Admin pages that have their own Permalink; for example, specific Archive or Category pages.
1004
+ Or groups of Pages, Posts or any other non-Admin pages that share the same URL Prefix.
1005
+ </p>
1006
+ <p>
1007
+ There is also a Query Keyword section
1008
+ farther down this Settings page
1009
+ that allows
1010
+ you to select a Theme to use whenever a specified
1011
+ Query Keyword (<code>?keyword=value</code> or <code>&keyword=value</code>)
1012
+ appears in the URL of any Page, Post or other non-Admin page.
1013
+ Query entries will even override the Site Home entry,
1014
+ if the Query Keyword follows the Site Home URL.
1015
+ </p>
1016
+ <?php
1017
+ }
1018
+
1019
+ function jr_mt_echo_site_home() {
1020
+ $settings = get_option( 'jr_mt_settings' );
1021
+ jr_mt_themes_field( 'site_home', $settings['site_home'], 'jr_mt_settings', FALSE );
1022
+ }
1023
+
1024
+ /**
1025
+ * Section text for Section3
1026
+ *
1027
+ * Display an explanation of this Section
1028
+ *
1029
+ */
1030
+ function jr_mt_single_settings_expl() {
1031
+ ?>
1032
+ <p>
1033
+ Select a Theme for an individual Page, Post or
1034
+ any other non-Admin page that has its own Permalink; for example, a specific Archive or Category page.
1035
+ Or for a group of pages which have URLs that all begin with the same characters ("Prefix"),
1036
+ optionally specifying an Asterisk ("*") to match all subdirectories at specific levels.
1037
+ </p>
1038
+ <p>
1039
+ Then cut and paste the URL of the desired Page, Post, Prefix or other non-Admin page.
1040
+ And click any of the <b>Save All Changes</b> buttons to add the entry.
1041
+ </p>
1042
+ There are three types of Entries that you can specify here:
1043
+ <ol>
1044
+ <li>
1045
+ <b>URL</b> - if Visitor URL matches this URL, use this Theme
1046
+ </li>
1047
+ <li>
1048
+ <b>URL Prefix</b> - any Visitor URL that begins with this URL Prefix will use this Theme
1049
+ </li>
1050
+ <li>
1051
+ <b>URL Prefix with Asterisk(s)</b> - URL Prefix that matches any subdirectory where Asterisk ("*") is specified
1052
+ </li>
1053
+ </ol>
1054
+ For the third type, an Asterisk can only be specified to match the entire subdirectory name, not parts of the name:
1055
+ <blockquote>
1056
+ For example, using a Permalink structure that uses dates,
1057
+ where a typical Post might be at URL
1058
+ <code>http://example.com/wp/2014/04/13/daily-thoughts/</code>,
1059
+ a URL Prefix with Asterisk entry of
1060
+ <code>http://example.com/wp/*/04/*/d</code>
1061
+ would match all April Posts with Titles that begin with the letter "d", no matter what year they were posted.
1062
+ </blockquote>
1063
+ </p>
1064
+ <?php
1065
+ }
1066
+
1067
+ function jr_mt_echo_add_is_prefix() {
1068
+ echo '<input type="radio" id="add_is_prefix" name="jr_mt_settings[add_is_prefix]" value="false" checked="checked" /> URL';
1069
+ ?>
1070
+ <br/>
1071
+ <input type="radio" id="add_is_prefix" name="jr_mt_settings[add_is_prefix]" value="prefix" /> URL Prefix<br/>
1072
+ <input type="radio" id="add_is_prefix" name="jr_mt_settings[add_is_prefix]" value="*" /> URL Prefix with Asterisk ("*")
1073
+ <?php
1074
+ }
1075
+
1076
+ function jr_mt_echo_add_theme() {
1077
+ jr_mt_themes_field( 'add_theme', '', 'jr_mt_settings', FALSE );
1078
+ }
1079
+
1080
+ function jr_mt_echo_add_path_id() {
1081
+ ?>
1082
+ <input id="add_path_id" name="jr_mt_settings[add_path_id]" type="text" size="100" maxlength="256" value="" />
1083
+ <br />
1084
+ (cut and paste URL here of Page, Post, Prefix or other)
1085
+ <br />
1086
+ URL must begin with
1087
+ <?php
1088
+ echo '<code>' . home_url() . '/</code>.';
1089
+ echo '<br />Beginning with Version 5.0, <code>keyword=value</code> Queries are now supported in all URLs.';
1090
+ }
1091
+
1092
+ /**
1093
+ * Section text for Section4
1094
+ *
1095
+ * Display an explanation of this Section
1096
+ *
1097
+ */
1098
+ function jr_mt_querykw_expl() {
1099
+ ?>
1100
+ <p>
1101
+ Select a Theme to use
1102
+ whenever the specified Query Keyword (<code>?keyword=</code> or <code>&keyword=</code>)
1103
+ is found in the URL of
1104
+ any Page, Post or
1105
+ any other non-Admin page.
1106
+ And click any of the <b>Save All Changes</b> buttons to add the entry.
1107
+ </p>
1108
+ <p>
1109
+ <b>
1110
+ Note
1111
+ </b>
1112
+ that Query Keyword takes precedence over all other types of Theme selection entries.
1113
+ For example,
1114
+ <?php
1115
+ echo '<code>' . home_url() . '?firstname=dorothy</code>'
1116
+ . ' would use the Theme specified for the <code>firstname</code> keyword, not the Theme specified for Site Home.'
1117
+ . ' Query matching is case-insensitive, so all Keywords entered are stored in lower-case.</p>';
1118
+ }
1119
+ function jr_mt_echo_add_querykw_theme() {
1120
+ jr_mt_themes_field( 'add_querykw_theme', '', 'jr_mt_settings', FALSE );
1121
+ }
1122
+ function jr_mt_echo_add_querykw_keyword() {
1123
+ $three_dots = '&#133;';
1124
+ echo '<code>'
1125
+ . home_url()
1126
+ . "/</code>$three_dots<code>/?"
1127
+ . '<input id="add_querykw_keyword" name="jr_mt_settings[add_querykw_keyword]" type="text" size="20" maxlength="64" value="" />=</code>'
1128
+ . $three_dots;
1129
+ }
1130
+
1131
+ /**
1132
+ * Section text for Section5
1133
+ *
1134
+ * Display an explanation of this Section
1135
+ *
1136
+ */
1137
+ function jr_mt_query_expl() {
1138
+ ?>
1139
+ <p>
1140
+ Select a Theme to use
1141
+ whenever the specified Query Keyword <b>and</b> Value (<code>?keyword=value</code> or <code>&keyword=value</code>)
1142
+ are found in the URL of
1143
+ any Page, Post or
1144
+ any other non-Admin page.
1145
+ And click any of the <b>Save All Changes</b> buttons to add the entry.
1146
+ </p>
1147
+ <p>
1148
+ <b>
1149
+ Note
1150
+ </b>
1151
+ that Query Keyword=Value takes precedence over all other Theme selection entries,
1152
+ including a Query Keyword entry for the same Keyword.
1153
+ For example,
1154
+ <?php
1155
+ echo '<code>' . home_url() . '?firstname=dorothy</code>'
1156
+ . ' would use the Theme specified for the <code>firstname=dorothy</code> keyword=value pair,'
1157
+ . ' not the Theme specified for Site Home nor even the Theme specified for the Keyword <code>firstname</code>.'
1158
+ . ' Query matching is case-insensitive, so all Keywords and Values entered are stored in lower-case.</p>';
1159
+ }
1160
+ function jr_mt_echo_add_query_theme() {
1161
+ jr_mt_themes_field( 'add_query_theme', '', 'jr_mt_settings', FALSE );
1162
+ }
1163
+ function jr_mt_echo_add_query_keyword() {
1164
+ $three_dots = '&#133;';
1165
+ echo '<code>'
1166
+ . home_url()
1167
+ . "/</code>$three_dots<code>/?"
1168
+ . '<input id="add_query_keyword" name="jr_mt_settings[add_query_keyword]" type="text" size="20" maxlength="64" value="" /></code>';
1169
+ }
1170
+ function jr_mt_echo_add_query_value() {
1171
+ echo '<code>'
1172
+ . '='
1173
+ . '<input id="add_query_value" name="jr_mt_settings[add_query_value]" type="text" size="20" maxlength="64" value="" /></code>';
1174
+ }
1175
+
1176
+ /**
1177
+ * Section text for Section6
1178
+ *
1179
+ * Display an explanation of this Section
1180
+ *
1181
+ */
1182
+ function jr_mt_sticky_expl() {
1183
+ /* "Membership System V2" is a paid plugin that blocks (our sticky) Cookies
1184
+ */
1185
+ global $jr_mt_plugins_cache;
1186
+ foreach ( $jr_mt_plugins_cache as $rel_path => $plugin_data ) {
1187
+ if ( 0 === strncasecmp( 'memberium', $rel_path, 9 ) ) {
1188
+ 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: '
1189
+ . $plugin_data['Name'];
1190
+ break;
1191
+ }
1192
+ }
1193
+ ?>
1194
+ <p>
1195
+ If one of the
1196
+ <b>
1197
+ Keyword=Value Entries
1198
+ </b>
1199
+ shown below
1200
+ (if any)
1201
+ is present in the URL of a WordPress non-Admin webpage on the current WordPress Site
1202
+ and that Entry is:
1203
+ <ol>
1204
+ <li>
1205
+ <b>Sticky</b>,
1206
+ then the specified Theme will continue to be displayed for subsequent
1207
+ WordPress non-Admin webpages
1208
+ viewed by the same Visitor
1209
+ until an Override entry is encountered by the same Visitor.
1210
+ </li>
1211
+ <li>
1212
+ <b>Override</b>,
1213
+ then the specified Theme will be displayed,
1214
+ effectively ending any previous Sticky Theme that was being displayed
1215
+ for the same Visitor.
1216
+ </li>
1217
+ </ol>
1218
+ <b>
1219
+ Note
1220
+ </b>
1221
+ that,
1222
+ as explained in the
1223
+ Query Keyword=Value
1224
+ section on the Settings tab,
1225
+ Query Keyword=Value already takes precedence over all other Theme selection entries,
1226
+ even without the Override checkbox selected.
1227
+ Override is only intended to cancel a Sticky entry
1228
+ and display the specified Theme on the current WordPress non-Admin webpage.
1229
+ </p>
1230
+ <p>
1231
+ Implementation Notes:
1232
+ <ol>
1233
+ <li>
1234
+ The term "Same Visitor",
1235
+ used above,
1236
+ refers to a single combination of
1237
+ computer, browser and possibly computer user name,
1238
+ if the visitor's computer has multiple accounts or user names.
1239
+ A computer could be a smartphone, tablet, laptop, desktop or other Internet access device used by the Visitor.
1240
+ </li>
1241
+ <li>
1242
+ When Sticky is active for a given Visitor,
1243
+ the associated Query Keyword=Value is added to the
1244
+ URL of links displayed on the current WordPress non-Admin webpage.
1245
+ With the following exceptions:
1246
+ <ul>
1247
+ <li>
1248
+ a)
1249
+ Only links pointing to non-Admin webpages of the current WordPress Site are altered.
1250
+ </li>
1251
+ <li>
1252
+ b)
1253
+ The
1254
+ "When to add Sticky Query to a URL"
1255
+ setting below also controls when a Sticky Keyword=Value is added to a URL.
1256
+ </li>
1257
+ </ul>
1258
+ <li>
1259
+ Cookies are used for Sticky entries. If the visitor's browser refuses Cookies,
1260
+ or another Plugin blocks cookies,
1261
+ this setting will not work and no error messages will be displayed.
1262
+ </li>
1263
+ </ol>
1264
+ </p>
1265
+ <p>
1266
+ <b>
1267
+ Important:
1268
+ </b>
1269
+ the Sticky feature cannot be made to work in all WordPress environments.
1270
+ Timing, Cookie and other issues may be caused by other plugins, themes and visitor browser settings,
1271
+ 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.
1272
+ </p>
1273
+ <?php
1274
+ }
1275
+
1276
+ function jr_mt_echo_query_present() {
1277
+ $settings = get_option( 'jr_mt_settings' );
1278
+ /*
1279
+ FALSE if Setting "Append if no question mark ("?") found in URL", or
1280
+ TRUE if Setting "Append if no Override keyword=value found in URL"
1281
+ */
1282
+ echo '<input type="radio" id="query_present" name="jr_mt_settings[query_present]" value="false" ';
1283
+ checked( $settings['query_present'], FALSE );
1284
+ echo ' /> Append if no question mark ("?") found in URL<br/><input type="radio" id="query_present" name="jr_mt_settings[query_present]" value="true" ';
1285
+ checked( $settings['query_present'] );
1286
+ echo ' /> Append if no Override <code>keyword=value</code> found in URL';
1287
+ }
1288
+
1289
+ function jr_mt_echo_sticky_query_entry() {
1290
+ global $jr_mt_kwvalsep;
1291
+ $settings = get_option( 'jr_mt_settings' );
1292
+ $three_dots = '&#133;';
1293
+ $first = TRUE;
1294
+ if ( !empty( $settings['query'] ) ) {
1295
+ foreach ( $settings['query'] as $keyword => $value_array ) {
1296
+ foreach ( $value_array as $value => $theme ) {
1297
+ if ( '*' !== $value ) {
1298
+ if ( $first ) {
1299
+ $first = FALSE;
1300
+ } else {
1301
+ echo '<br />';
1302
+ }
1303
+ echo 'Sticky <input type="checkbox" id="sticky_query_entry" name="jr_mt_settings[sticky_query_entry][]" value="'
1304
+ . "$keyword$jr_mt_kwvalsep$value"
1305
+ . '" ';
1306
+ checked( isset( $settings['remember']['query'][$keyword][$value] ) );
1307
+ echo ' /> &nbsp; Override <input type="checkbox" id="override_query_entry" name="jr_mt_settings[override_query_entry][]" value="'
1308
+ . "$keyword$jr_mt_kwvalsep$value"
1309
+ . '" ';
1310
+ checked( isset( $settings['override']['query'][$keyword][$value] ) );
1311
+ echo ' /> &nbsp; Theme='
1312
+ . wp_get_theme( $theme )->Name . '; '
1313
+ . 'Query='
1314
+ . '<code>'
1315
+ . home_url()
1316
+ . "/</code>$three_dots<code>/?"
1317
+ . "<b><input type='text' readonly='readonly' disable='disabled' name='jr_mt_stkw' value='$keyword' size='"
1318
+ . jr_mt_strlen( $keyword )
1319
+ . "' /></b>"
1320
+ . '='
1321
+ . "<b><input type='text' readonly='readonly' disable='disabled' name='jr_mt_stkwval' value='$value' size='"
1322
+ . jr_mt_strlen( $value )
1323
+ . "' /></b></code>";
1324
+ }
1325
+ }
1326
+ }
1327
+ }
1328
+ if ( $first ) {
1329
+ echo 'None';
1330
+ }
1331
+ }
1332
+
1333
+ function jr_mt_everything_expl() {
1334
+ ?>
1335
+ <p>
1336
+ <b>Theme for Everything</b>
1337
+ simplifies the use of a Theme with Theme Settings that you need to change frequently,
1338
+ when the Theme is only going to be used on one or more Pages or Posts.
1339
+ The Theme can be set as the WordPress Active Theme through the Appearance-Themes admin panel,
1340
+ and set for specific Pages or Posts using this plugin's settings (on Settings tab),
1341
+ with another Theme specified below as the plugin's default theme ("Theme for Everything").
1342
+ </p>
1343
+ <?php
1344
+ }
1345
+
1346
+ function jr_mt_echo_current() {
1347
+ $settings = get_option( 'jr_mt_settings' );
1348
+ jr_mt_themes_field( 'current', $settings['current'], 'jr_mt_settings', TRUE );
1349
+ echo '<br />(select blank entry for default: WordPress Active Theme defined in Appearance-Themes, currently <b>' . wp_get_theme()->Name . '</b>)';
1350
+ }
1351
+
1352
+ function jr_mt_all_settings_expl() {
1353
+ ?>
1354
+ <p>
1355
+ These are
1356
+ <b>
1357
+ Advanced Setting
1358
+ </b>
1359
+ because they may not work with every other plugin, theme or permalinks setting.
1360
+ This plugin is only able to determine whether what is about to be displayed at the current URL
1361
+ is a Page or Post
1362
+ after all other Plugins have been loaded;
1363
+ the one exception to this is the Default setting for Permalinks,
1364
+ when <code>?p=</code> and <code>?page_id=</code> are used.
1365
+ </p>
1366
+ <p>
1367
+ Some other plugins and themes request the name of the current Theme
1368
+ <i>
1369
+ too early,
1370
+ </i>
1371
+ while they are being loaded,
1372
+ which is before this plugin is able to determine if it is on a Page or Post.
1373
+ For this reason,
1374
+ using either of these settings may not work properly for all other plugins and themes.
1375
+ As a result,
1376
+ if you choose to use either or both of these two settings,
1377
+ careful testing is advised immediately
1378
+ <u>and</u>
1379
+ whenever you change the Permalink setting, activate a plugin or start using a different theme.
1380
+ </p>
1381
+ <p>
1382
+ In this section, you can select a different Theme for All Pages and/or All Posts.
1383
+ To remove a previously selected Theme, select the blank entry from the drop-down list.
1384
+ </p>
1385
+ <p>
1386
+ 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
1387
+ any other non-Admin pages that have their own Permalink; for example, specific Archive or Category pages.
1388
+ Or groups of Pages, Posts or any other non-Admin pages that share the same URL Prefix.
1389
+ </p>
1390
+ <p>
1391
+ The Settings tab also has a Query Keyword section
1392
+ that allows
1393
+ you to select a Theme to use whenever a specified
1394
+ Query Keyword (<code>?keyword=value</code> or <code>&keyword=value</code>)
1395
+ appears in the URL of any Page, Post or other non-Admin page.
1396
+ </p>
1397
+ <?php
1398
+ }
1399
+
1400
+ function jr_mt_echo_all_things( $thing ) {
1401
+ $settings = get_option( 'jr_mt_settings' );
1402
+ $field = 'all_' . strtolower( $thing['thing'] );
1403
+ jr_mt_themes_field( $field, $settings[$field], 'jr_mt_settings', TRUE );
1404
+ }
1405
+
1406
+ function jr_mt_validate_settings( $input ) {
1407
+ global $jr_mt_kwvalsep;
1408
+ $valid = array();
1409
+
1410
+ if ( isset( $input['permalink'] ) ) {
1411
+ $internal_settings = get_option( 'jr_mt_internal_settings' );
1412
+ $internal_settings['permalink'] = get_option( 'permalink_structure' );
1413
+ update_option( 'jr_mt_internal_settings', $internal_setting );
1414
+ }
1415
+
1416
+ foreach ( array( 'all_pages', 'all_posts', 'site_home', 'current' ) as $thing ) {
1417
+ $valid[$thing] = $input[$thing];
1418
+ }
1419
+
1420
+ $settings = get_option( 'jr_mt_settings' );
1421
+ $prefix_types = array(
1422
+ 'false' => 'url',
1423
+ 'prefix' => 'url_prefix',
1424
+ '*' => 'url_asterisk'
1425
+ );
1426
+ foreach ( $prefix_types as $key => $thing ) {
1427
+ $valid[$thing] = $settings[$thing];
1428
+ }
1429
+ $query = $settings['query'];
1430
+ $remember = array( 'query' => array() );
1431
+ if ( isset( $input['sticky_query_entry'] ) ) {
1432
+ foreach ( $input['sticky_query_entry'] as $query_entry ) {
1433
+ list( $keyword, $value ) = explode( $jr_mt_kwvalsep, $query_entry );
1434
+ /* Data Sanitization not required as
1435
+ Keyword and Value are not entered by a human,
1436
+ but extracted from previously-generated HTML.
1437
+ */
1438
+ $remember['query'][$keyword][$value] = TRUE;
1439
+ }
1440
+ }
1441
+
1442
+ $override = array( 'query' => array() );
1443
+ if ( isset( $input['override_query_entry'] ) ) {
1444
+ foreach ( $input['override_query_entry'] as $query_entry ) {
1445
+ list( $keyword, $value ) = explode( $jr_mt_kwvalsep, $query_entry );
1446
+ /* Data Sanitization not required as
1447
+ Keyword and Value are not entered by a human,
1448
+ but extracted from previously-generated HTML.
1449
+ */
1450
+ $override['query'][$keyword][$value] = TRUE;
1451
+ }
1452
+ }
1453
+
1454
+ if ( isset ( $input['del_entry'] ) ) {
1455
+ foreach ( $input['del_entry'] as $del_entry ) {
1456
+ $del_array = explode( '=', $del_entry, 3 );
1457
+ if ( 'query' === $del_array[0] ) {
1458
+ unset( $query[ $del_array[1] ][ $del_array[2] ] );
1459
+ if ( empty( $query[ $del_array[1] ] ) ) {
1460
+ unset( $query[ $del_array[1] ] );
1461
+ }
1462
+ /* unset() does nothing if a variable or array element does not exist.
1463
+ */
1464
+ unset( $remember['query'][ $del_array[1] ][ $del_array[2] ] );
1465
+ if ( empty( $remember['query'][ $del_array[1] ] ) ) {
1466
+ unset( $remember['query'][ $del_array[1] ] );
1467
+ }
1468
+ unset( $override['query'][ $del_array[1] ][ $del_array[2] ] );
1469
+ if ( empty( $override['query'][ $del_array[1] ] ) ) {
1470
+ unset( $override['query'][ $del_array[1] ] );
1471
+ }
1472
+ } else {
1473
+ /* Check for a URL entry
1474
+ */
1475
+ if ( 'url' === substr( $del_array[0], 0, 3 ) ) {
1476
+ foreach ( $valid[ $del_array[0] ] as $i => $entry_array ) {
1477
+ if ( $entry_array['url'] === $del_array[2] ) {
1478
+ /* Cannot unset $entry_array, even if prefixed by & in foreach
1479
+ */
1480
+ unset( $valid[ $del_array[0] ][ $i ] );
1481
+ break;
1482
+ }
1483
+ }
1484
+ } else {
1485
+ /* Must be Home, All Pages or Posts, or Everything
1486
+ */
1487
+ $valid[ $del_array[0] ] = '';
1488
+ }
1489
+ }
1490
+ }
1491
+ }
1492
+
1493
+ /* Handle troublesome %E2%80%8E UTF Left-to-right Mark (LRM) suffix first.
1494
+ */
1495
+ if ( FALSE === stripos( $input['add_path_id'], '%E2%80%8E' ) ) {
1496
+ if ( FALSE === stripos( rawurlencode( $input['add_path_id'] ), '%E2%80%8E' ) ) {
1497
+ $url = $input['add_path_id'];
1498
+ } else {
1499
+ $url = rawurldecode( str_ireplace( '%E2%80%8E', '', rawurlencode( $input['add_path_id'] ) ) );
1500
+ }
1501
+ } else {
1502
+ $url = str_ireplace( '%E2%80%8E', '', $input['add_path_id'] );
1503
+ }
1504
+ $url = rawurldecode( trim( $url ) );
1505
+
1506
+ if ( ( empty( $input['add_theme'] ) && !empty( $url ) ) || ( !empty( $input['add_theme'] ) && empty( $url ) ) ) {
1507
+ add_settings_error(
1508
+ 'jr_mt_settings',
1509
+ 'jr_mt_emptyerror',
1510
+ 'Both URL and Theme must be specified to add an Individual entry',
1511
+ 'error'
1512
+ );
1513
+ } else {
1514
+ if ( !empty( $url ) ) {
1515
+ if ( jr_mt_same_prefix_url( home_url(), $url ) ) {
1516
+ if ( ( '*' !== $input['add_is_prefix'] ) && ( FALSE !== strpos( $url, '*' ) ) ) {
1517
+ add_settings_error(
1518
+ 'jr_mt_settings',
1519
+ 'jr_mt_queryerror',
1520
+ 'Asterisk ("*") only allowed when "URL Prefix with Asterisk" selected: <code>' . $url . '</code>',
1521
+ 'error'
1522
+ );
1523
+ } else {
1524
+ $prep_url = jr_mt_prep_url( $url );
1525
+ if ( 'false' === $input['add_is_prefix'] ) {
1526
+ if ( jr_mt_same_url( $prep_url, home_url() ) ) {
1527
+ add_settings_error(
1528
+ 'jr_mt_settings',
1529
+ 'jr_mt_homeerror',
1530
+ 'Please use "Select Theme for Site Home" field instead of specifying Site Home URL as an individual entry.',
1531
+ 'error'
1532
+ );
1533
+ } else {
1534
+ if ( jr_mt_same_prefix_url( $prep_url, admin_url() ) ) {
1535
+ add_settings_error(
1536
+ 'jr_mt_settings',
1537
+ 'jr_mt_adminerror',
1538
+ 'Admin Page URLs are not allowed because no known Themes alter the appearance of Admin pages: <code>' . $url . '</code>',
1539
+ 'error'
1540
+ );
1541
+ }
1542
+ }
1543
+ } else {
1544
+ if ( '*' === $input['add_is_prefix'] ) {
1545
+ $url_dirs = explode( '/', str_replace( '\\', '/', $url ) );
1546
+ foreach ( $url_dirs as $dir ) {
1547
+ if ( FALSE !== strpos( $dir, '*' ) ) {
1548
+ $asterisk_found = TRUE;
1549
+ if ( '*' !== $dir ) {
1550
+ $asterisk_not_alone = TRUE;
1551
+ }
1552
+ break;
1553
+ }
1554
+ }
1555
+ if ( isset( $asterisk_found ) ) {
1556
+ if ( isset( $asterisk_not_alone ) ) {
1557
+ add_settings_error(
1558
+ 'jr_mt_settings',
1559
+ 'jr_mt_queryerror',
1560
+ 'An Asterisk ("*") may only replace a full subdirectory name, not just a portion of it: <code>' . $url . '</code>',
1561
+ 'error'
1562
+ );
1563
+ }
1564
+ } else {
1565
+ add_settings_error(
1566
+ 'jr_mt_settings',
1567
+ 'jr_mt_queryerror',
1568
+ 'No Asterisk ("*") specified but "URL Prefix with Asterisk" selected: <code>' . $url . '</code>',
1569
+ 'error'
1570
+ );
1571
+ }
1572
+ }
1573
+ }
1574
+
1575
+ function jr_mt_settings_errors() {
1576
+ $errors = get_settings_errors();
1577
+ if ( !empty( $errors ) ) {
1578
+ foreach ( $errors as $error_array ) {
1579
+ if ( 'error' === $error_array['type'] ) {
1580
+ return TRUE;
1581
+ }
1582
+ }
1583
+ }
1584
+ return FALSE;
1585
+ }
1586
+
1587
+ if ( !jr_mt_settings_errors() ) {
1588
+ /* ['url'], ['url_prefix'] or ['url_asterisk']
1589
+ */
1590
+ $key = $prefix_types[ $input['add_is_prefix'] ];
1591
+ $valid[ $key ][] = array(
1592
+ 'url' => $url,
1593
+ 'prep' => $prep_url,
1594
+ 'theme' => $input['add_theme']
1595
+ );
1596
+ }
1597
+ }
1598
+ } else {
1599
+ add_settings_error(
1600
+ 'jr_mt_settings',
1601
+ 'jr_mt_urlerror',
1602
+ ' URL specified is not part of current WordPress web site: <code>'
1603
+ . $url
1604
+ . '</code>. URL must begin with <code>'
1605
+ . home_url()
1606
+ . '</code>.',
1607
+ 'updated'
1608
+ );
1609
+ }
1610
+ }
1611
+ }
1612
+
1613
+ /* Make sure reserved characters are not used
1614
+ in URL Query keyword or value fields on Settings page.
1615
+ */
1616
+ function jr_mt_query_chars( $element, $where ) {
1617
+ foreach (
1618
+ array(
1619
+ '=' => 'Equals Sign' ,
1620
+ '?' => 'Question Mark' ,
1621
+ '&' => 'Ampersand' ,
1622
+ ' ' => 'Blank' ,
1623
+ '#' => 'Number Sign' ,
1624
+ '/' => 'Slash' ,
1625
+ '\\' => 'Backslash' ,
1626
+ '[' => 'Square Bracket',
1627
+ ']' => 'Square Bracket',
1628
+ ) as $char => $name ) {
1629
+ if ( FALSE !== strpos( $element, $char ) ) {
1630
+ add_settings_error(
1631
+ 'jr_mt_settings',
1632
+ 'jr_mt_queryerror',
1633
+ 'Illegal character used in '
1634
+ . $where
1635
+ . ': '
1636
+ . $name
1637
+ . ' ("' . $char . '") in "'
1638
+ . $element
1639
+ . '"',
1640
+ 'error'
1641
+ );
1642
+ return FALSE;
1643
+ }
1644
+ }
1645
+ return TRUE;
1646
+ }
1647
+ /* Data Sanitization needed here
1648
+ */
1649
+ $keyword = jr_mt_prep_query_keyword( $input['add_querykw_keyword'] );
1650
+ if ( !empty( $input['add_querykw_theme'] ) && !empty( $keyword ) ) {
1651
+ if ( jr_mt_query_chars( $keyword, 'Query Keyword' ) ) {
1652
+ /* If there is an existing entry for the Keyword,
1653
+ then replace it.
1654
+ Otherwise, create a new entry.
1655
+ */
1656
+ $query[$keyword]['*'] = $input['add_querykw_theme'];
1657
+ }
1658
+ } else {
1659
+ if ( !( empty( $input['add_querykw_theme'] ) && empty( $keyword ) ) ) {
1660
+ add_settings_error(
1661
+ 'jr_mt_settings',
1662
+ 'jr_mt_emptyerror',
1663
+ 'Both Query Keyword and Theme must be specified to add an Individual Query Keyword entry',
1664
+ 'error'
1665
+ );
1666
+ }
1667
+ }
1668
+
1669
+ /* Data Sanitization needed here
1670
+ */
1671
+ $keyword = jr_mt_prep_query_keyword( $input['add_query_keyword'] );
1672
+ $value = jr_mt_prep_query_value( $input['add_query_value'] );
1673
+ if ( !empty( $input['add_query_theme'] ) && !empty( $keyword ) && !empty( $value ) ) {
1674
+ if ( jr_mt_query_chars( $keyword, 'Query Keyword' ) && jr_mt_query_chars( $value, 'Query Value' ) ) {
1675
+ /* If there is an existing entry for the Keyword and Value pair,
1676
+ then replace it.
1677
+ Otherwise, create a new entry.
1678
+ */
1679
+ $query[$keyword][$value] = $input['add_query_theme'];
1680
+ }
1681
+ } else {
1682
+ if ( !( empty( $input['add_query_theme'] ) && empty( $keyword ) && empty( $value ) ) ) {
1683
+ add_settings_error(
1684
+ 'jr_mt_settings',
1685
+ 'jr_mt_emptyerror',
1686
+ 'Query Keyword, Value and Theme must all be specified to add an Individual Query entry',
1687
+ 'error'
1688
+ );
1689
+ }
1690
+ }
1691
+
1692
+ if ( 'true' === $input['query_present'] ) {
1693
+ $valid['query_present'] = TRUE;
1694
+ } else {
1695
+ if ( 'false' === $input['query_present'] ) {
1696
+ $valid['query_present'] = FALSE;
1697
+ }
1698
+ }
1699
+
1700
+ $errors = get_settings_errors();
1701
+ if ( empty( $errors ) ) {
1702
+ add_settings_error(
1703
+ 'jr_mt_settings',
1704
+ 'jr_mt_saved',
1705
+ 'Settings Saved',
1706
+ 'updated'
1707
+ );
1708
+ }
1709
+ $valid['query'] = $query;
1710
+ $valid['remember'] = $remember;
1711
+ $valid['override'] = $override;
1712
+ return $valid;
1713
+ }
1714
+
1715
+ ?>
includes/functions.php ADDED
@@ -0,0 +1,450 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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['path'] === $prefix['path'] ) {
257
+ /* Host and Path both exactly match for URL and Prefix specified.
258
+ */
259
+ if ( array() === $prefix['query'] ) {
260
+ $match = TRUE;
261
+ } else {
262
+ /* Now the hard part: determining a legitimate prefix match for Query
263
+ */
264
+ foreach ( $prefix['query'] as $prefix_keyword => $prefix_value ) {
265
+ $one_match = FALSE;
266
+ foreach ( $url['query'] as $url_keyword => $url_value ) {
267
+ if ( $prefix_keyword === jr_mt_substr( $url_keyword, 0, jr_mt_strlen( $prefix_keyword ) ) ) {
268
+ if ( $prefix_value === jr_mt_substr( $url_value, 0, jr_mt_strlen( $prefix_value ) ) ) {
269
+ $one_match = TRUE;
270
+ }
271
+ }
272
+ }
273
+ /* All Prefix Queries must match.
274
+ */
275
+ if ( FALSE === $one_match ) {
276
+ return FALSE;
277
+ }
278
+ }
279
+ $match = TRUE;
280
+ }
281
+ } else {
282
+ /* Paths must exactly match if Prefix specifies Query
283
+ */
284
+ if ( array() === $prefix['query'] ) {
285
+ /* No Query in Prefix, so check Path for Prefix match
286
+ */
287
+ $match = ( $prefix['path'] === jr_mt_substr( $url['path'], 0, jr_mt_strlen( $prefix['path'] ) ) );
288
+ } else {
289
+ $match = FALSE;
290
+ }
291
+ }
292
+ } else {
293
+ if ( ( '' === $prefix['path'] ) && ( array() === $prefix['query'] ) ) {
294
+ /* No Path or Query in Prefix, so check Host for Prefix match
295
+ */
296
+ $match = ( $prefix['host'] === jr_mt_substr( $url['host'], 0, jr_mt_strlen( $prefix['host'] ) ) );
297
+ } else {
298
+ /* Hosts must exactly match if Prefix specifies Path or Query
299
+ */
300
+ $match = FALSE;
301
+ }
302
+ }
303
+ return $match;
304
+ }
305
+
306
+ function jr_mt_same_prefix_url_asterisk( $prefix, $url ) {
307
+ if ( is_string( $prefix ) ) {
308
+ $prefix = jr_mt_prep_url( $prefix );
309
+ }
310
+ if ( is_string( $url ) ) {
311
+ $url = jr_mt_prep_url( $url );
312
+ }
313
+ $path_prefix = explode( '/', $prefix['path'] );
314
+ $path_url = explode( '/', $url['path'] );
315
+ foreach ( $path_prefix as $i => $directory ) {
316
+ if ( '*' === $directory ) {
317
+ $path_url[ $i ] = '*';
318
+ }
319
+ }
320
+ $url['path'] = implode( '/', $path_url );
321
+ return jr_mt_same_prefix_url( $prefix, $url );
322
+ }
323
+
324
+ /**
325
+ * Standardize a URL into an array of values that can be accurately compared with another
326
+ *
327
+ * Preps URL, by removing any UTF Left-to-right Mark (LRM), usually found as a suffix,
328
+ * translating the URL to lower-case, removing prefix http[s]//:[www.],
329
+ * any embedded index.php and any trailing slash or #bookmark,
330
+ * and breaks up ?keyword=value queries into array elements.
331
+ *
332
+ * Structure/Elements of Array returned:
333
+ * [host] - domain.com - www. is removed, but all other subdomains are included
334
+ * [path] - dir/file.ext
335
+ * [query] - any Queries (e.g. - "?kw=val&kw2=val2") broken up as follows:
336
+ * [$keyword] => $value with preceding equals sign, only if equals sign was present
337
+ * To simplify processing of this Array, zero length strings and empty arrays are used,
338
+ * rather than NULL entries or missing array elements.
339
+ *
340
+ * @param string $url URL to create an array from, in special format for accurate comparison
341
+ * @return array array of standardized attributes of the URL (see structure above)
342
+ */
343
+ function jr_mt_prep_url( $url ) {
344
+ /* Handle troublesome %E2%80%8E UTF Left-to-right Mark (LRM) suffix first.
345
+ */
346
+ if ( FALSE === strpos( $url, '%E2%80%8E' ) ) {
347
+ if ( FALSE === strpos( rawurlencode( $url ), '%E2%80%8E' ) ) {
348
+ $url_clean = $url;
349
+ } else {
350
+ $url_clean = rawurldecode( str_replace( '%E2%80%8E', '', rawurlencode( $url ) ) );
351
+ /* mb_str_replace() does not exist because str_replace() is binary-safe.
352
+ */
353
+ }
354
+ } else {
355
+ $url_clean = str_replace( '%E2%80%8E', '', $url );
356
+ }
357
+ $url_clean = str_replace( '\\', '/', trim( $url_clean ) );
358
+
359
+ /* parse_url(), especially before php Version 5.4.7,
360
+ has a history of problems when Scheme is not present,
361
+ especially for LocalHost as a Host,
362
+ so add a prefix of http:// if :// is not found
363
+ */
364
+ if ( FALSE === strpos( $url_clean, '://' ) ) {
365
+ $url_clean = "http://$url_clean";
366
+ }
367
+
368
+ $parse_array = parse_url( jr_mt_strtolower( $url_clean ) );
369
+ /* Get rid of URL components that do not matter to us in our comparison of URLs
370
+ */
371
+ foreach ( array( 'scheme', 'port', 'user', 'pass', 'fragment' ) as $component ) {
372
+ unset ( $parse_array[$component] );
373
+ }
374
+ /* Remove www. from host
375
+ */
376
+ if ( 'www.' === substr( $parse_array['host'], 0, 4 ) ) {
377
+ $parse_array['host'] = substr( $parse_array['host'], 4 );
378
+ }
379
+ if ( isset( $parse_array['path'] ) ) {
380
+ /* Remove any index.php occurences in path, since these can be spurious in IIS
381
+ and perhaps other environments.
382
+ */
383
+ $parse_array['path'] = str_replace( 'index.php', '', $parse_array['path'] );
384
+ /* Remove leading and trailing slashes from path
385
+ */
386
+ $parse_array['path'] = trim( $parse_array['path'], "/\\" );
387
+ } else {
388
+ $parse_array['path'] = '';
389
+ }
390
+ /* Take /?keyword=value&keyword=value URL query parameters
391
+ and break them up into array( keyword => value, keyword => value )
392
+ */
393
+ if ( isset( $parse_array['query'] ) ) {
394
+ $parms = explode( '&', $parse_array['query'] );
395
+ $parse_array['query'] = array();
396
+ foreach( $parms as $parm ) {
397
+ if ( FALSE === ( $cursor = strpos( $parm, '=' ) ) ) {
398
+ $parse_array['query'][$parm] = '';
399
+ } else {
400
+ /* Include the Equals Sign ("=") as the first character of the Query Value
401
+ to differentiate between a URL Prefix with a Query Keyword followed by
402
+ an Equals Sign, and one without. For example, "address" would match
403
+ address2=abc, while "address=" would not.
404
+ */
405
+ $parse_array['query'][jr_mt_substr( $parm, 0, $cursor + 1 )] = jr_mt_substr( $parm, $cursor + 1 );
406
+ }
407
+ }
408
+ } else {
409
+ $parse_array['query'] = array();
410
+ }
411
+ return $parse_array;
412
+ }
413
+
414
+ /** Build Query Array
415
+
416
+ $array[keyword] = array( value, value, ... )
417
+ Sets both keyword and value to lower-case as
418
+ that is how they are stored in Settings.
419
+
420
+ Supports only & separator, not proposed semi-colon separator.
421
+
422
+ Handles duplicate keywords in all four of these forms:
423
+ kw=val1&kw=val2 kw[]=val1&kw[]=val2 kw=val1&kw=val1 kw[]=val1&kw[]=val1
424
+ but nothing else, e.g. - kw=val1,val2 is not valid;
425
+ it returns "val1,val2" as the Value.
426
+ Also handles kw1&kw2
427
+
428
+ Tests of parse_str() in PHP 5.5.9 proved that semi-colon and comma
429
+ are not supported. But, neither is kw=val1,kw=val2 which is why
430
+ this function is written without the use of parse_str.
431
+ */
432
+ function jr_mt_query_array() {
433
+ /* Remove array entry indicators ("[]") as we properly handle duplicate keywords,
434
+ and covert to lower-case for comparison purposes.
435
+ */
436
+ $queries = array();
437
+ if ( !empty( $_SERVER['QUERY_STRING'] ) ) {
438
+ $query = explode( '&', jr_mt_strtolower( str_replace( '[]', '', $_SERVER['QUERY_STRING'] ) ) );
439
+ foreach ( $query as $kwval ) {
440
+ $query_entry = explode( '=', $kwval );
441
+ if ( !isset( $query_entry[1] ) ) {
442
+ $query_entry[1] = '';
443
+ }
444
+ $queries[ $query_entry[0] ][] = $query_entry[1];
445
+ }
446
+ }
447
+ return $queries;
448
+ }
449
+
450
+ ?>
includes/index.html ADDED
File without changes
includes/old-wp.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Exit if .php file accessed directly
3
+ if ( !defined( 'ABSPATH' ) ) exit;
4
+
5
+ /* A Version of WordPress older than the first one supported by the Plugin
6
+ is being run.
7
+ */
8
+
9
+ add_action( 'all_admin_notices', 'jr_mt_all_admin_notice' );
10
+ // Runs after admin_menu hook
11
+ add_action( 'admin_notices', 'jr_mt_all_admin_notice' ); // for older versions
12
+
13
+ function jr_mt_all_admin_notice() {
14
+ // Only displayed in Admin panels:
15
+ echo '<div class="error">Deactivated the <b>jonradio Multiple Themes</b> plugin: requires WordPress Version 3.4 or newer; you are running Version '
16
+ . get_bloginfo( 'version' ) . '</div>';
17
+ deactivate_plugins( JR_MT_FILE );
18
+ }
19
+
20
+ ?>
includes/select-theme.php ADDED
@@ -0,0 +1,478 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* Exit if .php file accessed directly
3
+ */
4
+ if ( !defined( 'ABSPATH' ) ) {
5
+ exit;
6
+ }
7
+
8
+ /* Select the relevant Theme
9
+ These hooks must be available immediately
10
+ as some Themes check them very early.
11
+ Also must be available in Admin for p2.
12
+ */
13
+ add_filter( 'pre_option_stylesheet', 'jr_mt_stylesheet' );
14
+ add_filter( 'pre_option_template', 'jr_mt_template' );
15
+
16
+ if ( !is_admin() ) {
17
+ /* Hooks below shown in order of execution */
18
+
19
+ /* Only do this if All Posts or All Pages setting is present.
20
+ */
21
+ if ( get_option( 'permalink_structure' ) && jr_mt_all_posts_pages() ) {
22
+ /* 'setup_theme' is the earliest Action that I could find where url_to_postid( $url )
23
+ is valid. get_post() works by then, too.
24
+ */
25
+ add_action( 'setup_theme', 'jr_mt_page_conditional', JR_MT_RUN_FIRST );
26
+ function jr_mt_page_conditional() {
27
+ /* In case any requests for Theme came before this hook,
28
+ make sure that Theme Selection is repeated the next time
29
+ it is needed.
30
+ Because url_to_postid() and possibly get_post() don't work until now.
31
+
32
+ Note: in PHP, you cannot directly unset a global variable,
33
+ hence the cryptic code below.
34
+ */
35
+ unset( $GLOBALS['jr_mt_theme'] );
36
+ DEFINE( 'JR_MT_PAGE_CONDITIONAL', TRUE );
37
+ }
38
+ }
39
+
40
+ add_action( 'wp_loaded', 'jr_mt_wp_loaded', JR_MT_RUN_LAST );
41
+ function jr_mt_wp_loaded() {
42
+ /* Purpose of this hook is to output any required Cookie before it is too late
43
+ (after the <html> or any other HTML is generated).
44
+ There is no performance impact because this effectively pre-caches values
45
+ for use later.
46
+ This timing is also used to enqueue JavaScript related to the Sticky feature.
47
+ */
48
+ global $jr_mt_theme;
49
+ if ( !isset( $jr_mt_theme ) ) {
50
+ $settings = get_option( 'jr_mt_settings' );
51
+ if ( !empty( $settings['remember']['query'] ) ) {
52
+ jr_mt_template();
53
+ }
54
+ }
55
+
56
+ DEFINE( 'JR_MT_TOO_LATE_FOR_COOKIES', TRUE );
57
+ }
58
+ }
59
+
60
+ function jr_mt_stylesheet() {
61
+ return jr_mt_theme( 'stylesheet' );
62
+ }
63
+
64
+ function jr_mt_template() {
65
+ return jr_mt_theme( 'template' );
66
+ }
67
+
68
+ function jr_mt_theme( $option ) {
69
+ /* The hooks that (indirectly) call this function are called repeatedly by WordPress,
70
+ so do the checking once and store the values in a global array.
71
+ $jt_mt_theme['stylesheet'] - Stylesheet Name of Theme chosen
72
+ $jt_mt_theme['template'] - Template Name of Theme chosen
73
+
74
+ Very important note:
75
+ - get_option( 'jr_mt_settings' ) ['ids']['theme'] is the Theme Subdirectory Name,
76
+ as opposed to the Template or Stylesheet Name for the Theme.
77
+ - likewise, the variable local variable $theme
78
+ These three different values for each Theme must be clearly separated, as all three usually
79
+ match, but do not have to, e.g. - Child Themes.
80
+ */
81
+ global $jr_mt_theme;
82
+ if ( !isset( $jr_mt_theme ) ) {
83
+ $jr_mt_theme = array();
84
+ }
85
+ if ( !isset( $jr_mt_theme[$option] ) ) {
86
+ $theme = jr_mt_chosen();
87
+ $jr_mt_all_themes = jr_mt_all_themes();
88
+ /* Check to be sure that Theme is still installed.
89
+ If not, do a massive cleanup to remove all Settings entries that
90
+ reference Themes that are no longer installed.
91
+ */
92
+ if ( ( FALSE !== $theme ) && ( !isset( $jr_mt_all_themes[ $theme ] ) ) ) {
93
+ require_once( jr_mt_path() . 'includes/settings-cleanup.php' );
94
+ $theme = jr_mt_chosen();
95
+ }
96
+ if ( FALSE === $theme ) {
97
+ // Get both at once, to save a repeat of this logic later:
98
+ $jr_mt_theme['stylesheet'] = jr_mt_current_theme( 'stylesheet' );
99
+ $jr_mt_theme['template'] = jr_mt_current_theme( 'template' );
100
+ } else {
101
+ $jr_mt_theme['stylesheet'] = $jr_mt_all_themes[ $theme ]->stylesheet;
102
+ $jr_mt_theme['template'] = $jr_mt_all_themes[ $theme ]->template;
103
+ }
104
+ if ( !is_admin() ) {
105
+ jr_mt_cookie( 'all', 'clean' );
106
+ }
107
+ }
108
+ $theme = $jr_mt_theme[$option];
109
+ return $theme;
110
+ }
111
+
112
+ // Returns FALSE for Current Theme
113
+ function jr_mt_chosen() {
114
+ $settings = get_option( 'jr_mt_settings' );
115
+
116
+ /* $queries - array of [keyword] => array( value, value, ... )
117
+ in the current URL.
118
+ */
119
+ $queries = jr_mt_query_array();
120
+
121
+ /* P2 free Theme special processing:
122
+ for both Admin and Public site,
123
+ check for P2 keyword p2ajax=,
124
+ and select P2 theme, if present.
125
+ */
126
+ if ( isset( $queries['p2ajax'] ) && array_key_exists( 'p2', jr_mt_all_themes() ) ) {
127
+ return 'p2';
128
+ }
129
+ /* Otherwise, Admin gets current ("Active") WordPress Theme
130
+ */
131
+ if ( is_admin() ) {
132
+ return FALSE;
133
+ }
134
+
135
+ /* KnowHow ThemeForest Paid Theme special processing:
136
+ if s= is present, and 'knowhow' is either the active WordPress Theme
137
+ or is specified in any Settings, then automatically select the KnowHow theme.
138
+ */
139
+ if ( isset( $queries['s'] ) && in_array( 'knowhow', jr_mt_themes_defined() ) ) {
140
+ return 'knowhow';
141
+ }
142
+
143
+ /* Non-Admin page, i.e. - Public Site, etc.
144
+
145
+ Begin by checking for any Query keywords specified by the Admin in Settings,
146
+ complicated by the fact that Override entries take precedence.
147
+ */
148
+ if ( !empty( $settings['query'] ) ) {
149
+ if ( '' !== $_SERVER['QUERY_STRING'] ) {
150
+ /* Check Override entries
151
+ */
152
+ foreach ( $settings['override']['query'] as $override_keyword => $override_value_array ) {
153
+ if ( isset( $queries[ $override_keyword ] ) ) {
154
+ foreach ( $override_value_array as $override_value => $bool ) {
155
+ if ( in_array( $override_value, $queries[ $override_keyword ] ) ) {
156
+ $override_found[] = array( $override_keyword, $override_value );
157
+ }
158
+ }
159
+ }
160
+ }
161
+ if ( !isset( $overrides_found ) ) {
162
+ /* Look for both keyword=value settings and keyword=* settings,
163
+ with keyword=value taking precedence (sorted out later).
164
+ */
165
+ foreach ( $settings['query'] as $query_settings_keyword => $value_array ) {
166
+ if ( isset( $queries[ $query_settings_keyword ] ) ) {
167
+ foreach ( $value_array as $query_settings_value => $theme ) {
168
+ if ( in_array( $query_settings_value, $queries[ $query_settings_keyword ] ) ) {
169
+ $query_found[] = array( $query_settings_keyword, $query_settings_value );
170
+ }
171
+ }
172
+ if ( isset( $value_array['*'] ) ) {
173
+ $keyword_found[] = $query_settings_keyword;
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+
181
+ /* Handle Overrides:
182
+ First, for Override keyword=value query in URL.
183
+ Second, for previous Override detected by PHP cookie.
184
+ */
185
+ if ( isset( $override_found ) ) {
186
+ /* If sticky, create JavaScript Sticky Cookie,
187
+ and PHP Sticky Cookie.
188
+ No matter what:
189
+ return Theme from the first Override found.
190
+ */
191
+ $keyword = $override_found[0][0];
192
+ $value = $override_found[0][1];
193
+ if ( isset( $settings['remember']['query'][ $keyword ][ $value ] ) ) {
194
+ jr_mt_js_sticky_query( $keyword, $value );
195
+ jr_mt_cookie( 'php', 'put', "$keyword=$value" );
196
+ }
197
+ return $settings['query'][ $keyword ][ $value ];
198
+ } else {
199
+ /* Is there a previous Override Query for this Site Visitor?
200
+ If so, use it, but only if it is still valid.
201
+ */
202
+ if ( FALSE !== ( $cookie = jr_mt_cookie( 'php', 'get' ) ) ) {
203
+ list( $keyword, $value ) = explode( '=', $cookie );
204
+ if ( isset( $settings['override']['query'][ $keyword ][ $value ] ) ) {
205
+ /* If sticky, create JavaScript Sticky Cookie,
206
+ and renew PHP Sticky Cookie.
207
+ No matter what:
208
+ Return Theme
209
+ */
210
+ if ( isset( $settings['remember']['query'][ $keyword ][ $value ] ) ) {
211
+ jr_mt_js_sticky_query( $keyword, $value );
212
+ jr_mt_cookie( 'php', 'put', "$keyword=$value" );
213
+ }
214
+ return $settings['query'][ $keyword ][ $value ];
215
+ }
216
+ }
217
+ }
218
+
219
+ /* Handle Non-Overrides:
220
+ keyword=value query in URL with matching setting entry.
221
+ */
222
+ if ( isset( $query_found ) ) {
223
+ $query_keyword_found = $query_found[0][0];
224
+ $query_value_found = $query_found[0][1];
225
+ /* Probably makes sense to give preference to the Sticky ones
226
+ */
227
+ foreach ( $query_found as $query_kwval_array ) {
228
+ if ( isset( $settings['remember']['query'][ $query_kwval_array[0] ][ $query_kwval_array[1] ] ) ) {
229
+ $query_keyword_found = $query_kwval_array[0];
230
+ $query_value_found = $query_kwval_array[1];
231
+ /* Create JavaScript Sticky Cookie,
232
+ and PHP Sticky Cookie.
233
+ */
234
+ jr_mt_js_sticky_query( $query_keyword_found, $query_value_found );
235
+ jr_mt_cookie( 'php', 'put', "$query_keyword_found=$query_value_found" );
236
+ break;
237
+ }
238
+ }
239
+ /* Return Theme
240
+ */
241
+ return $settings['query'][ $query_keyword_found ][ $query_value_found ];
242
+ }
243
+
244
+ /* Handle Keyword wildcards:
245
+ keyword=* setting entry that matches keyword in URL query.
246
+ */
247
+ if ( isset( $keyword_found ) ) {
248
+ return $settings['query'][ $keyword_found[0] ]['*'];
249
+ }
250
+
251
+ /* Now look at URL entries: $settings['url'] and ['url_prefix']
252
+ */
253
+
254
+ $home_url = home_url();
255
+ $prep_url = jr_mt_prep_url( $current_url = parse_url( $home_url, PHP_URL_SCHEME ) . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] );
256
+ foreach ( $settings['url'] as $settings_array ) {
257
+ if ( jr_mt_same_url( $settings_array['prep'], $prep_url ) ) {
258
+ return $settings_array['theme'];
259
+ }
260
+ }
261
+ foreach ( $settings['url_prefix'] as $settings_array ) {
262
+ if ( jr_mt_same_prefix_url( $settings_array['prep'], $prep_url ) ) {
263
+ return $settings_array['theme'];
264
+ }
265
+ }
266
+ foreach ( $settings['url_asterisk'] as $settings_array ) {
267
+ if ( jr_mt_same_prefix_url_asterisk( $settings_array['prep'], $prep_url ) ) {
268
+ return $settings_array['theme'];
269
+ }
270
+ }
271
+
272
+ /* Must check for Home near the end as queries override
273
+ */
274
+ $prep_url_no_query = $prep_url;
275
+ $prep_url_no_query['query'] = array();
276
+ if ( '' !== $settings['site_home'] ) {
277
+ /* Check for Home Page,
278
+ with or without Query.
279
+ */
280
+ $prep_url_no_query = $prep_url;
281
+ $prep_url_no_query['query'] = array();
282
+ if ( jr_mt_same_url( $home_url, $prep_url_no_query ) ) {
283
+ return $settings['site_home'];
284
+ }
285
+ }
286
+ /* All Pages and All Posts settings are checked second to last,
287
+ just before Everything Else.
288
+
289
+ url_to_postid() only works after JR_MT_PAGE_CONDITIONAL is set.
290
+ But alternate means can be used with default Permalinks.
291
+
292
+ First, see if any All Pages or All Posts setting exists.
293
+ */
294
+ if ( jr_mt_all_posts_pages() ) {
295
+ if ( defined( 'JR_MT_PAGE_CONDITIONAL' ) ) {
296
+ if ( 0 !== ( $id = url_to_postid( $current_url ) ) ) {
297
+ if ( NULL !== ( $post = get_post( $id ) ) ) {
298
+ $type = $post->post_type;
299
+ if ( 'post' === $type ) {
300
+ if ( '' !== $settings['all_posts'] ) {
301
+ return $settings['all_posts'];
302
+ }
303
+ } else {
304
+ if ( 'page' === $type ) {
305
+ if ( '' !== $settings['all_pages'] ) {
306
+ return $settings['all_pages'];
307
+ }
308
+ }
309
+ }
310
+ }
311
+ }
312
+ } else {
313
+ $permalink = get_option( 'permalink_structure' );
314
+ if ( empty( $permalink ) ) {
315
+ if ( '' !== $settings['all_posts'] ) {
316
+ if ( isset( $queries['p'] ) ) {
317
+ return $settings['all_posts'];
318
+ }
319
+ }
320
+
321
+ if ( '' !== $settings['all_pages'] ) {
322
+ if ( isset( $queries['page_id'] ) ) {
323
+ return $settings['all_pages'];
324
+ }
325
+ }
326
+ }
327
+ }
328
+ }
329
+ /* This is the Theme for Everything Advanced Setting.
330
+ A Setting of Blank uses WordPress Current Theme value,
331
+ i.e. - the Setting is not set.
332
+ */
333
+ if ( '' === $settings['current'] ) {
334
+ return FALSE;
335
+ } else {
336
+ return $settings['current'];
337
+ }
338
+ }
339
+
340
+ /** Cookie to JavaScript with Sticky Query and related info.
341
+
342
+ Replace Existing or Create New (if no existing) Cookie
343
+ to remember what Sticky Keyword=Value to use on this Browser on this Visitor Computer.
344
+ Cookie is an encoding of this array:
345
+ - keyword=value query to append to URL
346
+ - FALSE if Setting "Append if no question mark ("?") found in URL", or
347
+ TRUE if Setting "Append if no Override keyword=value found in URL"
348
+ - an array of all sticky or override queries (empty array if FALSE)
349
+ */
350
+ function jr_mt_js_sticky_query( $keyword, $value ) {
351
+ add_action( 'wp_enqueue_scripts', 'jr_mt_wp_enqueue_scripts' );
352
+ function jr_mt_wp_enqueue_scripts() {
353
+ global $jr_mt_plugin_data;
354
+ wp_enqueue_script( 'jr_mt_sticky', plugins_url() . '/' . dirname( jr_mt_plugin_basename() ) . '/js/sticky.js', array(), $jr_mt_plugin_data['Version'] );
355
+ /* JavaScript needs some values passed in HTML,
356
+ so add that hook here, too.
357
+ */
358
+ add_action( 'wp_footer', 'jr_mt_wp_footer' );
359
+ }
360
+ function jr_mt_wp_footer() {
361
+ echo '<div style="display: none;"><div id="jr-mt-home-url" title="'
362
+ . jr_mt_prep_comp_url( home_url() )
363
+ . '"></div><div id="jr-mt-site-admin" title="'
364
+ . jr_mt_prep_comp_url( admin_url() )
365
+ . '"></div></div>';
366
+ }
367
+ /** Prepare URL for JavaScript compares
368
+
369
+ Remove http[s]//: from beginning
370
+ Convert rest of URL to lower-case
371
+ Remove www. from beginning, if present
372
+ Convert any backslashes to forward slashes
373
+ Remove any trailing slash(es).
374
+ */
375
+ function jr_mt_prep_comp_url( $url ) {
376
+ $comp_url = strtolower( substr( $url, 3 + strpos( $url, '://' ) ) );
377
+ if ( 'www.' === substr( $comp_url, 0, 4 ) ) {
378
+ $comp_url = substr( $comp_url, 4 );
379
+ }
380
+ return rtrim( str_replace( '\\', '/', $comp_url ), '/' );
381
+ }
382
+
383
+ $settings = get_option( 'jr_mt_settings' );
384
+
385
+ if ( $settings['query_present'] ) {
386
+ foreach ( $settings['override']['query'] as $override_keyword => $override_value_array ) {
387
+ foreach ( $override_value_array as $override_value => $theme ) {
388
+ $override[] = "$override_keyword=$override_value";
389
+ }
390
+ }
391
+ } else {
392
+ $override = array();
393
+ }
394
+
395
+ jr_mt_cookie( 'js', 'put', strtr( rawurlencode( json_encode(
396
+ array( "$keyword=$value", $settings['query_present'], $override ) ) ),
397
+ array( '%21' => '!', '%2A' => '*', '%27' => "'", '%28' => '(', '%29' => ')' ) )
398
+ );
399
+ }
400
+
401
+ /* All Cookie Handling occurs here.
402
+ $action - 'get', 'put', 'del'
403
+ */
404
+ function jr_mt_cookie( $lang, $action, $cookie_value = '' ) {
405
+ switch ( $lang ) {
406
+ case 'js':
407
+ $cookie_name = 'jr-mt-remember-query';
408
+ $raw = TRUE;
409
+ $expiry = '+36 hours';
410
+ $function = 'setrawcookie';
411
+ break;
412
+ case 'php':
413
+ $cookie_name = 'jr_mt_php_override_query';
414
+ $raw = FALSE;
415
+ $expiry = '+1 year';
416
+ $function = 'setcookie';
417
+ break;
418
+ }
419
+ if ( 'get' === $action ) {
420
+ if ( isset( $_COOKIE[ $cookie_name ] ) ) {
421
+ return $_COOKIE[ $cookie_name ];
422
+ } else {
423
+ return FALSE;
424
+ }
425
+ } else {
426
+ global $jr_mt_cookie_track;
427
+ if ( defined( 'JR_MT_TOO_LATE_FOR_COOKIES' ) ) {
428
+ return FALSE;
429
+ }
430
+ /* Determine Path off Domain to WordPress Address, not Site Address, for Cookie Path value.
431
+ Using home_url().
432
+ */
433
+ $cookie_path = parse_url( home_url(), PHP_URL_PATH ) . '/';
434
+ switch ( $action ) {
435
+ case 'put':
436
+ if ( empty( $cookie_value ) ) {
437
+ return FALSE;
438
+ } else {
439
+ return ( $jr_mt_cookie_track[ $lang ] = $function( $cookie_name, $cookie_value, strtotime( $expiry ), $cookie_path, $_SERVER['SERVER_NAME'] ) );
440
+ }
441
+ break;
442
+ case 'del':
443
+ /* Don't clutter up output to browser with a Cookie Delete request if a Cookie does not exist.
444
+ */
445
+ if ( isset( $_COOKIE[ $cookie_name ] ) ) {
446
+ return ( $jr_mt_cookie_track[ $lang ] = setrawcookie( $cookie_name, '', strtotime( '-2 days' ), $cookie_path, $_SERVER['SERVER_NAME'] ) );
447
+ }
448
+ break;
449
+ case 'clean':
450
+ if ( 'all' === $lang ) {
451
+ $clean_langs = array( 'php', 'js' );
452
+ } else {
453
+ $clean_langs = array( $lang );
454
+ }
455
+ foreach ( $clean_langs as $clean_lang ) {
456
+ if ( !isset( $jr_mt_cookie_track[ $clean_lang ] ) ) {
457
+ jr_mt_cookie( $clean_lang, 'del' );
458
+ }
459
+ }
460
+ break;
461
+ }
462
+ }
463
+ }
464
+
465
+ /** Will the url_to_postid() function be required?
466
+ *
467
+ * Only if:
468
+ * - Pretty Permalinks are being used, AND
469
+ * - ( All Posts setting is set, OR
470
+ * - All Pages setting is set )
471
+ * @return bool if add_action is required
472
+ */
473
+ function jr_mt_all_posts_pages() {
474
+ $settings = get_option( 'jr_mt_settings' );
475
+ return ( $settings['all_posts'] || $settings['all_pages'] );
476
+ }
477
+
478
+ ?>
includes/settings-cleanup.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /* Exit if .php file accessed directly
3
+ */
4
+ if ( !defined( 'ABSPATH' ) ) {
5
+ exit;
6
+ }
7
+
8
+ if ( defined( 'JR_MT_WP_GET_THEMES_WORKS' ) ) {
9
+ jr_mt_settings_cleanup();
10
+ } else {
11
+ add_action( JR_MT_WP_GET_THEMES_ACTION, 'jr_mt_settings_cleanup', JR_MT_RUN_SECOND );
12
+ }
13
+
14
+ function jr_mt_settings_cleanup() {
15
+ /* Go through all Settings and eliminate any entries where Theme
16
+ "does not exist", i.e. - has been deleted since Setting was originally created.
17
+ */
18
+ $settings = get_option( 'jr_mt_settings' );
19
+ $update = FALSE;
20
+ foreach ( array( 'all_pages', 'all_posts', 'site_home', 'current' ) as $key ) {
21
+ $theme = $settings[ $key ];
22
+ $jr_mt_all_themes = jr_mt_all_themes();
23
+ if ( ( '' !== $theme ) && ( !isset( $jr_mt_all_themes[ $theme ] ) ) ) {
24
+ /* Theme is not installed, so delete entry.
25
+ */
26
+ $settings[ $key ] = '';
27
+ $update = TRUE;
28
+ }
29
+ }
30
+ foreach ( $settings['query'] as $keyword => $values ) {
31
+ foreach ( $values as $value => $theme ) {
32
+ if ( !isset( $jr_mt_all_themes[ $theme ] ) ) {
33
+ unset( $settings['query'][ $keyword ][ $value ] );
34
+ if ( empty( $settings['query'][ $keyword ] ) ) {
35
+ unset( $settings['query'][ $keyword ] );
36
+ }
37
+ $update = TRUE;
38
+ }
39
+ }
40
+ }
41
+ foreach ( array( 'url', 'url_prefix', 'url_asterisk' ) as $index => $url_type ) {
42
+ foreach ( $settings[ $url_type ] as $entry_array ) {
43
+ if ( !isset( $jr_mt_all_themes[ $entry_array['theme'] ] ) ) {
44
+ unset( $settings[ $url_type ][ $index ] );
45
+ $update = TRUE;
46
+ }
47
+ }
48
+ }
49
+ $queries = $settings['query'];
50
+ foreach ( array( 'remember', 'override' ) as $query_type ) {
51
+ foreach ( $settings[ $query_type ]['query'] as $keyword => $values ) {
52
+ foreach ( $values as $value => $bool ) {
53
+ if ( !isset( $queries[ $keyword ][ $value ] ) ) {
54
+ unset( $settings[ $query_type ]['query'][ $keyword ][ $value ] );
55
+ $update = TRUE;
56
+ if ( empty( $settings[ $query_type ]['query'][ $keyword ] ) ) {
57
+ unset( $settings[ $query_type ]['query'][ $keyword ] );
58
+ }
59
+ }
60
+ }
61
+ }
62
+ }
63
+ if ( $update ) {
64
+ update_option( 'jr_mt_settings', $settings );
65
+ }
66
+ }
67
+
68
+ ?>
includes/upgradev5.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* Exit if .php file accessed directly
4
+ */
5
+ if ( !defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ /* setup_theme is the earliest Action where
10
+ all functions in jr_mt_convert_ids() work properly.
11
+ */
12
+ add_action( 'setup_theme', 'jr_mt_convert_ids', JR_MT_RUN_FIRST );
13
+
14
+ /**
15
+ * Convert pre-Version 5 ['ids'] Settings to new Version 5 format.
16
+ *
17
+ * Mainly, it involves converting Post ID to URL.
18
+ *
19
+ */
20
+ function jr_mt_convert_ids() {
21
+ $internal_settings = get_option( 'jr_mt_internal_settings' );
22
+ if ( isset( $internal_settings['ids'] ) ) {
23
+ $settings = get_option( 'jr_mt_settings' );
24
+ foreach ( $settings['ids'] as $key => $ids_array ) {
25
+ /* Be sure that Theme has not been deleted.
26
+ */
27
+ $jr_mt_all_themes = jr_mt_all_themes();
28
+ if ( isset( $jr_mt_all_themes[ $ids_array['theme'] ] ) ) {
29
+ /* $key:
30
+ '' - Home entry
31
+ */
32
+ if ( '' === $key ) {
33
+ if ( '' === $settings['site_home'] ) {
34
+ $settings['site_home'] = $ids_array['theme'];
35
+ }
36
+ } else {
37
+ if ( isset( $ids_array['type'] ) ) {
38
+ switch ( $ids_array['type'] ) {
39
+ case 'admin':
40
+ /* Ignore as Admin pages are ignored
41
+ */
42
+ break;
43
+ case 'prefix':
44
+ /* URL Prefix
45
+ */
46
+ $url = get_home_url() . "/$key";
47
+ $settings['url_prefix'][] = array(
48
+ 'url' => $url,
49
+ 'prep' => jr_mt_prep_url( $url ),
50
+ 'theme' => $ids_array['theme']
51
+ );
52
+ break;
53
+ case '*':
54
+ /* URL Prefix with Asterisk
55
+ */
56
+ $url = get_home_url() . "/$key";
57
+ $settings['url_asterisk'][] = array(
58
+ 'url' => $url,
59
+ 'prep' => jr_mt_prep_url( $url ),
60
+ 'theme' => $ids_array['theme']
61
+ );
62
+ break;
63
+ case 'cat':
64
+ if ( !is_wp_error( get_the_category_by_ID( $key ) ) ) {
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
+ /* Ignore non-existent Categories.
73
+ They were likely deleted.
74
+ */
75
+ break;
76
+ case 'archive':
77
+ /* From ?m=yyyymm query originally
78
+ */
79
+ $yyyymm = $ids_array['id'];
80
+ $year = intval( $yyyymm / 100 );
81
+ $month = $yyyymm % 100;
82
+ $url = get_month_link( $year, $month );
83
+ $settings['url'][] = array(
84
+ 'url' => $url,
85
+ 'prep' => jr_mt_prep_url( $url ),
86
+ 'theme' => $ids_array['theme']
87
+ );
88
+ break;
89
+ default:
90
+ if ( FALSE === $ids_array['id'] ) {
91
+ /* Exact URL
92
+ */
93
+ $url = get_home_url() . "/$key";
94
+ $settings['url'][] = array(
95
+ 'url' => $url,
96
+ 'prep' => jr_mt_prep_url( $url ),
97
+ 'theme' => $ids_array['theme']
98
+ );
99
+ } else {
100
+ /* Some Post type
101
+
102
+ get_permalink() can be used as early as Action Hook 'setup_theme',
103
+ but not in 'plugins_loaded' (Fatal Error).
104
+ */
105
+ if ( FALSE !== ( $url = get_permalink( $key ) ) ) {
106
+ $settings['url'][] = array(
107
+ 'url' => $url,
108
+ 'prep' => jr_mt_prep_url( $url ),
109
+ 'theme' => $ids_array['theme']
110
+ );
111
+ }
112
+ /* Ignore any non-existent IDs, typically deleted.
113
+ */
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+ }
120
+ update_option( 'jr_mt_settings', $settings );
121
+
122
+ unset( $internal_settings['ids'] );
123
+ update_option( 'jr_mt_internal_settings', $internal_settings );
124
+ }
125
+ }
126
+
127
+ ?>
index.html ADDED
File without changes
jonradio-multiple-themes.php ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: 5.0.2
7
+ Author: David Gewirtz
8
+ Author URI: http://zatzlabs.com/plugins/
9
+ License: GPLv2
10
+ */
11
+
12
+ /* Copyright 2014 jonradio (email : info@zatz.com)
13
+
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License as published by
16
+ the Free Software Foundation; either version 2 of the License, or
17
+ (at your option) any later version.
18
+
19
+ This program is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ GNU General Public License for more details.
23
+
24
+ You should have received a copy of the GNU General Public License
25
+ along with this program; if not, write to the Free Software
26
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
+ */
28
+
29
+ /* Exit if .php file accessed directly
30
+ */
31
+ if ( !defined( 'ABSPATH' ) ) {
32
+ exit;
33
+ }
34
+
35
+ /* For Hooks, when it needs to run first or last.
36
+ */
37
+ DEFINE( 'JR_MT_RUN_FIRST', 1 );
38
+ DEFINE( 'JR_MT_RUN_SECOND', JR_MT_RUN_FIRST + 1 );
39
+ DEFINE( 'JR_MT_RUN_LAST', 999 );
40
+
41
+ DEFINE( 'JR_MT_WP_GET_THEMES_ACTION', 'plugins_loaded' );
42
+
43
+ DEFINE( 'JR_MT_FILE', __FILE__ );
44
+
45
+ /* Catch old unsupported version of WordPress before any damage can be done.
46
+ */
47
+ if ( version_compare( get_bloginfo( 'version' ), '3.4', '<' ) ) {
48
+ require_once( plugin_dir_path( JR_MT_FILE ) . 'includes/old-wp.php' );
49
+ } else {
50
+ /* Use $plugin_data['Name'] for the array of incompatible plugins
51
+ */
52
+ global $jr_mt_incompat_plugins;
53
+ $jr_mt_incompat_plugins = array( 'Theme Test Drive' ); // removed for V5: 'BuddyPress', 'Polylang'
54
+
55
+ require_once( plugin_dir_path( JR_MT_FILE ) . 'includes/functions.php' );
56
+
57
+ /* Check for missing Settings and set them to defaults.
58
+ On first use, this means initializing all Settings to their defaults.
59
+ */
60
+ jr_mt_missing_settings( 'jr_mt_settings',
61
+ array(
62
+ /* Settings structure:
63
+ code - get_option( 'jr_mt_settings' )
64
+ ['all_pages'] => zero length string or folder in Themes directory containing theme to use for All Pages
65
+ ['all_posts'] => zero length string or folder in Themes directory containing theme to use for All Posts
66
+ ['site_home'] => zero length string or folder in Themes directory containing theme to use for Home Page
67
+ ['current'] => zero length string or folder in Themes directory containing theme to override WordPress Current Theme
68
+ ['query']
69
+ [keyword]
70
+ [value] or ['*'] => folder in Themes directory containing theme to use
71
+ ['remember']
72
+ ['query']
73
+ [keyword]
74
+ [value] => TRUE
75
+ ['override']
76
+ ['query']
77
+ [keyword]
78
+ [value] => TRUE
79
+ ['query_present'] => TRUE or FALSE
80
+ ['url'], ['url_prefix'] and ['url_asterisk']
81
+ ['url'] => URL
82
+ ['prep'] => URL array created by jr_mt_prep_url()
83
+ ['theme'] => folder in Themes directory containing theme to use
84
+ Prior to Version 5.0:
85
+ ['ids']
86
+ [id] - zero length string or WordPress ID of Page, Post, etc.
87
+ ['type'] => 'page' or 'post' or 'admin' or 'cat' or 'archive' or 'prefix' or other
88
+ ['theme'] => folder in Themes directory containing theme to use
89
+ ['id'] => FALSE or WordPress ID of Page, Post, etc.
90
+ ['page_url'] => relative URL WordPress page, post, admin, etc. or FALSE
91
+ ['rel_url'] => URL relative to WordPress home
92
+ ['url'] => original full URL, from Settings page entry by user
93
+ */
94
+ 'all_pages' => '',
95
+ 'all_posts' => '',
96
+ 'site_home' => '',
97
+ 'current' => '',
98
+ 'query' => array(),
99
+ 'remember' => array( 'query' => array() ),
100
+ 'override' => array( 'query' => array() ),
101
+ 'query_present' => FALSE,
102
+ 'url' => array(),
103
+ 'url_prefix' => array(),
104
+ 'url_asterisk' => array()
105
+ )
106
+ );
107
+
108
+ /* Detect initial activation or a change in plugin's Version number
109
+
110
+ Sometimes special processing is required when the plugin is updated to a new version of the plugin.
111
+ Also used in place of standard activation and new site creation exits provided by WordPress.
112
+ Once that is complete, update the Version number in the plugin's Network-wide settings.
113
+ */
114
+ if ( FALSE === ( $internal_settings = get_option( 'jr_mt_internal_settings' ) ) ) {
115
+ /* New install or Plugin was deleted previously, erasing all its Settings
116
+ */
117
+ $old_version = $jr_mt_plugin_data['Version'];
118
+ $version_change = TRUE;
119
+ $update_version_setting = FALSE;
120
+ } else {
121
+ if ( empty( $internal_settings['version'] ) ) {
122
+ /* Internal Settings are corrupt, or extremely old.
123
+ */
124
+ $old_version = '0';
125
+ $version_change = TRUE;
126
+ $update_version_setting = TRUE;
127
+ } else {
128
+ $old_version = $internal_settings['version'];
129
+ $version_change = version_compare( $old_version, $jr_mt_plugin_data['Version'], '!=' );
130
+ $update_version_setting = $version_change;
131
+ }
132
+ }
133
+ /* Create and initialize any or all internal settings that do not exist.
134
+ */
135
+ jr_mt_missing_settings( 'jr_mt_internal_settings',
136
+ array(
137
+ 'version' => $jr_mt_plugin_data['Version'],
138
+ 'permalink' => get_option( 'permalink_structure' )
139
+ )
140
+ );
141
+
142
+ if ( $version_change ) {
143
+ /* Handle all Settings changes made in old plugin versions
144
+ */
145
+ if ( version_compare( $old_version, '5.0', '<' ) ) {
146
+ $settings = get_option( 'jr_mt_settings' );
147
+ if ( !empty( $settings['ids'] ) ) {
148
+ /* Convert 'ids' array to 'urls' array in Settings jr_mt_settings
149
+
150
+ Signal that a conversion is required.
151
+ */
152
+ $internal_settings = get_option( 'jr_mt_internal_settings' );
153
+ $internal_settings['ids'] = TRUE;
154
+ update_option( 'jr_mt_internal_settings', $internal_settings );
155
+ }
156
+ }
157
+ }
158
+
159
+ /* Only Update if I have to.
160
+ */
161
+ if ( $update_version_setting ) {
162
+ $internal_settings = get_option( 'jr_mt_internal_settings' );
163
+ $internal_settings['version'] = $jr_mt_plugin_data['Version'];
164
+ update_option( 'jr_mt_internal_settings', $internal_settings );
165
+ }
166
+
167
+ /* Do the Version 5.0 Upgrade, if required.
168
+ */
169
+ $internal_settings = get_option( 'jr_mt_internal_settings' );
170
+ if ( isset( $internal_settings['ids'] ) ) {
171
+ require_once( jr_mt_path() . 'includes/upgradev5.php' );
172
+ }
173
+
174
+ /* p2 runs in Admin, so must also execute this code in Admin, too.
175
+ */
176
+ require_once( jr_mt_path() . 'includes/select-theme.php' );
177
+
178
+ if ( is_admin() ) {
179
+ require_once( jr_mt_path() . 'includes/admin-functions.php' );
180
+ // Admin panel
181
+ require_once( jr_mt_path() . 'includes/admin.php' );
182
+ }
183
+ }
184
+
185
+ /*
186
+ Research Notes:
187
+ 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:
188
+ - is_admin()
189
+ - is_user_logged_in()
190
+ - get_option("page_on_front") - ID of home page; zero if Reading Settings NOT set to a Static Page of a WordPress Page
191
+ */
192
+
193
+ ?>
js/index.html ADDED
File without changes
js/sticky.js ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ window.onload =
41
+ function ( ) {
42
+ var allCookies, keywordMatch, pos, valueStart, cookieArray, query, homeUrl, siteAdmin, appendSetting, overrideQueries, overrideQueriesEmpty, hrefs, i, max, href, colonSlashSlash, hrefCompare, addQuery, posQuestionMark, posNumberSign, hrefQueries,
43
+ cookieEquals = 'jr-mt-remember-query=',
44
+ cookieSplit = '; ';
45
+
46
+ /* Check if there are any Cookies at all.
47
+ */
48
+ if ( '' !== allCookies ) {
49
+ allCookies = cookieSplit + document.cookie + cookieSplit;
50
+ keywordMatch = cookieSplit + cookieEquals;
51
+ pos = allCookies.indexOf( keywordMatch );
52
+ /* Check if our cookie is present.
53
+ */
54
+ if ( -1 !== pos ) {
55
+ valueStart = pos + keywordMatch.length;
56
+ /* Extract Value of Cookie, which is found after the equals sign and before the semicolon
57
+ */
58
+ cookieArray = JSON.parse( decodeURIComponent( allCookies.substring( pos + keywordMatch.length, allCookies.indexOf( cookieSplit, pos + cookieSplit.length ) ) ) );
59
+ /* Assign Cookie array elements to meaningfully-named variables.
60
+ */
61
+ query = cookieArray[0];
62
+ appendSetting = cookieArray[1];
63
+ overrideQueries = cookieArray[2];
64
+ overrideQueriesEmpty = ( 0 === overrideQueries.length );
65
+
66
+ homeUrl = document.getElementById( 'jr-mt-home-url' )['title'];
67
+ siteAdmin = document.getElementById( 'jr-mt-site-admin' )['title'];
68
+
69
+ hrefs = document.getElementsByTagName ( 'a' );
70
+ for ( i = 0, max = hrefs.length; i < max; i++ ) {
71
+ href = hrefs [ i ] ['href'];
72
+ colonSlashSlash = href.indexOf( '://' );
73
+ /* Ignore Relative URLs: those without ://
74
+ */
75
+ if ( -1 !== colonSlashSlash ) {
76
+ hrefCompare = href.substring( colonSlashSlash + 3 ).toLowerCase();
77
+ if ( 'www.' === hrefCompare.substring( 0, 4 ) ) {
78
+ hrefCompare = hrefCompare.substring( 4 );
79
+ }
80
+ hrefCompare = hrefCompare.replace( /\\/g, '/' );
81
+ addQuery = '';
82
+ if ( hrefCompare.substring( 0, homeUrl.length ) === homeUrl ) {
83
+ if ( hrefCompare.substring( 0, siteAdmin.length ) !== siteAdmin ) {
84
+ posQuestionMark = href.indexOf( '?' );
85
+ posNumberSign = href.indexOf( '#' );
86
+ if ( -1 === posNumberSign ) {
87
+ posNumberSign = href.length;
88
+ }
89
+ /* Only add a Query if one does not already exist.
90
+ */
91
+ if ( -1 === posQuestionMark ) {
92
+ /* Query must be before the Fragment (#anchor),
93
+ when one exists.
94
+ */
95
+ addQuery = '?';
96
+ } else {
97
+ /* Query exists because "?" found in URL.
98
+ Check if setting set to add query when one already exists.
99
+ If not, don't touch this URL.
100
+ */
101
+ if ( appendSetting ) {
102
+ addQuery = '&';
103
+ hrefQueries = href.substring( posQuestionMark + 1, posNumberSign ).split( '&' );
104
+ /* Don't append Sticky query if it is already present in the URL
105
+ */
106
+ if ( -1 !== hrefQueries.indexOf( query ) ) {
107
+ addQuery = '';
108
+ } else {
109
+ if ( !overrideQueriesEmpty ) {
110
+ for ( j = 0, hrefQueriesLength = hrefQueries.length; j < hrefQueriesLength; j++ ) {
111
+ /* Don't append Sticky query if an Override query is present in URL
112
+ */
113
+ if ( -1 !== overrideQueries.indexOf( hrefQueries[ j ].toLowerCase() ) ) {
114
+ /* Override query already in URL.
115
+ */
116
+ addQuery = '';
117
+ break;
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+ }
126
+ if ( '' !== addQuery ) {
127
+ /* No override or sticky query already in URL, so safe to add current sticky query.
128
+ */
129
+ hrefs [ i ] ['href'] = href.substring( 0, posNumberSign ) + addQuery + query + href.substring( posNumberSign );
130
+ }
131
+ }
132
+ }
133
+ }
134
+ }
135
+ };
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,397 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === jonradio Multiple Themes ===
2
+ Contributors: dgewirtz
3
+ Donate link: http://zatzlabs.com/plugins/
4
+ Tags: themes, theme, sections, style, template, stylesheet, accessibility
5
+ Requires at least: 3.4
6
+ Tested up to: 4.0
7
+ Stable tag: 5.0.2
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ Select different Themes for one or more WordPress Pages, Posts or other non-Admin pages. Or Site Home.
12
+
13
+ == Description ==
14
+
15
+ **Version 5 was a major rewrite that now supports nearly all plugins and themes, including BuddyPress.** In the unlikely situation that such a massive change introduces unforeseen issues for your site, it is possible to downgrade to Version 4.12 until the issue is resolved. [Click here](http://downloads.wordpress.org/plugin/jonradio-multiple-themes.4.12.zip "Downgrade") to download Version 4.12.
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. Plugin's Settings page
138
+
139
+ == Changelog ==
140
+
141
+ = 5.0.2 =
142
+ * Remove /downgrade/ directory in case it caused the reported PCLZIP_ERR_BAD_FORMAT errors
143
+
144
+
145
+ = 5.0.1 =
146
+ * Fix All Pages and All Posts by complete rewrite of Theme Selection logic for those Advanced Settings
147
+
148
+ = 5.0 =
149
+ * Major rewrite of the Theme Selection logic
150
+ * Tabs added to the Settings page, for easier navigation
151
+ * Greatly expanded compatibility with other Plugins and Themes
152
+ * Allow ?keyword=value&keyword=value Queries in URL, URL Prefix and URL Prefix with Asterisk ("*") Theme Selection entries
153
+ * Accurate Theme Selection even for plugins and themes that request Stylesheet or Template information before WordPress is fully loaded
154
+ * 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
155
+ * 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
156
+ * Complete How-To details on Theme Option and Template selection right on the Settings page, replacing the FAQs in the WordPress Plugin Directory
157
+ * Automatic deletion of Theme Selection entries for Themes that have been deleted
158
+ * Enhanced performance with tighter code, and less of it, on the public side of your WordPress site
159
+ * Changing Permalinks invalidates more Theme Selection settings than in previous versions
160
+ * Changing the Theme for an Entry requires Deletion of the old Entry before or after adding the same Entry with the new Theme specified
161
+ * 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.
162
+
163
+ = 4.11.3 =
164
+ * Fix Array to String Warning on some Search plugins by rewriting jt_mt_themes_defined() which creates list of Themes referenced in plugin Settings
165
+ * Add More Diagnostic Information to Settings page
166
+ * Suggest "URL Prefix" setting when "URL" setting does not work, especially for WooCommerce
167
+ * Detect Memberium plugins and explain that Sticky will not work with Membership System V2 because it blocks Cookies
168
+ * Add Warning and change one confusing Error Message when Query is incorrectly included in URL of Page/Post entry
169
+
170
+ = 4.11.2 =
171
+ * Made all Query comparisons (URL match Setting) case insensitive
172
+ * Eliminate Connection Info prompt from Settings page that occurred for certain User Permissions
173
+ * Add File Permissions table to Settings
174
+
175
+ = 4.11.1 =
176
+ * Correct foreach() error
177
+
178
+ = 4.11 =
179
+ * Complete Rewrite of Sticky logic, adding additional Settings, including Override
180
+
181
+ = 4.10.1 =
182
+ * Sticky: add a unique Query to URL so that Caching plugins will cache separate copies for each Theme used on a particular page
183
+
184
+ = 4.10 =
185
+ * 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
186
+ * Enhance performance by eliminating processing related to each Type of Setting when no Setting entries of that Type exist
187
+
188
+ = 4.9 =
189
+ * Add an Asterisk ("*") to match any Subdirectory at a given level of the File Hierarchy, as another form of the Prefix URL option
190
+ * Reorganize Settings page
191
+
192
+ = 4.8 =
193
+ * Delay intercept of get_options 'stylesheet' and 'template' until 'plugins_loaded' (NextGen Gallery conflict)
194
+ * Check for illegal characters in Keyword and Value of Query portion of URL in Settings fields
195
+
196
+ = 4.7.3 =
197
+ * Add support for dot in URL Queries (keyword or value) by replacing parse_str()
198
+ * Removed subfolder /includes/debug/
199
+
200
+ = 4.7.2 =
201
+ * Do not execute select-theme.php on Admin panels, to eliminate error message whenever any plugin is uninstalled
202
+ * Handle URL Query Keyword[]=Value
203
+ * Add Polylang to list of incompatible plugins
204
+
205
+ = 4.7.1 =
206
+ * Handle PHP without mbstring extension
207
+
208
+ = 4.7 =
209
+ * Add option to select a Theme based on Query Keyword and Value pair in URL
210
+ * Redesign how Query entries are stored
211
+ * Full testing completed with WordPress Version 3.8
212
+
213
+ = 4.6 =
214
+ * Add option to select a Theme based on Query Keyword in URL
215
+ * Rearrange Settings page
216
+
217
+ = 4.5.2 =
218
+ * Eliminate Fatal Error if php zip_open() function is not available, when readme.txt is out of date
219
+
220
+ = 4.5.1 =
221
+ * Remove %E2%80%8E suffix from URLs being entered
222
+
223
+ = 4.5 =
224
+ * Check with get_page_by_path() and get_posts( array( 'name' => $page_url ) ) if url_to_postid() fails to find URL input
225
+
226
+ = 4.4 =
227
+ * 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
228
+ * Prevent Fatal Error for Versions of WordPress before 3.4, and Deactivate Plugin instead, because plugin requires at least 3.4 to function
229
+ * Security: require "switch_themes" Capability rather than "manage_options" Capability to access plugin's Settings page
230
+
231
+ = 4.3 =
232
+ * Add SSL support so that visitors can view the WordPress site with https:// URLs and Site URL can be https://
233
+
234
+ = 4.2 =
235
+ * Add option to override WordPress Current Theme
236
+ * Security enhancements to eliminate direct execution of .php files
237
+
238
+ = 4.1.1 =
239
+ * Handle situations where readme.txt file in plugin's directory cannot be read or written
240
+
241
+ = 4.1 =
242
+ * Support for non-alphanumeric characters in URLs, e.g. - languages using characters not in the English alphabet
243
+ * Support for Live Search feature of KnowHow Theme
244
+ * Display errors, not settings, on plugin's Admin page for activated BuddyPress or Theme Test Drive plugins, or old versions of WordPress
245
+ * Add error checking/messages and diagnostic information to plugin's Admin page
246
+
247
+ = 4.0.2 =
248
+ * Prevent Warning and Notice by initializing global $wp
249
+
250
+ = 4.0.1 =
251
+ * Prevent Fatal Error by initializing global $wp_rewrite
252
+
253
+ = 4 =
254
+ * Discovered url_to_postid() function, to address situations where Slug differed from Permalink, such as Posts with Year/Month folders
255
+
256
+ = 3.3.1 =
257
+ * Fix White Screen of Death on a Page selected by plugin
258
+
259
+ = 3.3 =
260
+ * Support Child Themes and any other situation where stylesheet and template names are not the same
261
+
262
+ = 3.2 =
263
+ * Correct Problem with P2 Theme, and its logged on verification at wp-admin/admin-ajax.php?p2ajax=true&action=logged_in_out&_loggedin={nonce}
264
+ * Add "Settings Saved" message to Admin page
265
+ * Tested with WordPress Version 3.5 beta
266
+
267
+ = 3.1 =
268
+ * Add Support for Prefixes, where all URLs beginning with the specified characters ("Prefix") can be assigned to a specified Theme
269
+
270
+ = 3.0 =
271
+ * Add Support for Categories and Archives when no Permalinks exist (support already existed Categories and Archives with Permalinks)
272
+ * Resolve several minor bugs
273
+
274
+ = 2.9 =
275
+ * Rewrite much of the Settings page and Plugin Directory documentation
276
+ * Add Support for IIS which returns incorrect values in $_SERVER['REQUEST_URI']
277
+ * Make it easier to select the Theme for the Site Home by providing a new Settings field
278
+ * 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
279
+ * Add version upgrade detection to add, remove and update Settings fields
280
+ * Move Settings link on Plugins page from beginning to end of links
281
+
282
+ = 2.0 =
283
+ * Address pecularities of wp_make_link_relative() related to root-based WordPress sites using Permalinks
284
+
285
+ = 1.1 =
286
+ * Fix foreach failing on some systems, based on PHP warning level
287
+
288
+ = 1.0 =
289
+ * Make plugin conform to WordPress plugin repository standards.
290
+ * Beta testing completed.
291
+
292
+ == Upgrade Notice ==
293
+
294
+ = 5.0.2 =
295
+ Remove /downgrade/ directory that may have caused PCLZIP_ERR_BAD_FORMAT errors on some web hosts
296
+
297
+ = 5.0.1 =
298
+ Correct All Pages and All Posts (Advanced) Setting bug
299
+
300
+ = 5.0 =
301
+ Greatly expanded compatibility with other Plugins and Themes
302
+
303
+ = 4.11.2 =
304
+ Standardize to case insensitive Query comparisons and eliminate Connection Info prompt on Settings page
305
+
306
+ = 4.11.1 =
307
+ Fix foreach() error
308
+
309
+ = 4.11 =
310
+ Complete rewrite of Sticky logic
311
+
312
+ = 4.10.1 =
313
+ Make Sticky work with Caching plugins
314
+
315
+ = 4.10 =
316
+ Performance improvements and add Sticky Queries
317
+
318
+ = 4.9 =
319
+ Allow Prefix URLs to match all subdirectories with an Asterisk ("*")
320
+
321
+ = 4.8 =
322
+ Compatibility with NextGen Gallery plugin
323
+
324
+ = 4.7.3 =
325
+ Allow dots in URL Queries
326
+
327
+ = 4.7.2 =
328
+ Avoid Error Message during Uninstall of other Plugins
329
+
330
+ = 4.7.1 =
331
+ Avoid mb_ function errors for PHP without mbstring extension
332
+
333
+ = 4.7 =
334
+ Select Theme by Query Keyword/Value pair in URL
335
+
336
+ = 4.6 =
337
+ Select Theme by Query Keyword in URL
338
+
339
+ = 4.5.2 =
340
+ Fix zip_open Fatal Error
341
+
342
+ = 4.5.1 =
343
+ Fix %E2%80%8E suffix problem on input URLs
344
+
345
+ = 4.5 =
346
+ Handle URL input for non-standard Pages and Posts
347
+
348
+ = 4.4 =
349
+ Fix errors when new Network site created or old WordPress version used, and correct Setting page Permissions to "switch_themes"
350
+
351
+ = 4.3 =
352
+ Add SSL support for sites with https:// URLs
353
+
354
+ = 4.2 =
355
+ Add "Select Theme for Everything" feature and improve security
356
+
357
+ = 4.1.1 =
358
+ Resolve issues with readme.txt permissions introduced in Version 4.1's compatibility checking
359
+
360
+ = 4.1 =
361
+ Support non-English alphabet in URLs and Live Search feature in KnowHow Theme
362
+
363
+ = 4.0.2 =
364
+ Fix "Warning: in_array() expects parameter 2 to be array, null given in domain.com/wp-includes/rewrite.php on line 364"
365
+
366
+ = 4.0.1 =
367
+ 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"
368
+
369
+ = 4 =
370
+ Fix Posts not working in some Permalink setups, most notably Year/Month
371
+
372
+ = 3.3.1 =
373
+ Fix White Screen of Death on a Page, Post or other element selected by plugin
374
+
375
+ = 3.3 =
376
+ Remove Restriction that Stylesheet Name must match Template Name, which it does not with Child Themes
377
+
378
+ = 3.2 =
379
+ Add Support for P2 Theme and provide "Settings Saved" message
380
+
381
+ = 3.1 =
382
+ Allow Prefix URLs to be used to specify where a Theme will be displayed
383
+
384
+ = 3.0 =
385
+ Improve support for Categories and Archives, and eliminate all known bugs.
386
+
387
+ = 2.9 =
388
+ Improve Settings fields, correct display of wrong Current Theme in Appearance-Themes Admin panel, and add IIS Support.
389
+
390
+ = 2.0 =
391
+ Selecting Individual Pages and Posts on a WordPress site installed in the root and using Permalinks now works correctly.
392
+
393
+ = 1.1 =
394
+ Eliminate possibility of foreach error message if PHP warning level is set at a high level
395
+
396
+ = 1.0 =
397
+ 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
+ ?>