Multiple Themes - Version 2.0

Version Description

  • Address pecularities of wp_make_link_relative() related to root-based WordPress sites using Permalinks
Download this release

Release Info

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

Version 2.0

includes/admin.php ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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> &raquo; All Pages</li>
32
+ <li> &raquo; All Posts</li>
33
+ <li> &raquo; All Admin Pages</li>
34
+ <li> &raquo; The Site Home</li>
35
+ <li> &raquo; A Specific Page</li>
36
+ <li> &raquo; A Specific Post</li>
37
+ <li> &raquo; 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' /> &nbsp; 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
+ if ( isset ( $input['del_entry'] ) ) {
174
+ foreach ( $input['del_entry'] as $del_entry ) {
175
+ unset( $ids[$del_entry] );
176
+ }
177
+ }
178
+
179
+ // This section needs error-checking for a bad URL pasted by Admin
180
+ $url = trim( $input['add_path_id'] );
181
+ if ( !empty( $url ) ) {
182
+ extract( jr_mt_url_to_id( $url ) );
183
+ if ( $id === FALSE ) {
184
+ $key = $page_url;
185
+ } else {
186
+ $key = $id;
187
+ }
188
+ $ids[$key] = array(
189
+ 'theme' => $input['add_theme'],
190
+ 'type' => $type,
191
+ 'id' => $id,
192
+ 'page_url' => $page_url,
193
+ 'rel_url' => $rel_url,
194
+ 'url' => $url
195
+ );
196
+ }
197
+ $valid['ids'] = $ids;
198
+ return $valid;
199
+ }
200
+
201
+ // Add Link to the plugin's entry on the Admin "Plugins" Page, for easy access
202
+ global $jr_mt_plugin_basename;
203
+ add_filter( "plugin_action_links_$jr_mt_plugin_basename", 'jr_mt_plugin_action_links', 10, 1 );
204
+
205
+ /**
206
+ * Creates Settings entry right on the Plugins Page entry.
207
+ *
208
+ * Helps the user understand where to go immediately upon Activation of the Plugin
209
+ * by creating entries on the Plugins page, right beside Deactivate and Edit.
210
+ *
211
+ * @param array $links Existing links for our Plugin, supplied by WordPress
212
+ * @param string $file Name of Plugin currently being processed
213
+ * @return string $links Updated set of links for our Plugin
214
+ */
215
+ function jr_mt_plugin_action_links( $links ) {
216
+ // The "page=" query string value must be equal to the slug
217
+ // of the Settings admin page.
218
+ array_unshift( $links, '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=jr_mt_settings' . '">Settings</a>' );
219
+ return $links;
220
+ }
221
+
222
+ function jr_mt_themes_field( $field_name, $theme_name, $setting ) {
223
+ echo "<select id='$field_name' name='$setting" . "[$field_name]' size='1'>";
224
+ if ( empty( $theme_name ) ) {
225
+ $selected = 'selected="selected"';
226
+ } else {
227
+ $selected = '';
228
+ }
229
+ echo "<option value='' $selected></option>";
230
+ foreach ( wp_get_themes() as $folder => $theme_obj ) {
231
+ if ( $theme_name == $folder ) {
232
+ $selected = 'selected="selected"';
233
+ } else {
234
+ $selected = '';
235
+ }
236
+ $name = $theme_obj->Name;
237
+ echo "<option value='$folder' $selected>$name</option>";
238
+ }
239
+ echo '</select>' . PHP_EOL;
240
+ }
241
+
242
+ ?>
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,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( parse_url( get_home_url(), PHP_URL_PATH ), $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( 'http://' . $_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: 2.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,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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: 2.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
+ **Major bug solved in Version 2.0**
16
+
17
+ 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.
18
+
19
+ 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.
20
+
21
+ 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.
22
+
23
+ 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.
24
+
25
+ **Limitation**: This plugin does not currently support Theme usage that involves the stylesheet and template names not being the same.
26
+
27
+ **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.
28
+
29
+ == Installation ==
30
+
31
+ This section describes how to install the plugin and get it working.
32
+
33
+ 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.
34
+ 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.
35
+ 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.
36
+
37
+ == Frequently Asked Questions ==
38
+
39
+ = I specified a Theme for an Admin Page, but I don't see any change. What happened? =
40
+
41
+ The Theme you specified leaves the Admin panels unaltered. Most Themes do not change the appearance of Admin panels.
42
+
43
+ = I added a new entry but why doesn't it appear in the list of entries? =
44
+
45
+ If you add an entry that already exists, it merely replaces the previous entry.
46
+
47
+ = How can I change the Theme for an entry? =
48
+
49
+ Simply add the entry again, with the new Theme. It will replace the previous entry.
50
+
51
+ == Screenshots ==
52
+
53
+ 1. Plugin's Admin Page when first installed
54
+ 2. Plugin's Admin Page with entries added
55
+
56
+ == Changelog ==
57
+
58
+ = 2.0 =
59
+ * Address pecularities of wp_make_link_relative() related to root-based WordPress sites using Permalinks
60
+
61
+ = 1.1 =
62
+ * Fix foreach failing on some systems, based on PHP warning level
63
+
64
+ = 1.0 =
65
+ * Make plugin conform to WordPress plugin repository standards.
66
+ * Beta testing completed.
67
+
68
+ == Upgrade Notice ==
69
+
70
+ = 2.0 =
71
+ Selecting Individual Pages and Posts on a WordPress site installed in the root and using Permalinks now works correctly.
72
+
73
+ = 1.1 =
74
+ Eliminate possibility of foreach error message if PHP warning level is set at a high level
75
+
76
+ = 1.0 =
77
+ 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
+ ?>