Version Description
- Correct Problem with P2 Theme, and its logged on verification at wp-admin/admin-ajax.php?p2ajax=true&action=logged_in_out&_loggedin={nonce}
- Add "Settings Saved" message to Admin page
- Tested with WordPress Version 3.5 beta
Download this release
Release Info
Developer | dgewirtz |
Plugin | Multiple Themes |
Version | 3.2 |
Comparing to | |
See all releases |
Version 3.2
- includes/admin.php +391 -0
- includes/debug/debug.php +36 -0
- includes/functions.php +157 -0
- includes/select-theme.php +108 -0
- jonradio-multiple-themes.php +178 -0
- readme.txt +144 -0
- uninstall.php +18 -0
includes/admin.php
ADDED
@@ -0,0 +1,391 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Admin Page
|
3 |
+
|
4 |
+
add_action( 'admin_menu', 'jr_mt_admin_hook' );
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Add Admin Menu item for plugin
|
8 |
+
*
|
9 |
+
* Plugin needs its own Page in the Settings section of the Admin menu.
|
10 |
+
*
|
11 |
+
*/
|
12 |
+
function jr_mt_admin_hook() {
|
13 |
+
// Add Settings Page for this Plugin
|
14 |
+
add_theme_page( 'jonradio Multiple Themes', 'Multiple Themes plugin', 'manage_options', 'jr_mt_settings', 'jr_mt_settings_page' );
|
15 |
+
add_options_page( 'jonradio Multiple Themes', 'Multiple Themes plugin', 'manage_options', 'jr_mt_settings', 'jr_mt_settings_page' );
|
16 |
+
}
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Settings page for plugin
|
20 |
+
*
|
21 |
+
* Display and Process Settings page for this plugin.
|
22 |
+
*
|
23 |
+
*/
|
24 |
+
function jr_mt_settings_page() {
|
25 |
+
echo '<div class="wrap">';
|
26 |
+
screen_icon( 'plugins' );
|
27 |
+
echo '<h2>jonradio Multiple Themes</h2>';
|
28 |
+
|
29 |
+
// Required because it is only called automatically for Admin Pages in the Settings section
|
30 |
+
settings_errors( 'jr_mt_settings' );
|
31 |
+
|
32 |
+
$theme = wp_get_theme()->Name;
|
33 |
+
global $jr_mt_options_cache;
|
34 |
+
if ( $jr_mt_options_cache['template'] == $jr_mt_options_cache['stylesheet'] ) {
|
35 |
+
?>
|
36 |
+
<p>This plugin allows you to selectively change the Theme you have selected as your <b>Current Theme</b> in <b>Appearance-Themes</b> on the Admin panels.
|
37 |
+
You can choose from any of the <b>Available Themes</b> listed on the Appearance-Themes Admin panel for:
|
38 |
+
<ul>
|
39 |
+
<li> » All Pages</li>
|
40 |
+
<li> » All Posts</li>
|
41 |
+
<li> » The Site Home</li>
|
42 |
+
<li> » A Specific Page</li>
|
43 |
+
<li> » A Specific Post</li>
|
44 |
+
<li> » Any other non-Admin page that has its own Permalink; for example, a specific Archive or Category page</li>
|
45 |
+
</ul>
|
46 |
+
<?php
|
47 |
+
if ( function_exists('is_multisite') && is_multisite() ) {
|
48 |
+
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.";
|
49 |
+
}
|
50 |
+
echo '</p>';
|
51 |
+
echo '<p>';
|
52 |
+
echo "The Current Theme is <b>$theme</b>. You will not normally need to specify it in any of the Settings on this page. The only exception would be if you specify a different Theme for All Pages or All Posts and wish to use the Current Theme for a specific Page, Post or other non-Admin page.";
|
53 |
+
echo '</p>';
|
54 |
+
echo '<form action="options.php" method="POST">';
|
55 |
+
|
56 |
+
// Plugin Settings are displayed and entered here:
|
57 |
+
settings_fields( 'jr_mt_settings' );
|
58 |
+
do_settings_sections( 'jr_mt_settings_page' );
|
59 |
+
echo '<p><input name="save" type="submit" value="Save Changes" class="button-primary" /></p></form>';
|
60 |
+
} else {
|
61 |
+
echo '<p>Please report this problem to the Plugin Author:<br />';
|
62 |
+
echo "Stylesheet and Template names do not match for Theme $theme: " . $jr_mt_options_cache['stylesheet'] . ' v.s. ' . $jr_mt_options_cache['template'];
|
63 |
+
global $jr_mt_plugin_data;
|
64 |
+
echo '</p><p><a href="' . $jr_mt_plugin_data['AuthorURI'] . '"' . ">Click here</a> to get to The Plugin Author's page where you can click Contact Us in the menu bar.</p>";
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
add_action( 'admin_init', 'jr_mt_admin_init' );
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Register and define the settings
|
72 |
+
*
|
73 |
+
* Everything to be stored and/or can be set by the user
|
74 |
+
*
|
75 |
+
*/
|
76 |
+
function jr_mt_admin_init() {
|
77 |
+
register_setting( 'jr_mt_settings', 'jr_mt_settings', 'jr_mt_validate_settings' );
|
78 |
+
add_settings_section( 'jr_mt_all_settings_section',
|
79 |
+
'For All Pages, All Posts and/or Site Home',
|
80 |
+
'jr_mt_all_settings_expl',
|
81 |
+
'jr_mt_settings_page'
|
82 |
+
);
|
83 |
+
$suffix = array(
|
84 |
+
'Pages' => '<br />(Pages created with Add Page)',
|
85 |
+
'Posts' => ''
|
86 |
+
);
|
87 |
+
foreach ( array( 'Pages', 'Posts' ) as $thing ) {
|
88 |
+
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',
|
89 |
+
array( 'thing' => $thing ) );
|
90 |
+
}
|
91 |
+
add_settings_field( 'site_home',
|
92 |
+
'Select Theme for Site Home<br />(' . get_home_url() . ')',
|
93 |
+
'jr_mt_echo_site_home',
|
94 |
+
'jr_mt_settings_page',
|
95 |
+
'jr_mt_all_settings_section'
|
96 |
+
);
|
97 |
+
$settings = get_option( 'jr_mt_settings' );
|
98 |
+
$ids = $settings['ids'];
|
99 |
+
if ( !empty( $ids) ) {
|
100 |
+
add_settings_section( 'jr_mt_delete_settings_section',
|
101 |
+
'To Display or Delete Theme Selections for Individual Pages or Posts',
|
102 |
+
'jr_mt_delete_settings_expl',
|
103 |
+
'jr_mt_settings_page'
|
104 |
+
);
|
105 |
+
add_settings_field( 'del_entry', 'Entries:', 'jr_mt_echo_delete_entry', 'jr_mt_settings_page', 'jr_mt_delete_settings_section' );
|
106 |
+
}
|
107 |
+
add_settings_section( 'jr_mt_single_settings_section',
|
108 |
+
'For An Individual Page, Post or other non-Admin page',
|
109 |
+
'jr_mt_single_settings_expl',
|
110 |
+
'jr_mt_settings_page'
|
111 |
+
);
|
112 |
+
add_settings_field( 'add_theme', 'Theme', 'jr_mt_echo_add_theme', 'jr_mt_settings_page', 'jr_mt_single_settings_section' );
|
113 |
+
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' );
|
114 |
+
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' );
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* Section text for Section1
|
119 |
+
*
|
120 |
+
* Display an explanation of this Section
|
121 |
+
*
|
122 |
+
*/
|
123 |
+
function jr_mt_all_settings_expl() {
|
124 |
+
?>
|
125 |
+
<p>
|
126 |
+
In this section, you can select a different Theme for All Pages, All Posts and/or Site Home.
|
127 |
+
To remove a previously selected Theme, select the blank entry from the drop-down list.
|
128 |
+
</p>
|
129 |
+
<p>
|
130 |
+
In the <i>next</i> section, you will be able to select a Theme, including the Current Theme, to override any choice you make here, for individual Pages, Posts or
|
131 |
+
any other non-Admin pages that have their own Permalink; for example, specific Archive or Category pages.
|
132 |
+
</p>
|
133 |
+
<?php
|
134 |
+
}
|
135 |
+
|
136 |
+
function jr_mt_echo_all_things( $thing ) {
|
137 |
+
$settings = get_option( 'jr_mt_settings' );
|
138 |
+
$field = 'all_' . strtolower( $thing['thing'] );
|
139 |
+
jr_mt_themes_field( $field, $settings[$field], 'jr_mt_settings', TRUE );
|
140 |
+
}
|
141 |
+
|
142 |
+
function jr_mt_echo_site_home() {
|
143 |
+
$settings = get_option( 'jr_mt_settings' );
|
144 |
+
jr_mt_themes_field( 'site_home', $settings['site_home'], 'jr_mt_settings', FALSE );
|
145 |
+
}
|
146 |
+
|
147 |
+
/**
|
148 |
+
* Section text for Section2
|
149 |
+
*
|
150 |
+
* Display an explanation of this Section
|
151 |
+
*
|
152 |
+
*/
|
153 |
+
function jr_mt_delete_settings_expl() {
|
154 |
+
?>
|
155 |
+
<p>
|
156 |
+
In this section, all entries are displayed for Themes selected for individual Pages, Posts
|
157 |
+
and any other non-Admin pages that have their own Permalink; for example, specific Archive or Category pages.
|
158 |
+
</p>
|
159 |
+
<p>
|
160 |
+
You can delete any of these entries by filling in the check box beside each one.
|
161 |
+
To change the Theme for an entry, add the same entry with a different Theme in the section below this one.</p>
|
162 |
+
<?php
|
163 |
+
}
|
164 |
+
|
165 |
+
function jr_mt_echo_delete_entry() {
|
166 |
+
$entry_num = 0;
|
167 |
+
$settings = get_option( 'jr_mt_settings' );
|
168 |
+
foreach ( $settings['ids'] as $path_id => $opt_array ) {
|
169 |
+
++$entry_num;
|
170 |
+
echo "Delete <input type='checkbox' id='del_entry' name='jr_mt_settings[del_entry][]' value='$path_id' /> Theme="
|
171 |
+
. wp_get_theme( $opt_array['theme'] )->Name . '; ';
|
172 |
+
if ( $path_id == '' ) {
|
173 |
+
echo 'Site=<a href="' . get_home_url() . '" target="_blank">Home</a>';
|
174 |
+
} else {
|
175 |
+
if ( $opt_array['type'] == 'prefix' ) {
|
176 |
+
echo 'Prefix=<a href="' . get_home_url() . "/$path_id" . '" target="_blank">' . "$path_id</a>";
|
177 |
+
} else {
|
178 |
+
if ( $opt_array['type'] == 'cat' ) {
|
179 |
+
echo 'Category=<a href="' . get_home_url() . '/?cat=' . $opt_array['id'] . '" target="_blank">' . get_cat_name( $opt_array['id'] ) . '</a>';
|
180 |
+
} else {
|
181 |
+
if ( $opt_array['type'] == 'archive' ) {
|
182 |
+
echo 'Archive=<a href="' . get_home_url() . '/?m=' . $opt_array['id'] . '" target="_blank">' . $opt_array['id'] . '</a>';
|
183 |
+
} else {
|
184 |
+
$p_array = get_posts( array( 'post_type' => 'any', 'include' => array( $path_id ) ) );
|
185 |
+
if ( empty( $p_array ) ) {
|
186 |
+
if ( $opt_array['type'] == 'admin' ) {
|
187 |
+
echo 'Admin=<a href="' . get_home_url() . '/' . $opt_array['rel_url'] . '" target="_blank">' . "$path_id</a>";
|
188 |
+
} else {
|
189 |
+
echo 'Path=<a href="' . get_home_url() . "/$path_id" . '" target="_blank">' . "$path_id</a>";
|
190 |
+
}
|
191 |
+
} else {
|
192 |
+
echo ucfirst( $p_array[0]->post_type ) . '=<a href="' . get_permalink( $path_id ) . '" target="_blank">' . $p_array[0]->post_title . '</a>';
|
193 |
+
}
|
194 |
+
}
|
195 |
+
}
|
196 |
+
}
|
197 |
+
}
|
198 |
+
echo '<br />';
|
199 |
+
}
|
200 |
+
}
|
201 |
+
|
202 |
+
/**
|
203 |
+
* Section text for Section3
|
204 |
+
*
|
205 |
+
* Display an explanation of this Section
|
206 |
+
*
|
207 |
+
*/
|
208 |
+
function jr_mt_single_settings_expl() {
|
209 |
+
?>
|
210 |
+
<p>
|
211 |
+
Select a Theme for an individual Page, Post or
|
212 |
+
any other non-Admin pages that has its own Permalink; for example, a specific Archive or Category page.
|
213 |
+
<p>
|
214 |
+
</p>
|
215 |
+
Then cut and paste the URL of the desired Page, Post or other non-Admin page.
|
216 |
+
And click the <b>Save Changes</b> button to add the entry.
|
217 |
+
</p>
|
218 |
+
<?php
|
219 |
+
}
|
220 |
+
|
221 |
+
function jr_mt_echo_add_theme() {
|
222 |
+
jr_mt_themes_field( 'add_theme', '', 'jr_mt_settings', FALSE );
|
223 |
+
}
|
224 |
+
|
225 |
+
function jr_mt_echo_add_path_id() {
|
226 |
+
?>
|
227 |
+
<input id="add_path_id" name="jr_mt_settings[add_path_id]" type="text" size="100" maxlength="256" value="" />
|
228 |
+
<br />
|
229 |
+
(cut and paste URL here of Page, Post, Prefix or other)
|
230 |
+
<br />
|
231 |
+
URL must begin with
|
232 |
+
<?php
|
233 |
+
echo trim( get_home_url(), '\ /' ) . '/';
|
234 |
+
}
|
235 |
+
|
236 |
+
function jr_mt_echo_add_is_prefix() {
|
237 |
+
?>
|
238 |
+
<input type="checkbox" id="add_is_prefix" name="jr_mt_settings[add_is_prefix]" value="true" /> Anything that begins with this URL will use this Theme
|
239 |
+
<?php
|
240 |
+
}
|
241 |
+
|
242 |
+
function jr_mt_validate_settings( $input ) {
|
243 |
+
$valid = array();
|
244 |
+
foreach ( array( 'all_pages', 'all_posts', 'site_home' ) as $thing ) {
|
245 |
+
$valid[$thing] = $input[$thing];
|
246 |
+
}
|
247 |
+
|
248 |
+
$settings = get_option( 'jr_mt_settings' );
|
249 |
+
$ids = $settings['ids'];
|
250 |
+
if ( isset ( $input['del_entry'] ) ) {
|
251 |
+
foreach ( $input['del_entry'] as $del_entry ) {
|
252 |
+
unset( $ids[$del_entry] );
|
253 |
+
}
|
254 |
+
}
|
255 |
+
|
256 |
+
$url = trim( $input['add_path_id'] );
|
257 |
+
if ( ( empty( $input['add_theme'] ) && !empty( $url ) ) || ( !empty( $input['add_theme'] ) && empty( $url ) ) ) {
|
258 |
+
add_settings_error(
|
259 |
+
'jr_mt_settings',
|
260 |
+
'jr_mt_emptyerror',
|
261 |
+
'Both URL and Theme must be specified to add an Individual entry',
|
262 |
+
'error'
|
263 |
+
);
|
264 |
+
} else {
|
265 |
+
if ( !empty( $url ) ) {
|
266 |
+
$validate_url = jr_mt_site_url( $url );
|
267 |
+
if ( $validate_url === TRUE ) {
|
268 |
+
extract( jr_mt_url_to_id( $url ) );
|
269 |
+
if ( isset ( $input['add_is_prefix'] ) && ( $input['add_is_prefix'] == "true" ) ) {
|
270 |
+
if ( parse_url( $url, PHP_URL_QUERY ) === NULL ) {
|
271 |
+
$ids[$rel_url] = array(
|
272 |
+
'theme' => $input['add_theme'],
|
273 |
+
'type' => 'prefix',
|
274 |
+
'id' => $id,
|
275 |
+
'page_url' => $page_url,
|
276 |
+
'rel_url' => $rel_url,
|
277 |
+
'url' => $url
|
278 |
+
);
|
279 |
+
} else {
|
280 |
+
add_settings_error(
|
281 |
+
'jr_mt_settings',
|
282 |
+
'jr_mt_queryerror',
|
283 |
+
'?key=val&key=val Queries are not supported in a URL Prefix',
|
284 |
+
'error'
|
285 |
+
);
|
286 |
+
|
287 |
+
}
|
288 |
+
} else {
|
289 |
+
if ( $home ) {
|
290 |
+
add_settings_error(
|
291 |
+
'jr_mt_settings',
|
292 |
+
'jr_mt_homeerror',
|
293 |
+
'Please use "Select Theme for Site Home" field instead of specifying Site Home URL as an individual entry.',
|
294 |
+
'error'
|
295 |
+
);
|
296 |
+
} else {
|
297 |
+
if ( $type == 'admin' ) {
|
298 |
+
add_settings_error(
|
299 |
+
'jr_mt_settings',
|
300 |
+
'jr_mt_adminerror',
|
301 |
+
'Admin Page URLs are not allowed because no known Themes alter the appearance of Admin pages.',
|
302 |
+
'error'
|
303 |
+
);
|
304 |
+
} else {
|
305 |
+
if ( $id === FALSE ) {
|
306 |
+
$key = $page_url;
|
307 |
+
} else {
|
308 |
+
$key = $id;
|
309 |
+
}
|
310 |
+
$ids[$key] = array(
|
311 |
+
'theme' => $input['add_theme'],
|
312 |
+
'type' => $type,
|
313 |
+
'id' => $id,
|
314 |
+
'page_url' => $page_url,
|
315 |
+
'rel_url' => $rel_url,
|
316 |
+
'url' => $url
|
317 |
+
);
|
318 |
+
}
|
319 |
+
}
|
320 |
+
}
|
321 |
+
} else {
|
322 |
+
add_settings_error(
|
323 |
+
'jr_mt_settings',
|
324 |
+
'jr_mt_urlerror',
|
325 |
+
"Invalid URL specified for Individual page/post: '$url'. $validate_url",
|
326 |
+
'error'
|
327 |
+
);
|
328 |
+
}
|
329 |
+
}
|
330 |
+
}
|
331 |
+
$errors = get_settings_errors();
|
332 |
+
if ( empty( $errors ) ) {
|
333 |
+
add_settings_error(
|
334 |
+
'jr_mt_settings',
|
335 |
+
'jr_mt_saved',
|
336 |
+
'Settings Saved',
|
337 |
+
'updated'
|
338 |
+
);
|
339 |
+
}
|
340 |
+
$valid['ids'] = $ids;
|
341 |
+
return $valid;
|
342 |
+
}
|
343 |
+
|
344 |
+
// Add Link to the plugin's entry on the Admin "Plugins" Page, for easy access
|
345 |
+
global $jr_mt_plugin_basename;
|
346 |
+
add_filter( "plugin_action_links_$jr_mt_plugin_basename", 'jr_mt_plugin_action_links', 10, 1 );
|
347 |
+
|
348 |
+
/**
|
349 |
+
* Creates Settings entry right on the Plugins Page entry.
|
350 |
+
*
|
351 |
+
* Helps the user understand where to go immediately upon Activation of the Plugin
|
352 |
+
* by creating entries on the Plugins page, right beside Deactivate and Edit.
|
353 |
+
*
|
354 |
+
* @param array $links Existing links for our Plugin, supplied by WordPress
|
355 |
+
* @param string $file Name of Plugin currently being processed
|
356 |
+
* @return string $links Updated set of links for our Plugin
|
357 |
+
*/
|
358 |
+
function jr_mt_plugin_action_links( $links ) {
|
359 |
+
// The "page=" query string value must be equal to the slug
|
360 |
+
// of the Settings admin page.
|
361 |
+
array_push( $links, '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=jr_mt_settings' . '">Settings</a>' );
|
362 |
+
return $links;
|
363 |
+
}
|
364 |
+
|
365 |
+
function jr_mt_themes_field( $field_name, $theme_name, $setting, $excl_current_theme ) {
|
366 |
+
echo "<select id='$field_name' name='$setting" . "[$field_name]' size='1'>";
|
367 |
+
if ( empty( $theme_name ) ) {
|
368 |
+
$selected = 'selected="selected"';
|
369 |
+
} else {
|
370 |
+
$selected = '';
|
371 |
+
}
|
372 |
+
echo "<option value='' $selected></option>";
|
373 |
+
foreach ( wp_get_themes() as $folder => $theme_obj ) {
|
374 |
+
if ( $excl_current_theme ) {
|
375 |
+
if ( jr_mt_current_theme() == $folder ) {
|
376 |
+
// Skip the Current Theme
|
377 |
+
continue;
|
378 |
+
}
|
379 |
+
}
|
380 |
+
if ( $theme_name == $folder ) {
|
381 |
+
$selected = 'selected="selected"';
|
382 |
+
} else {
|
383 |
+
$selected = '';
|
384 |
+
}
|
385 |
+
$name = $theme_obj->Name;
|
386 |
+
echo "<option value='$folder' $selected>$name</option>";
|
387 |
+
}
|
388 |
+
echo '</select>' . PHP_EOL;
|
389 |
+
}
|
390 |
+
|
391 |
+
?>
|
includes/debug/debug.php
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/* require_once( jr_mt_path() . 'includes/debug/debug.php' );
|
3 |
+
jr_dump( 'jr_mt_validate_settings $input', $input );
|
4 |
+
*/
|
5 |
+
|
6 |
+
function jr_dump( $comment, $dump_var ) {
|
7 |
+
$file_name = 'jonradio-dump.txt';
|
8 |
+
|
9 |
+
$header = '***' . current_time('mysql') . ': ' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
|
10 |
+
ob_start();;
|
11 |
+
echo "$comment: ";
|
12 |
+
var_dump( $dump_var );
|
13 |
+
$output = ob_get_clean() . jr_dump_env();
|
14 |
+
if ( function_exists('is_multisite') && is_multisite() ) {
|
15 |
+
global $site_id, $blog_id;
|
16 |
+
$file_name = $site_id . '-' . $blog_id . '-' . $file_name;
|
17 |
+
}
|
18 |
+
$file = fopen( plugin_dir_path( __FILE__ ) . $file_name, 'at' );
|
19 |
+
fwrite( $file, $header . PHP_EOL . $output );
|
20 |
+
fclose( $file );
|
21 |
+
|
22 |
+
return;
|
23 |
+
}
|
24 |
+
|
25 |
+
function jr_dump_env() {
|
26 |
+
global $jr_dump_env_first;
|
27 |
+
if ( isset( $jr_dump_env_first ) ) {
|
28 |
+
$output = '';
|
29 |
+
} else {
|
30 |
+
$jr_dump_env_first = FALSE;
|
31 |
+
$output = PHP_EOL;
|
32 |
+
|
33 |
+
}
|
34 |
+
return $output;
|
35 |
+
}
|
36 |
+
?>
|
includes/functions.php
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Return WordPress Current Theme, as defined in Appearance Admin panels
|
4 |
+
*
|
5 |
+
* Obtains Folder Name of Current Theme, from 'template' option of wp_load_alloptions().
|
6 |
+
*
|
7 |
+
* @param string $option optional parameter that is not currently used,
|
8 |
+
* but may in the future select current template or stylesheet
|
9 |
+
* @return string type Folder Name of Current Theme
|
10 |
+
*/
|
11 |
+
function jr_mt_current_theme( $option='stylesheet' ) {
|
12 |
+
global $jr_mt_options_cache;
|
13 |
+
return $jr_mt_options_cache[$option];
|
14 |
+
}
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Given URL, return post or page ID, if possible, and relative path if not
|
18 |
+
*
|
19 |
+
* Calls jr_mt_query_keywords.
|
20 |
+
*
|
21 |
+
* @param string $url full URL of WordPress page, post, admin, etc.
|
22 |
+
* @return array array with keys of "type", "id" and "page_url":
|
23 |
+
* string type "pages", "posts" or "admin"
|
24 |
+
* string id Page ID or Post ID or FALSE
|
25 |
+
* string page_url relative URL WordPress page, post, admin, etc. or FALSE
|
26 |
+
* string rel_url URL relative to WordPress home
|
27 |
+
* bool home is URL Site Home?
|
28 |
+
*/
|
29 |
+
function jr_mt_url_to_id( $url_orig ) {
|
30 |
+
// Some hosts, likely only IIS, insert an erroneous "/index.php" into the middle of the Permalink in $_SERVER['REQUEST_URI']
|
31 |
+
$url = str_replace( '/index.php', '', $url_orig );
|
32 |
+
|
33 |
+
$trim = '\ /'; // remove leading and trailing backslashes, blanks and forward slashes
|
34 |
+
|
35 |
+
$is_home = FALSE;
|
36 |
+
|
37 |
+
// get_home_url() returns "https://subdomain.domain.com/wp" - the full URL of the home page of the site
|
38 |
+
$home = trim( parse_url( get_home_url(), PHP_URL_PATH ), $trim ); // "wp"
|
39 |
+
|
40 |
+
$admin_home = trim( parse_url( admin_url(), PHP_URL_PATH ), $trim );
|
41 |
+
$page_url = trim( parse_url( $url, PHP_URL_PATH ), $trim ); // "wp/fruit/apples"
|
42 |
+
$is_admin = ( $admin_home == substr( $page_url, 0, strlen( $admin_home ) ) );
|
43 |
+
if ( !empty( $home ) ) { // Only if WordPress is installed in a subfolder, NOT in the Root
|
44 |
+
$page_url = trim( substr( $page_url, stripos( $page_url, $home ) + strlen( $home ) ), $trim ); // "fruit/apples"
|
45 |
+
}
|
46 |
+
$rel_url = $page_url;
|
47 |
+
|
48 |
+
$type = FALSE;
|
49 |
+
|
50 |
+
$id = jr_mt_query_keywords( parse_url( $url, PHP_URL_QUERY ) );
|
51 |
+
if ( $id === NULL ) {
|
52 |
+
if ( $is_admin ) {
|
53 |
+
$id = FALSE;
|
54 |
+
$type = 'admin';
|
55 |
+
} else {
|
56 |
+
// Check for home page (get_page_by_path() does not work for home page)
|
57 |
+
if ( empty( $page_url ) ) {
|
58 |
+
$is_home = TRUE;
|
59 |
+
$id = get_option('page_on_front');
|
60 |
+
if ( $id == 0 ) {
|
61 |
+
// There is no home Page; posts are displayed instead on the home page
|
62 |
+
$page_url = '';
|
63 |
+
$id = FALSE;
|
64 |
+
} else {
|
65 |
+
$type = 'pages';
|
66 |
+
}
|
67 |
+
} else {
|
68 |
+
$page = get_page_by_path( $page_url );
|
69 |
+
if ( $page === NULL ) {
|
70 |
+
// get_page_by_path() returns NULL for Posts, Home Page, Admin, etc.
|
71 |
+
// So, check for Posts:
|
72 |
+
$post = get_posts( array( 'name' => $page_url ) );
|
73 |
+
if ( empty( $post ) ) {
|
74 |
+
$id = FALSE;
|
75 |
+
} else {
|
76 |
+
$id = $post[0]->ID;
|
77 |
+
$type = 'posts';
|
78 |
+
}
|
79 |
+
} else {
|
80 |
+
$id = $page->ID;
|
81 |
+
$type = 'pages';
|
82 |
+
}
|
83 |
+
}
|
84 |
+
}
|
85 |
+
} else {
|
86 |
+
// id in query of URL (?keyword=value&keyword=value)
|
87 |
+
$type = key( $id );
|
88 |
+
$id = $id[$type];
|
89 |
+
$page_url = FALSE;
|
90 |
+
}
|
91 |
+
return array(
|
92 |
+
'type' => $type,
|
93 |
+
'id' => $id,
|
94 |
+
'page_url' => $page_url,
|
95 |
+
'rel_url' => $rel_url,
|
96 |
+
'home' => $is_home
|
97 |
+
);
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Return page_id= or p= (post ID) or page= (admin page) value from a URL
|
102 |
+
*
|
103 |
+
* Calls parse_str function in its own variable space because it could create virtually any variable name!
|
104 |
+
* Only looks at page_id=, p= and page= now, but could be expanded to other query keywords.
|
105 |
+
*
|
106 |
+
* @param string $url_query Query portion (after the ?) in a URL
|
107 |
+
* @return var array with key of "pages", "posts" or "admin" and value of page_id=, p= or page=, respectively; or NULL if none are present
|
108 |
+
*/
|
109 |
+
function jr_mt_query_keywords( $url_query ) {
|
110 |
+
if ( $url_query === NULL ) {
|
111 |
+
return NULL;
|
112 |
+
} else {
|
113 |
+
parse_str( $url_query );
|
114 |
+
if ( isset( $page_id ) ) {
|
115 |
+
return array( 'pages' => $page_id );
|
116 |
+
} else {
|
117 |
+
if ( isset( $p ) ) {
|
118 |
+
return array( 'posts' => $p );
|
119 |
+
} else {
|
120 |
+
if ( isset( $page ) ) {
|
121 |
+
return array( 'admin' => $page );
|
122 |
+
} else {
|
123 |
+
if ( isset( $cat ) ) {
|
124 |
+
return array( 'cat' => $cat );
|
125 |
+
} else {
|
126 |
+
if ( isset( $m ) ) {
|
127 |
+
return array( 'archive' => $m );
|
128 |
+
} else {
|
129 |
+
return NULL;
|
130 |
+
}
|
131 |
+
}
|
132 |
+
}
|
133 |
+
}
|
134 |
+
}
|
135 |
+
}
|
136 |
+
}
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Is the URL on the current WordPress web site?
|
140 |
+
*
|
141 |
+
* Checks if URL begins with Site Home URL.
|
142 |
+
*
|
143 |
+
* @param string $url URL to be checked to be sure it is "on" the current WordPress web site
|
144 |
+
* @return var bool TRUE if URL on current WordPress web site; string error message otherwise
|
145 |
+
*/
|
146 |
+
function jr_mt_site_url( $url ) {
|
147 |
+
$check_url = trim( $url );
|
148 |
+
if ( strcasecmp( 'http', substr( $check_url, 0, 4 ) ) != 0 ) {
|
149 |
+
return 'URL does not begin with http://';
|
150 |
+
}
|
151 |
+
$site_home = get_home_url();
|
152 |
+
if ( strcasecmp( $site_home, substr( $check_url, 0, strlen( $site_home ) ) ) != 0 ) {
|
153 |
+
return "URL specified is not part of current WordPress web site. URL must begin with '$site_home'";
|
154 |
+
}
|
155 |
+
return TRUE;
|
156 |
+
}
|
157 |
+
?>
|
includes/select-theme.php
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Select the relevant Theme
|
3 |
+
|
4 |
+
add_filter( 'pre_option_stylesheet', 'jr_mt_stylesheet' );
|
5 |
+
add_filter( 'pre_option_template', 'jr_mt_template' );
|
6 |
+
|
7 |
+
function jr_mt_stylesheet() {
|
8 |
+
return jr_mt_theme( 'stylesheet' );
|
9 |
+
}
|
10 |
+
|
11 |
+
function jr_mt_template() {
|
12 |
+
return jr_mt_theme( 'template' );
|
13 |
+
}
|
14 |
+
|
15 |
+
function jr_mt_theme( $option ) {
|
16 |
+
/* The hooks that (indirectly) call this function are called repeatedly by WordPress,
|
17 |
+
so do the checking once and store the values in a global array.
|
18 |
+
*/
|
19 |
+
global $jr_mt_theme;
|
20 |
+
if ( !isset( $jr_mt_theme ) ) {
|
21 |
+
$jr_mt_theme = array();
|
22 |
+
}
|
23 |
+
if ( !isset( $jr_mt_theme[$option] ) ) {
|
24 |
+
$theme = jr_mt_chosen();
|
25 |
+
if ( $theme === FALSE ) {
|
26 |
+
// $jr_mt_theme[$option] = jr_mt_current_theme( $option ); if stylesheet and template are ever different
|
27 |
+
$jr_mt_theme['template'] = jr_mt_current_theme();
|
28 |
+
$jr_mt_theme['stylesheet'] = jr_mt_current_theme();
|
29 |
+
} else {
|
30 |
+
$jr_mt_theme[$option] = $theme;
|
31 |
+
}
|
32 |
+
}
|
33 |
+
return $jr_mt_theme[$option];
|
34 |
+
}
|
35 |
+
|
36 |
+
function jr_mt_chosen() {
|
37 |
+
if ( is_admin() ) {
|
38 |
+
// Admin panel
|
39 |
+
// return P2 theme if p2ajax= is present; current theme otherwise
|
40 |
+
parse_str( $_SERVER['QUERY_STRING'], $keywords );
|
41 |
+
if ( isset( $keywords['p2ajax'] ) && array_key_exists( 'p2', wp_get_themes() ) ) {
|
42 |
+
$theme = 'p2';
|
43 |
+
} else {
|
44 |
+
$theme = jr_mt_current_theme();
|
45 |
+
}
|
46 |
+
} else {
|
47 |
+
// Non-Admin page, i.e. - Public Site, etc.
|
48 |
+
extract( jr_mt_url_to_id( 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] ) );
|
49 |
+
$settings = get_option( 'jr_mt_settings' );
|
50 |
+
if ( $home ) {
|
51 |
+
if ( trim( $settings['site_home'] ) != '' ) {
|
52 |
+
return $settings['site_home'];
|
53 |
+
}
|
54 |
+
}
|
55 |
+
$ids = $settings['ids'];
|
56 |
+
if ( $id === FALSE ) {
|
57 |
+
if ( isset( $ids[$page_url] ) ) {
|
58 |
+
$theme = $ids[$page_url]['theme'];
|
59 |
+
} else {
|
60 |
+
$theme = jr_mt_check_all( $type, $rel_url, $ids );
|
61 |
+
}
|
62 |
+
} else {
|
63 |
+
if ( isset( $ids[$id] ) ) {
|
64 |
+
$theme = $ids[$id]['theme'];
|
65 |
+
} else {
|
66 |
+
$theme = jr_mt_check_all( $type, $rel_url, $ids );
|
67 |
+
}
|
68 |
+
}
|
69 |
+
}
|
70 |
+
return $theme;
|
71 |
+
}
|
72 |
+
|
73 |
+
function jr_mt_check_all( $type, $rel_url, $ids ) {
|
74 |
+
// Check Prefix entries first, because we already know there is no specific entry for this URL.
|
75 |
+
$theme = '';
|
76 |
+
$match_length = 0;
|
77 |
+
foreach ( $ids as $key => $array ) {
|
78 |
+
if ( $array['type'] == 'prefix' ) {
|
79 |
+
$this_length = strlen( $array['rel_url'] );
|
80 |
+
if ( $array['rel_url'] == substr( $rel_url, 0, $this_length ) ) {
|
81 |
+
// Need to find longest match if there are multiple prefix matches.
|
82 |
+
if ( $this_length > $match_length ) {
|
83 |
+
$theme = $array['theme'];
|
84 |
+
$match_length = $this_length;
|
85 |
+
}
|
86 |
+
}
|
87 |
+
}
|
88 |
+
}
|
89 |
+
// See if a Prefix entry was found
|
90 |
+
if ( $match_length == 0 ) {
|
91 |
+
if ( $type === FALSE ) {
|
92 |
+
$theme = FALSE;
|
93 |
+
} else {
|
94 |
+
$settings = get_option( 'jr_mt_settings' );
|
95 |
+
if ( isset( $settings["all_$type"] ) ) {
|
96 |
+
$theme = $settings["all_$type"];
|
97 |
+
} else {
|
98 |
+
$theme = '';
|
99 |
+
}
|
100 |
+
if ( empty( $theme ) ) {
|
101 |
+
$theme = FALSE;
|
102 |
+
}
|
103 |
+
}
|
104 |
+
}
|
105 |
+
return $theme;
|
106 |
+
}
|
107 |
+
|
108 |
+
?>
|
jonradio-multiple-themes.php
ADDED
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: jonradio Multiple Themes
|
4 |
+
Plugin URI: http://zatzlabs.com/plugins/
|
5 |
+
Description: Select different Themes for one or more, or all WordPress Pages, Posts or other non-Admin pages. Or Site Home.
|
6 |
+
Version: 3.2
|
7 |
+
Author: David Gewirtz
|
8 |
+
Author URI: http://zatzlabs.com/plugins/
|
9 |
+
License: GPLv2
|
10 |
+
*/
|
11 |
+
|
12 |
+
/* Copyright 2012 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 |
+
// Limitation: This plugin does not currently support Theme usage that involves the stylesheet and template names not being the same.
|
30 |
+
|
31 |
+
global $jr_mt_plugin_folder;
|
32 |
+
$jr_mt_plugin_folder = basename( dirname( __FILE__ ) );
|
33 |
+
|
34 |
+
function jr_mt_plugin_folder() {
|
35 |
+
global $jr_mt_plugin_folder;
|
36 |
+
return $jr_mt_plugin_folder;
|
37 |
+
}
|
38 |
+
|
39 |
+
global $jr_mt_path;
|
40 |
+
$jr_mt_path = plugin_dir_path( __FILE__ );
|
41 |
+
function jr_mt_path() {
|
42 |
+
global $jr_mt_path;
|
43 |
+
return $jr_mt_path;
|
44 |
+
}
|
45 |
+
|
46 |
+
global $jr_mt_plugin_basename;
|
47 |
+
$jr_mt_plugin_basename = plugin_basename( __FILE__ );
|
48 |
+
|
49 |
+
if ( !function_exists( 'get_plugin_data' ) ) {
|
50 |
+
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
51 |
+
}
|
52 |
+
|
53 |
+
global $jr_mt_plugin_data;
|
54 |
+
$jr_mt_plugin_data = get_plugin_data( __FILE__ );
|
55 |
+
|
56 |
+
global $jr_mt_options_cache;
|
57 |
+
$all_options = wp_load_alloptions();
|
58 |
+
$jr_mt_options_cache['stylesheet'] = $all_options['stylesheet'];
|
59 |
+
$jr_mt_options_cache['template'] = $all_options['template'];
|
60 |
+
|
61 |
+
register_activation_hook( __FILE__, 'jr_mt_activate' );
|
62 |
+
register_deactivation_hook( __FILE__, 'jr_mt_deactivate' );
|
63 |
+
|
64 |
+
function jr_mt_activate( $network_wide ) {
|
65 |
+
if ( $network_wide ) {
|
66 |
+
global $wpdb, $site_id;
|
67 |
+
$blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = $site_id" );
|
68 |
+
foreach ( $blogs as $blog_obj ) {
|
69 |
+
if ( switch_to_blog( $blog_obj->blog_id ) ) {
|
70 |
+
// We know the Site actually exists
|
71 |
+
jr_mt_activate1();
|
72 |
+
}
|
73 |
+
}
|
74 |
+
restore_current_blog();
|
75 |
+
} else {
|
76 |
+
jr_mt_activate1();
|
77 |
+
}
|
78 |
+
}
|
79 |
+
|
80 |
+
function jr_mt_activate1() {
|
81 |
+
$settings = array(
|
82 |
+
'all_pages' => '',
|
83 |
+
'all_posts' => '',
|
84 |
+
'site_home' => '',
|
85 |
+
'ids' => array()
|
86 |
+
);
|
87 |
+
// Nothing happens if Settings already exist
|
88 |
+
add_option( 'jr_mt_settings', $settings );
|
89 |
+
|
90 |
+
global $jr_mt_plugin_data;
|
91 |
+
$internal_settings = array(
|
92 |
+
'version' => $jr_mt_plugin_data['Version']
|
93 |
+
); // Only records you version when plugin installed, not current version
|
94 |
+
add_option( 'jr_mt_internal_settings', $internal_settings ); // Nothing happens if Settings already exist
|
95 |
+
}
|
96 |
+
|
97 |
+
add_action( 'wpmu_new_blog', 'jr_mt_new_site', 10, 6 );
|
98 |
+
|
99 |
+
function jr_mt_new_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
|
100 |
+
if ( is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
|
101 |
+
switch_to_blog( $blog_id );
|
102 |
+
jr_mt_activate1();
|
103 |
+
restore_current_blog();
|
104 |
+
}
|
105 |
+
}
|
106 |
+
|
107 |
+
function jr_mt_deactivate() {
|
108 |
+
// Nothing (yet)
|
109 |
+
}
|
110 |
+
|
111 |
+
jr_mt_version_check();
|
112 |
+
|
113 |
+
function jr_mt_version_check() {
|
114 |
+
// Check for Plugin Version update (Deactivate and Activate Hooks not fired)
|
115 |
+
$internal_settings = get_option( 'jr_mt_internal_settings' );
|
116 |
+
if ( $internal_settings ) { // Just in case Activation has not occurred yet
|
117 |
+
global $jr_mt_plugin_data;
|
118 |
+
if ( version_compare( $internal_settings['version'], $jr_mt_plugin_data['Version'], '<' ) ) {
|
119 |
+
$settings = get_option( 'jr_mt_settings' );
|
120 |
+
if ( isset( $settings['ids'] ) ) {
|
121 |
+
$ids = $settings['ids'];
|
122 |
+
} else {
|
123 |
+
$ids = array();
|
124 |
+
}
|
125 |
+
if ( version_compare( $internal_settings['version'], '2.1', '<' ) ) {
|
126 |
+
unset( $settings['all_admin'] );
|
127 |
+
// Check for Site Home entry, remove it and set Site Home field
|
128 |
+
// And remove all Admin entries (no longer supported)
|
129 |
+
if ( isset( $ids[''] ) ) {
|
130 |
+
$settings['site_home'] = $ids['']['theme'];
|
131 |
+
unset( $ids[''] );
|
132 |
+
} else {
|
133 |
+
$settings['site_home'] = '';
|
134 |
+
}
|
135 |
+
foreach ( $ids as $key => $arr ) {
|
136 |
+
if ( $arr['type'] == 'admin' ) {
|
137 |
+
unset( $ids[$key] );
|
138 |
+
}
|
139 |
+
}
|
140 |
+
}
|
141 |
+
if ( version_compare( $internal_settings['version'], '3.0', '<' ) ) {
|
142 |
+
foreach ( $ids as $key => $arr ) {
|
143 |
+
if ( strcasecmp( 'http', substr( $arr['rel_url'], 0, 4 ) ) == 0 ) {
|
144 |
+
unset( $ids[$key] );
|
145 |
+
}
|
146 |
+
}
|
147 |
+
}
|
148 |
+
$settings['ids'] = $ids;
|
149 |
+
update_option( 'jr_mt_settings', $settings );
|
150 |
+
$internal_settings['version'] = $jr_mt_plugin_data['Version'];
|
151 |
+
update_option( 'jr_mt_internal_settings', $internal_settings );
|
152 |
+
}
|
153 |
+
}
|
154 |
+
}
|
155 |
+
|
156 |
+
require_once( jr_mt_path() . 'includes/functions.php' );
|
157 |
+
|
158 |
+
// Do not try and select a Theme for Admin Pages
|
159 |
+
// Check that template and stylesheet have the same value for the Current Theme, as Plugin expects this to be true.
|
160 |
+
global $jr_mt_options_cache;
|
161 |
+
if ( $jr_mt_options_cache['template'] == $jr_mt_options_cache['stylesheet'] ) {
|
162 |
+
require_once( jr_mt_path() . 'includes/select-theme.php' );
|
163 |
+
}
|
164 |
+
|
165 |
+
if ( is_admin() ) {
|
166 |
+
// Admin panel
|
167 |
+
require_once( jr_mt_path() . 'includes/admin.php' );
|
168 |
+
}
|
169 |
+
|
170 |
+
/*
|
171 |
+
Research Notes:
|
172 |
+
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:
|
173 |
+
- is_admin()
|
174 |
+
- is_user_logged_in()
|
175 |
+
- get_option("page_on_front") - ID of home page; zero if Reading Settings NOT set to a Static Page of a WordPress Page
|
176 |
+
*/
|
177 |
+
|
178 |
+
?>
|
readme.txt
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== jonradio Multiple Themes ===
|
2 |
+
Contributors: dgewirtz
|
3 |
+
Donate link: http://zatzlabs.com/plugins/
|
4 |
+
Tags: themes, theme, sections, style, template, stylesheet, accessibility
|
5 |
+
Requires at least: 3.4.1
|
6 |
+
Tested up to: 3.5
|
7 |
+
Stable tag: 3.2
|
8 |
+
License: GPLv2 or later
|
9 |
+
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
+
|
11 |
+
Select different Themes for one or more, or all WordPress Pages, Posts or other non-Admin pages. Or Site Home.
|
12 |
+
|
13 |
+
== Description ==
|
14 |
+
|
15 |
+
Allows the Administrator to specify which Theme will be used on specific Pages, Posts, other non-Admin pages (such as Category or Archive pages) or Site Home. Also allows a Theme to be specified for All Pages or All Posts. In turn, even when a Theme is specified for All Pages or All Posts, a different Theme can still be specified for specific Pages or Posts.
|
16 |
+
|
17 |
+
**Changing Theme Options (Widgets, Sidebars, Menus, Background, Header, etc.)?**: See the FAQ (Frequently-Asked Questions) tab for important information on changing Options on Themes other than the Current Theme.
|
18 |
+
|
19 |
+
Think what you could do if you could easily use more than one Theme on your WordPress web site or blog:
|
20 |
+
|
21 |
+
* Divide your site into Sections, each with its own unique look
|
22 |
+
* Style individual Pages, Posts, or other elements (Site Home, Category main page, Archive main page) with a different Theme
|
23 |
+
* Select a unique Theme for all Pages, Posts, Attachments, Category pages or Archive pages
|
24 |
+
* Supports Multiple Stylesheets for Accessibility and other purposes (create one Child Theme for each Stylesheet)
|
25 |
+
* Test a new Theme on one or more Pages or Posts
|
26 |
+
* Convert to a new Theme a Page or Post at a time
|
27 |
+
* Host multiple mini-web sites on your WordPress site, each with a different Theme
|
28 |
+
* When a larger version of an image attachment is displayed, for example, when clicking on a gallery image thumbnail, use a different theme to display it, for one or all images attached to a Page or Post
|
29 |
+
|
30 |
+
To select all Pages, Posts, Archives, Categories, etc. that begin with the same partial URL, a "Prefix URL" can be specified by selecting the Prefix checkbox when creating an entry on the Settings page for the Plugin. Restriction: the Prefix URL cannot contain all or part of a Query, which is the portion of a URL that begins with a question mark ("?"). Although the Prefix cannot contain a Query, URLs containing a Query will be matched by the Prefix.
|
31 |
+
|
32 |
+
If a Theme is not specified for a Page, Post, Site Home or other WordPress-displayed web page, such as Category or Archive display, the **Current Theme** specified in **Appearance-Themes** on the Admin panels will be used.
|
33 |
+
|
34 |
+
When selecting a Theme for Site Home or all or specific Pages, Posts or other non-Admin pages, the Theme must be shown in the list of Available Themes on the Appearance-Themes Admin panel. If necessary, install the Theme. In a WordPress Network (AKA Multisite), Themes must be **Network Enabled** before they will appear as Available Themes on individual sites' Appearance-Themes panel.
|
35 |
+
|
36 |
+
I hesitate to use the term **Theme Switcher** to describe this plugin, because the term has so many meanings. This plugin does **not** alter the standard WordPress options that define what Theme is used on your WordPress site. Instead, it dynamically (and selectively) overrides that choice. Technical details aside, what this means is that deactivating or deleting the plugin will instantly revert to the WordPress Current Theme that you have defined through the standard WordPress Appearance-Themes Admin panel.
|
37 |
+
|
38 |
+
== Installation ==
|
39 |
+
|
40 |
+
This section describes how to install the plugin and get it working.
|
41 |
+
|
42 |
+
1. Use "Add Plugin" within the WordPress Admin panel to download and install this 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.
|
43 |
+
1. Activate the plugin through the 'Plugins' menu in WordPress. If you have a WordPress Network ("Multisite"), you can either Network Activate this plugin, or Activate it individually on the sites where you wish to use it. Activating on individual sites within a Network avoids some of the confusion created by WordPress' hiding of Network Activated plugins on the Plugin menu of individual sites.
|
44 |
+
1. Be sure that all Themes you plan to use have been installed and are listed under Available Themes on the WordPress Appearance-Themes Admin panel. In a WordPress Network (AKA Multisite), Themes must be **Network Enabled** before they will appear as Available Themes on individual sites' Appearance-Themes panel.
|
45 |
+
1. Select Themes to be used on the Plugin's "Multiple Themes plugin" page in the WordPress Admin panels, which is found in both the **Appearance** and **Settings** sections. You can also get to this page by clicking on the **Settings** link for this plugin on the **Installed Plugins** page.
|
46 |
+
1. If you need to change Theme Options (Widgets, Sidebars, Menus, Background, Header, etc.) for any Theme other than the Current Theme, see the FAQ (Frequently-Asked Questions) tab for important information.
|
47 |
+
|
48 |
+
== Frequently Asked Questions ==
|
49 |
+
|
50 |
+
= How do I change the Theme Options (Widgets, Sidebars, Menus, Background, Header, etc.) used for each Theme? =
|
51 |
+
|
52 |
+
Options for all Themes, including Widgets, Sidebars, Menus, Background, Header and other Customizations supported by the Theme, can be modified in the Admin panel using the Appearance menu items on the left sidebar and the Customize link displayed beside the Current Theme on the Manage Themes tab of Appearance-Themes.
|
53 |
+
|
54 |
+
For the Current Theme, there are no issues, as WordPress provides this functionality without any intervention by plugins.
|
55 |
+
|
56 |
+
However, to modify Options for Active Themes that are *not* the Current Theme, the jonradio Multiple Themes plugin (i.e. - this plugin) must be Deactivated, and the Theme Test Drive plugin installed and activated, so that each Theme can be selected with the Theme Test Drive plugin, allowing the Theme's Options to be set "as if" it were the Current Theme.
|
57 |
+
|
58 |
+
Design work is currently underway to fully support Theme Options for each Theme used with the jonradio Multiple Themes plugin. Until that work is completed, in a future version of this plugin, the following Workaround using the Theme Test Drive plugin is being provided:
|
59 |
+
|
60 |
+
1. Deactivate jonradio Multiple Themes
|
61 |
+
1. Install the Theme Test Drive plugin found at http://wordpress.org/extend/plugins/theme-test-drive/
|
62 |
+
1. Activate the Theme Test Drive plugin
|
63 |
+
1. Go to Appearance-Theme Test Drive
|
64 |
+
1. In the Usage section, select an alternate Theme you will be using with jonradio Multiple Themes
|
65 |
+
1. Push the Enable Theme Drive button at the bottom
|
66 |
+
1. Go to the WordPress Admin panel's Appearance menu (left sidebar)
|
67 |
+
1. Make your changes to the Theme Options, including Widgets, Sidebars, Menus, Background, Header and other Customizations for this alternate Theme (which will appear as if it were the Current Theme)
|
68 |
+
1. If you have more than one alternate Theme with Options you wish to change, repeat Steps 4-8 for each alternate Theme
|
69 |
+
1. Deactivate the Theme Test Drive plugin
|
70 |
+
1. Activate jonradio Multiple Themes
|
71 |
+
1. Changes to the Options for the Current Theme can now be made normally, just as you would without either plugin
|
72 |
+
1. Both the alternate and Current Themes should now display all Theme options properly when selected through the jonradio Multiple Themes plugin
|
73 |
+
|
74 |
+
= What happens when I change Permalinks? =
|
75 |
+
|
76 |
+
For entries you have created for individual Pages and Posts with this plugin, you can subsequently change your Permalink structure or you can change the Permalink of a Page or Post, without having to change the plugin's entry. However, for other pages, such as Categories or Archives, you will have to delete your old entries and create new ones with this plugin.
|
77 |
+
|
78 |
+
= I added a new entry but why doesn't it appear in the list of entries? =
|
79 |
+
|
80 |
+
If you add an entry that already exists, it merely replaces the previous entry.
|
81 |
+
|
82 |
+
= How can I change the Theme for an entry? =
|
83 |
+
|
84 |
+
Simply add the entry again, with the new Theme. It will replace the previous entry.
|
85 |
+
|
86 |
+
== Screenshots ==
|
87 |
+
|
88 |
+
1. Plugin's Admin Page when first installed
|
89 |
+
2. Plugin's Admin Page, adding entries
|
90 |
+
|
91 |
+
== Changelog ==
|
92 |
+
|
93 |
+
= 3.2 =
|
94 |
+
* Correct Problem with P2 Theme, and its logged on verification at wp-admin/admin-ajax.php?p2ajax=true&action=logged_in_out&_loggedin={nonce}
|
95 |
+
* Add "Settings Saved" message to Admin page
|
96 |
+
* Tested with WordPress Version 3.5 beta
|
97 |
+
|
98 |
+
= 3.1 =
|
99 |
+
* Add Support for Prefixes, where all URLs beginning with the specified characters ("Prefix") can be assigned to a specified Theme
|
100 |
+
|
101 |
+
= 3.0 =
|
102 |
+
* Add Support for Categories and Archives when no Permalinks exist (support already existed Categories and Archives with Permalinks)
|
103 |
+
* Resolve several minor bugs
|
104 |
+
|
105 |
+
= 2.9 =
|
106 |
+
* Rewrite much of the Settings page and Plugin Directory documentation
|
107 |
+
* Add Support for IIS which returns incorrect values in $_SERVER['REQUEST_URI']
|
108 |
+
* Make it easier to select the Theme for the Site Home by providing a new Settings field
|
109 |
+
* 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
|
110 |
+
* Add version upgrade detection to add, remove and update Settings fields
|
111 |
+
* Move Settings link on Plugins page from beginning to end of links
|
112 |
+
|
113 |
+
= 2.0 =
|
114 |
+
* Address pecularities of wp_make_link_relative() related to root-based WordPress sites using Permalinks
|
115 |
+
|
116 |
+
= 1.1 =
|
117 |
+
* Fix foreach failing on some systems, based on PHP warning level
|
118 |
+
|
119 |
+
= 1.0 =
|
120 |
+
* Make plugin conform to WordPress plugin repository standards.
|
121 |
+
* Beta testing completed.
|
122 |
+
|
123 |
+
== Upgrade Notice ==
|
124 |
+
|
125 |
+
= 3.2 =
|
126 |
+
Add Support for P2 Theme and provide "Settings Saved" message
|
127 |
+
|
128 |
+
= 3.1 =
|
129 |
+
Allow Prefix URLs to be used to specify where a Theme will be displayed
|
130 |
+
|
131 |
+
= 3.0 =
|
132 |
+
Improve support for Categories and Archives, and eliminate all known bugs.
|
133 |
+
|
134 |
+
= 2.9 =
|
135 |
+
Improve Settings fields, correct display of wrong Current Theme in Appearance-Themes Admin panel, and add IIS Support.
|
136 |
+
|
137 |
+
= 2.0 =
|
138 |
+
Selecting Individual Pages and Posts on a WordPress site installed in the root and using Permalinks now works correctly.
|
139 |
+
|
140 |
+
= 1.1 =
|
141 |
+
Eliminate possibility of foreach error message if PHP warning level is set at a high level
|
142 |
+
|
143 |
+
= 1.0 =
|
144 |
+
Beta version 0.9 had not been tested when installed from the WordPress Plugin Repository
|
uninstall.php
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Ensure call comes from WordPress, not a hacker.
|
3 |
+
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
|
4 |
+
exit ();
|
5 |
+
|
6 |
+
/* Remove any tables, options, and such created by this Plugin */
|
7 |
+
if ( function_exists('is_multisite') && is_multisite() ) {
|
8 |
+
global $wpdb, $site_id;
|
9 |
+
$blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = $site_id" );
|
10 |
+
foreach ($blogs as $blog_obj) {
|
11 |
+
delete_blog_option( $blog_obj->blog_id, 'jr_mt_settings' );
|
12 |
+
delete_blog_option( $blog_obj->blog_id, 'jr_mt_internal_settings' );
|
13 |
+
}
|
14 |
+
} else {
|
15 |
+
delete_option( 'jr_mt_settings' );
|
16 |
+
delete_option( 'jr_mt_internal_settings' );
|
17 |
+
}
|
18 |
+
?>
|