Version Description
- Make plugin conform to WordPress plugin repository standards.
- Beta testing completed.
=
Download this release
Release Info
Developer | dgewirtz |
Plugin | Multiple Themes |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
- includes/admin.php +240 -0
- includes/debug/debug.php +24 -0
- includes/functions.php +102 -0
- includes/select-theme.php +68 -0
- jonradio-multiple-themes.php +118 -0
- readme.txt +63 -0
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
- uninstall.php +18 -0
includes/admin.php
ADDED
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
?><h2>jonradio Multiple Themes</h2>
|
28 |
+
<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.
|
29 |
+
You can choose from any of the <b>Available Themes</b> listed on the Appearance-Themes Admin panel for:
|
30 |
+
<ul>
|
31 |
+
<li> » All Pages</li>
|
32 |
+
<li> » All Posts</li>
|
33 |
+
<li> » All Admin Pages</li>
|
34 |
+
<li> » The Site Home</li>
|
35 |
+
<li> » A Specific Page</li>
|
36 |
+
<li> » A Specific Post</li>
|
37 |
+
<li> » A Specific Admin Page</li>
|
38 |
+
</ul>
|
39 |
+
<?php
|
40 |
+
if ( function_exists('is_multisite') && is_multisite() ) {
|
41 |
+
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.";
|
42 |
+
}
|
43 |
+
echo '</p>';
|
44 |
+
echo '<form action="options.php" method="POST">';
|
45 |
+
|
46 |
+
// Plugin Settings are displayed and entered here:
|
47 |
+
settings_fields( 'jr_mt_settings' );
|
48 |
+
do_settings_sections( 'jr_mt_settings_page' );
|
49 |
+
echo '<p><input name="save" type="submit" value="Save Changes" class="button-primary" /></p></form>';
|
50 |
+
}
|
51 |
+
|
52 |
+
add_action( 'admin_init', 'jr_mt_admin_init' );
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Register and define the settings
|
56 |
+
*
|
57 |
+
* Everything to be stored and/or can be set by the user
|
58 |
+
*
|
59 |
+
*/
|
60 |
+
function jr_mt_admin_init() {
|
61 |
+
register_setting( 'jr_mt_settings', 'jr_mt_settings', 'jr_mt_validate_settings' );
|
62 |
+
add_settings_section( 'jr_mt_all_settings_section',
|
63 |
+
'For All Pages, Posts and/or Admin Panel Pages',
|
64 |
+
'jr_mt_all_settings_expl',
|
65 |
+
'jr_mt_settings_page'
|
66 |
+
);
|
67 |
+
foreach ( array( 'Pages', 'Posts', 'Admin' ) as $thing ) {
|
68 |
+
add_settings_field( 'all_' . strtolower( $thing ), "Select Theme for All $thing", 'jr_mt_echo_all_things', 'jr_mt_settings_page', 'jr_mt_all_settings_section',
|
69 |
+
array( 'thing' => $thing ) );
|
70 |
+
}
|
71 |
+
$settings = get_option( 'jr_mt_settings' );
|
72 |
+
$ids = $settings['ids'];
|
73 |
+
if ( !empty( $ids) ) {
|
74 |
+
add_settings_section( 'jr_mt_delete_settings_section',
|
75 |
+
'To Display or Delete Theme Selections for Individual Pages, Posts and/or Admin Panel Pages',
|
76 |
+
'jr_mt_delete_settings_expl',
|
77 |
+
'jr_mt_settings_page'
|
78 |
+
);
|
79 |
+
add_settings_field( 'del_entry', 'Entries:', 'jr_mt_echo_delete_entry', 'jr_mt_settings_page', 'jr_mt_delete_settings_section' );
|
80 |
+
}
|
81 |
+
add_settings_section( 'jr_mt_single_settings_section',
|
82 |
+
'For An Individual Page, Post, Admin Panel Page or Site Home',
|
83 |
+
'jr_mt_single_settings_expl',
|
84 |
+
'jr_mt_settings_page'
|
85 |
+
);
|
86 |
+
add_settings_field( 'add_theme', 'Theme', 'jr_mt_echo_add_theme', 'jr_mt_settings_page', 'jr_mt_single_settings_section' );
|
87 |
+
add_settings_field( 'add_path_id', 'URL of Page, Post or Admin Panel', 'jr_mt_echo_add_path_id', 'jr_mt_settings_page', 'jr_mt_single_settings_section' );
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Section text for Section1
|
92 |
+
*
|
93 |
+
* Display an explanation of this Section
|
94 |
+
*
|
95 |
+
*/
|
96 |
+
function jr_mt_all_settings_expl() {
|
97 |
+
echo '<p>In this section, you can select a different Theme for All Pages, Posts and/or Admin Panel Pages.';
|
98 |
+
echo ' After this, you will be able to select a Theme, including the Current Theme, to override any choice you make here, for individual Pages, Posts or Admin Panel Pages.</p>';
|
99 |
+
}
|
100 |
+
|
101 |
+
function jr_mt_echo_all_things( $thing ) {
|
102 |
+
$settings = get_option( 'jr_mt_settings' );
|
103 |
+
$field = 'all_' . strtolower( $thing['thing'] );
|
104 |
+
jr_mt_themes_field( $field, $settings[$field], 'jr_mt_settings' );
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Section text for Section2
|
109 |
+
*
|
110 |
+
* Display an explanation of this Section
|
111 |
+
*
|
112 |
+
*/
|
113 |
+
function jr_mt_delete_settings_expl() {
|
114 |
+
echo '<p>In this section, all entries are displayed for Themes selected for individual Pages, Posts or Admin Panel Pages.';
|
115 |
+
echo ' You can delete any of these entries by filling in the check box beside each one.</p>';
|
116 |
+
echo '<p>To change the Theme for an entry, add the same entry with a different Theme in the section below this one.</p>';
|
117 |
+
}
|
118 |
+
|
119 |
+
function jr_mt_echo_delete_entry() {
|
120 |
+
$entry_num = 0;
|
121 |
+
$settings = get_option( 'jr_mt_settings' );
|
122 |
+
foreach ( $settings['ids'] as $path_id => $opt_array ) {
|
123 |
+
++$entry_num;
|
124 |
+
echo "Delete <input type='checkbox' id='del_entry' name='jr_mt_settings[del_entry][]' value='$path_id' /> Theme="
|
125 |
+
. wp_get_theme( $opt_array['theme'] )->Name . '; ';
|
126 |
+
if ( $path_id == '' ) {
|
127 |
+
echo 'Site=<a href="' . get_home_url() . '" target="_blank">Home</a>';
|
128 |
+
} else {
|
129 |
+
$p_array = get_posts( array( 'post_type' => 'any', 'include' => array( $path_id ) ) );
|
130 |
+
if ( empty( $p_array ) ) {
|
131 |
+
if ( $opt_array['type'] == 'admin' ) {
|
132 |
+
echo 'Admin=<a href="' . get_home_url() . '/' . $opt_array['rel_url'] . '" target="_blank">'. "$path_id</a>";
|
133 |
+
} else {
|
134 |
+
echo 'Path=<a href="' . get_home_url() . "/$path_id" . '" target="_blank">'. "$path_id</a>";
|
135 |
+
}
|
136 |
+
} else {
|
137 |
+
echo ucfirst( $p_array[0]->post_type ) . '=<a href="' . get_permalink( $path_id ) . '" target="_blank">' . $p_array[0]->post_title . '</a>';
|
138 |
+
}
|
139 |
+
}
|
140 |
+
echo '<br />';
|
141 |
+
}
|
142 |
+
}
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Section text for Section3
|
146 |
+
*
|
147 |
+
* Display an explanation of this Section
|
148 |
+
*
|
149 |
+
*/
|
150 |
+
function jr_mt_single_settings_expl() {
|
151 |
+
echo '<p>Select a Theme for an individual Page, Post or Admin Panel Page.';
|
152 |
+
echo ' Then cut and paste the URL of the desired Page, Post or Admin Page.';
|
153 |
+
echo ' And click the <b>Save Changes</b> button to add the entry.</p>';
|
154 |
+
}
|
155 |
+
|
156 |
+
function jr_mt_echo_add_theme() {
|
157 |
+
jr_mt_themes_field( 'add_theme', '', 'jr_mt_settings' );
|
158 |
+
}
|
159 |
+
|
160 |
+
function jr_mt_echo_add_path_id() {
|
161 |
+
echo '<input id="add_path_id" name="jr_mt_settings[add_path_id]" type="text" size="100" maxlength="256" value="" /><br />(cut and paste URL of Page, Post, Admin Panel Page or Site Home here)';
|
162 |
+
echo '<p>Note: Few, if any, Themes alter the appearance of the Admin Panel Pages. This Plugin hopes to change that. For those who cannot wait, there are Plugins, most of which call themselves Themes but are listed in the WordPress Plugin Directory, that change the appearance of Admin Panel Pages.</p>';
|
163 |
+
}
|
164 |
+
|
165 |
+
function jr_mt_validate_settings( $input ) {
|
166 |
+
$valid = array();
|
167 |
+
foreach ( array( 'pages', 'posts', 'admin' ) as $thing ) {
|
168 |
+
$valid["all_$thing"] = $input["all_$thing"];
|
169 |
+
}
|
170 |
+
|
171 |
+
$settings = get_option( 'jr_mt_settings' );
|
172 |
+
$ids = $settings['ids'];
|
173 |
+
foreach ( $input['del_entry'] as $del_entry ) {
|
174 |
+
unset( $ids[$del_entry] );
|
175 |
+
}
|
176 |
+
|
177 |
+
// This section needs error-checking for a bad URL pasted by Admin
|
178 |
+
$url = trim( $input['add_path_id'] );
|
179 |
+
if ( !empty( $url ) ) {
|
180 |
+
extract( jr_mt_url_to_id( $url ) );
|
181 |
+
if ( $id === FALSE ) {
|
182 |
+
$key = $page_url;
|
183 |
+
} else {
|
184 |
+
$key = $id;
|
185 |
+
}
|
186 |
+
$ids[$key] = array(
|
187 |
+
'theme' => $input['add_theme'],
|
188 |
+
'type' => $type,
|
189 |
+
'id' => $id,
|
190 |
+
'page_url' => $page_url,
|
191 |
+
'rel_url' => $rel_url,
|
192 |
+
'url' => $url
|
193 |
+
);
|
194 |
+
}
|
195 |
+
$valid['ids'] = $ids;
|
196 |
+
return $valid;
|
197 |
+
}
|
198 |
+
|
199 |
+
// Add Link to the plugin's entry on the Admin "Plugins" Page, for easy access
|
200 |
+
global $jr_mt_plugin_basename;
|
201 |
+
add_filter( "plugin_action_links_$jr_mt_plugin_basename", 'jr_mt_plugin_action_links', 10, 1 );
|
202 |
+
|
203 |
+
/**
|
204 |
+
* Creates Settings entry right on the Plugins Page entry.
|
205 |
+
*
|
206 |
+
* Helps the user understand where to go immediately upon Activation of the Plugin
|
207 |
+
* by creating entries on the Plugins page, right beside Deactivate and Edit.
|
208 |
+
*
|
209 |
+
* @param array $links Existing links for our Plugin, supplied by WordPress
|
210 |
+
* @param string $file Name of Plugin currently being processed
|
211 |
+
* @return string $links Updated set of links for our Plugin
|
212 |
+
*/
|
213 |
+
function jr_mt_plugin_action_links( $links ) {
|
214 |
+
// The "page=" query string value must be equal to the slug
|
215 |
+
// of the Settings admin page.
|
216 |
+
array_unshift( $links, '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=jr_mt_settings' . '">Settings</a>' );
|
217 |
+
return $links;
|
218 |
+
}
|
219 |
+
|
220 |
+
function jr_mt_themes_field( $field_name, $theme_name, $setting ) {
|
221 |
+
echo "<select id='$field_name' name='$setting" . "[$field_name]' size='1'>";
|
222 |
+
if ( empty( $theme_name ) ) {
|
223 |
+
$selected = 'selected="selected"';
|
224 |
+
} else {
|
225 |
+
$selected = '';
|
226 |
+
}
|
227 |
+
echo "<option value='' $selected></option>";
|
228 |
+
foreach ( wp_get_themes() as $folder => $theme_obj ) {
|
229 |
+
if ( $theme_name == $folder ) {
|
230 |
+
$selected = 'selected="selected"';
|
231 |
+
} else {
|
232 |
+
$selected = '';
|
233 |
+
}
|
234 |
+
$name = $theme_obj->Name;
|
235 |
+
echo "<option value='$folder' $selected>$name</option>";
|
236 |
+
}
|
237 |
+
echo '</select>' . PHP_EOL;
|
238 |
+
}
|
239 |
+
|
240 |
+
?>
|
includes/debug/debug.php
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/* require_once( jr_mt_path() . 'includes/debug/debug.php' );
|
3 |
+
jr_dump( '$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();
|
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 |
+
?>
|
includes/functions.php
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Given URL, return post or page ID, if possible, and relative path if not
|
4 |
+
*
|
5 |
+
* Calls jr_mt_query_keywords.
|
6 |
+
*
|
7 |
+
* @param string $url full URL of WordPress page, post, admin, etc.
|
8 |
+
* @return array array with keys of "type", "id" and "page_url":
|
9 |
+
* string type "pages", "posts" or "admin"
|
10 |
+
* string id Page ID or Post ID or FALSE
|
11 |
+
* string page_url relative URL WordPress page, post, admin, etc. or FALSE
|
12 |
+
* string rel_url URL relative to WordPress home
|
13 |
+
*/
|
14 |
+
function jr_mt_url_to_id( $url ) {
|
15 |
+
$trim = '\ /'; // remove leading and trailing backslashes, blanks and forward slashes
|
16 |
+
|
17 |
+
// get_home_url() returns "https://subdomain.domain.com/wp" - the full URL of the home page of the site
|
18 |
+
$home = trim( wp_make_link_relative( get_home_url() ), $trim ); // "wp"
|
19 |
+
|
20 |
+
$admin_home = trim( wp_make_link_relative( admin_url() ), $trim );
|
21 |
+
$page_url = trim( wp_make_link_relative( $url ), $trim ); // "wp/fruit/apples"
|
22 |
+
$is_admin = ( $admin_home == substr( $page_url, 0, strlen( $admin_home ) ) );
|
23 |
+
if ( !empty( $home ) ) { // Only if WordPress is installed in a subfolder, NOT in the Root
|
24 |
+
$page_url = trim( substr( $page_url, stripos( $page_url, $home ) + strlen( $home ) ), $trim ); // "fruit/apples"
|
25 |
+
}
|
26 |
+
$rel_url = $page_url;
|
27 |
+
|
28 |
+
$type = FALSE;
|
29 |
+
|
30 |
+
$id = jr_mt_query_keywords( parse_url( $url, PHP_URL_QUERY ) );
|
31 |
+
if ( $id === NULL ) {
|
32 |
+
if ( $is_admin ) {
|
33 |
+
$id = FALSE;
|
34 |
+
$type = 'admin';
|
35 |
+
} else {
|
36 |
+
// Check for home page (get_page_by_path() does not work for home page)
|
37 |
+
if ( empty( $page_url ) ) {
|
38 |
+
$id = get_option('page_on_front');
|
39 |
+
if ( $id == 0 ) {
|
40 |
+
// There is no home Page; posts are displayed instead on the home page
|
41 |
+
$page_url = '';
|
42 |
+
$id = FALSE;
|
43 |
+
} else {
|
44 |
+
$type = 'pages';
|
45 |
+
}
|
46 |
+
} else {
|
47 |
+
$page = get_page_by_path( $page_url );
|
48 |
+
if ( $page === NULL ) {
|
49 |
+
// get_page_by_path() returns NULL for Posts, Home Page, Admin, etc.
|
50 |
+
// So, check for Posts:
|
51 |
+
$post = get_posts( array( 'name' => $page_url ) );
|
52 |
+
if ( empty( $post ) ) {
|
53 |
+
$id = FALSE;
|
54 |
+
} else {
|
55 |
+
$id = $post[0]->ID;
|
56 |
+
$type = 'posts';
|
57 |
+
}
|
58 |
+
} else {
|
59 |
+
$id = $page->ID;
|
60 |
+
$type = 'pages';
|
61 |
+
}
|
62 |
+
}
|
63 |
+
}
|
64 |
+
} else {
|
65 |
+
// id in query of URL (?keyword=value&keyword=value)
|
66 |
+
$type = key( $id );
|
67 |
+
$id = $id[$type];
|
68 |
+
$page_url = FALSE;
|
69 |
+
}
|
70 |
+
return array( 'type' => $type, 'id' => $id, 'page_url' => $page_url, 'rel_url' => $rel_url );
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Return page_id= or p= (post ID) or page= (admin page) value from a URL
|
75 |
+
*
|
76 |
+
* Calls parse_str function in its own variable space because it could create virtually any variable name!
|
77 |
+
* Only looks at page_id=, p= and page= now, but could be expanded to other query keywords.
|
78 |
+
*
|
79 |
+
* @param string $url_query Query portion (after the ?) in a URL
|
80 |
+
* @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
|
81 |
+
*/
|
82 |
+
function jr_mt_query_keywords( $url_query ) {
|
83 |
+
if ( $url_query === NULL ) {
|
84 |
+
return NULL;
|
85 |
+
} else {
|
86 |
+
parse_str( $url_query );
|
87 |
+
if ( isset( $page_id ) ) {
|
88 |
+
return array( 'pages' => $page_id );
|
89 |
+
} else {
|
90 |
+
if ( isset( $p ) ) {
|
91 |
+
return array( 'posts' => $p );
|
92 |
+
} else {
|
93 |
+
if ( isset( $page ) ) {
|
94 |
+
return array( 'admin' => $page );
|
95 |
+
} else {
|
96 |
+
return NULL;
|
97 |
+
}
|
98 |
+
}
|
99 |
+
}
|
100 |
+
}
|
101 |
+
}
|
102 |
+
?>
|
includes/select-theme.php
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
$all_options = wp_load_alloptions();
|
27 |
+
$jr_mt_theme[$option] = $all_options[$option];
|
28 |
+
} else {
|
29 |
+
$jr_mt_theme[$option] = $theme;
|
30 |
+
}
|
31 |
+
}
|
32 |
+
return $jr_mt_theme[$option];
|
33 |
+
}
|
34 |
+
|
35 |
+
function jr_mt_chosen() {
|
36 |
+
extract( jr_mt_url_to_id( $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] ) );
|
37 |
+
$settings = get_option( 'jr_mt_settings' );
|
38 |
+
$ids = $settings['ids'];
|
39 |
+
if ( $id === FALSE ) {
|
40 |
+
if ( isset( $ids[$page_url] ) ) {
|
41 |
+
$theme = $ids[$page_url]['theme'];
|
42 |
+
} else {
|
43 |
+
$theme = jr_mt_check_all( $type );
|
44 |
+
}
|
45 |
+
} else {
|
46 |
+
if ( isset( $ids[$id] ) ) {
|
47 |
+
$theme = $ids[$id]['theme'];
|
48 |
+
} else {
|
49 |
+
$theme = jr_mt_check_all( $type );
|
50 |
+
}
|
51 |
+
}
|
52 |
+
return $theme;
|
53 |
+
}
|
54 |
+
|
55 |
+
function jr_mt_check_all( $type ) {
|
56 |
+
if ( $type === FALSE ) {
|
57 |
+
$theme = FALSE;
|
58 |
+
} else {
|
59 |
+
$settings = get_option( 'jr_mt_settings' );
|
60 |
+
$theme = $settings["all_$type"];
|
61 |
+
if ( empty( $theme ) ) {
|
62 |
+
$theme = FALSE;
|
63 |
+
}
|
64 |
+
}
|
65 |
+
return $theme;
|
66 |
+
}
|
67 |
+
|
68 |
+
?>
|
jonradio-multiple-themes.php
ADDED
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 Admin Panels. Or Site Home.
|
6 |
+
Version: 1.0
|
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 |
+
register_activation_hook( __FILE__, 'jr_mt_activate' );
|
50 |
+
register_deactivation_hook( __FILE__, 'jr_mt_deactivate' );
|
51 |
+
|
52 |
+
function jr_mt_activate( $network_wide ) {
|
53 |
+
if ( $network_wide ) {
|
54 |
+
global $wpdb, $site_id;
|
55 |
+
$blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = $site_id" );
|
56 |
+
foreach ( $blogs as $blog_obj ) {
|
57 |
+
if ( switch_to_blog( $blog_obj->blog_id ) ) {
|
58 |
+
// We know the Site actually exists
|
59 |
+
jr_mt_activate1();
|
60 |
+
}
|
61 |
+
}
|
62 |
+
restore_current_blog();
|
63 |
+
} else {
|
64 |
+
jr_mt_activate1();
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
function jr_mt_activate1() {
|
69 |
+
$settings = array(
|
70 |
+
'all_pages' => '',
|
71 |
+
'all_posts' => '',
|
72 |
+
'all_admin' => '',
|
73 |
+
'ids' => array()
|
74 |
+
);
|
75 |
+
// Nothing happens if Settings already exist
|
76 |
+
add_option( 'jr_mt_settings', $settings );
|
77 |
+
|
78 |
+
$plugin_data = get_plugin_data( __FILE__ );
|
79 |
+
$version = $plugin_data['Version'];
|
80 |
+
$internal_settings = array(
|
81 |
+
'version' => $version
|
82 |
+
);
|
83 |
+
// Nothing happens if Settings already exist
|
84 |
+
add_option( 'jr_mt_internal_settings', $internal_settings );
|
85 |
+
}
|
86 |
+
|
87 |
+
add_action( 'wpmu_new_blog', 'jr_mt_new_site', 10, 6 );
|
88 |
+
|
89 |
+
function jr_mt_new_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
|
90 |
+
if ( is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
|
91 |
+
switch_to_blog( $blog_id );
|
92 |
+
jr_mt_activate1();
|
93 |
+
restore_current_blog();
|
94 |
+
}
|
95 |
+
}
|
96 |
+
|
97 |
+
function jr_mt_deactivate() {
|
98 |
+
// Nothing (yet)
|
99 |
+
}
|
100 |
+
|
101 |
+
require_once( jr_mt_path() . 'includes/select-theme.php' );
|
102 |
+
|
103 |
+
if ( is_admin() ) {
|
104 |
+
// Admin panel
|
105 |
+
require_once( jr_mt_path() . 'includes/admin.php' );
|
106 |
+
}
|
107 |
+
|
108 |
+
require_once( jr_mt_path() . 'includes/functions.php' );
|
109 |
+
|
110 |
+
/*
|
111 |
+
Research Notes:
|
112 |
+
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:
|
113 |
+
- is_admin()
|
114 |
+
- is_user_logged_in()
|
115 |
+
- get_option("page_on_front") - ID of home page; zero if Reading Settings NOT set to a Static Page of a WordPress Page
|
116 |
+
*/
|
117 |
+
|
118 |
+
?>
|
readme.txt
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== jonradio Multiple Themes ===
|
2 |
+
Contributors: dgewirtz
|
3 |
+
Donate link: http://zatzlabs.com/plugins/
|
4 |
+
Tags: themes, theme
|
5 |
+
Requires at least: 3.4.1
|
6 |
+
Tested up to: 3.4.1
|
7 |
+
Stable tag: 1.0
|
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 Admin Panels. Or Site Home.
|
12 |
+
|
13 |
+
== Description ==
|
14 |
+
|
15 |
+
Allows the Administrator to specify which Theme will be used on specific Pages, Posts, Admin Panels or Site Home. Also allows a Theme to be specified for All Pages, All Posts or All Admin Panel Pages. In turn, even when a Theme is specified for All Pages, a different Theme can still be specified for specific Pages.
|
16 |
+
|
17 |
+
If a Theme is not specified for a Page, Post, Admin Panel, Site Home or other WordPress-displayed web page (e.g. - Category display), the **Current Theme** specified in **Appearance-Themes** on the Admin panels will be used.
|
18 |
+
|
19 |
+
When selecting a Theme for Site Home or all or specific Pages, Posts or Admin Panels, 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.
|
20 |
+
|
21 |
+
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 Theme that you have defined through the standard WordPress Appearance-Themes Admin panel.
|
22 |
+
|
23 |
+
**Limitation**: This plugin does not currently support Theme usage that involves the stylesheet and template names not being the same.
|
24 |
+
|
25 |
+
**Note**: Few, if any, Themes alter the appearance of the Admin Panel Pages. This Plugin hopes to change that. For those who cannot wait, there are Plugins, most of which call themselves Themes but are listed in the WordPress Plugin Directory, that change the appearance of Admin Panel Pages.
|
26 |
+
|
27 |
+
== Installation ==
|
28 |
+
|
29 |
+
This section describes how to install the plugin and get it working.
|
30 |
+
|
31 |
+
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.
|
32 |
+
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.
|
33 |
+
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.
|
34 |
+
|
35 |
+
== Frequently Asked Questions ==
|
36 |
+
|
37 |
+
= I specified a Theme for an Admin Page, but I don't see any change. What happened? =
|
38 |
+
|
39 |
+
The Theme you specified leaves the Admin panels unaltered. Most Themes do not change the appearance of Admin panels.
|
40 |
+
|
41 |
+
= I added a new entry but why doesn't it appear in the list of entries? =
|
42 |
+
|
43 |
+
If you add an entry that already exists, it merely replaces the previous entry.
|
44 |
+
|
45 |
+
= How can I change the Theme for an entry? =
|
46 |
+
|
47 |
+
Simply add the entry again, with the new Theme. It will replace the previous entry.
|
48 |
+
|
49 |
+
== Screenshots ==
|
50 |
+
|
51 |
+
1. Plugin's Admin Page when first installed
|
52 |
+
2. Plugin's Admin Page with entries added
|
53 |
+
|
54 |
+
== Changelog ==
|
55 |
+
|
56 |
+
= 1.0 =
|
57 |
+
* Make plugin conform to WordPress plugin repository standards.
|
58 |
+
* Beta testing completed.
|
59 |
+
|
60 |
+
== Upgrade Notice ==
|
61 |
+
|
62 |
+
= 1.0 =
|
63 |
+
Beta version 0.9 had not been tested when installed from the WordPress Plugin Repository
|
screenshot-1.png
ADDED
Binary file
|
screenshot-2.png
ADDED
Binary file
|
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 |
+
?>
|