Version Description
- Correct foreach() error
Download this release
Release Info
Developer | dgewirtz |
Plugin | Multiple Themes |
Version | 4.11.1 |
Comparing to | |
See all releases |
Version 4.11.1
- includes/admin-other.php +26 -0
- includes/admin.php +1155 -0
- includes/functions.php +414 -0
- includes/index.html +0 -0
- includes/old-wp.php +21 -0
- includes/select-theme.php +493 -0
- index.html +0 -0
- jonradio-multiple-themes.php +260 -0
- js/sticky.js +131 -0
- readme.txt +420 -0
- uninstall.php +20 -0
includes/admin-other.php
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Exit if .php file accessed directly
|
3 |
+
if ( !defined( 'ABSPATH' ) ) exit;
|
4 |
+
|
5 |
+
|
6 |
+
// Add Link to the plugin's entry on the Admin "Plugins" Page, for easy access
|
7 |
+
add_filter( 'plugin_action_links_' . jr_mt_plugin_basename(), 'jr_mt_plugin_action_links', 10, 1 );
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Creates Settings entry right on the Plugins Page entry.
|
11 |
+
*
|
12 |
+
* Helps the user understand where to go immediately upon Activation of the Plugin
|
13 |
+
* by creating entries on the Plugins page, right beside Deactivate and Edit.
|
14 |
+
*
|
15 |
+
* @param array $links Existing links for our Plugin, supplied by WordPress
|
16 |
+
* @param string $file Name of Plugin currently being processed
|
17 |
+
* @return string $links Updated set of links for our Plugin
|
18 |
+
*/
|
19 |
+
function jr_mt_plugin_action_links( $links ) {
|
20 |
+
// The "page=" query string value must be equal to the slug
|
21 |
+
// of the Settings admin page.
|
22 |
+
array_push( $links, '<a href="' . get_bloginfo('wpurl') . '/wp-admin/admin.php?page=jr_mt_settings' . '">Settings</a>' );
|
23 |
+
return $links;
|
24 |
+
}
|
25 |
+
|
26 |
+
?>
|
includes/admin.php
ADDED
@@ -0,0 +1,1155 @@
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
// Exit if .php file accessed directly
|
3 |
+
if ( !defined( 'ABSPATH' ) ) exit;
|
4 |
+
|
5 |
+
|
6 |
+
// Admin Page
|
7 |
+
|
8 |
+
require_once( jr_mt_path() . 'includes/admin-other.php' );
|
9 |
+
|
10 |
+
add_action( 'admin_menu', 'jr_mt_admin_hook' );
|
11 |
+
// Runs just before admin_init (below)
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Add Admin Menu item for plugin
|
15 |
+
*
|
16 |
+
* Plugin needs its own Page in the Settings section of the Admin menu.
|
17 |
+
*
|
18 |
+
*/
|
19 |
+
function jr_mt_admin_hook() {
|
20 |
+
// Add Settings Page for this Plugin
|
21 |
+
global $jr_mt_plugin_data;
|
22 |
+
add_theme_page( $jr_mt_plugin_data['Name'], 'Multiple Themes plugin', 'switch_themes', 'jr_mt_settings', 'jr_mt_settings_page' );
|
23 |
+
add_options_page( $jr_mt_plugin_data['Name'], 'Multiple Themes plugin', 'switch_themes', 'jr_mt_settings', 'jr_mt_settings_page' );
|
24 |
+
}
|
25 |
+
|
26 |
+
global $jr_mt_kwvalsep;
|
27 |
+
/* Everything is converted to lower-case, so upper-case letter makes a good keyword-value separator
|
28 |
+
*/
|
29 |
+
$jr_mt_kwvalsep = 'A';
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Settings page for plugin
|
33 |
+
*
|
34 |
+
* Display and Process Settings page for this plugin.
|
35 |
+
*
|
36 |
+
*/
|
37 |
+
function jr_mt_settings_page() {
|
38 |
+
global $jr_mt_plugin_data;
|
39 |
+
$jr_mt_plugin_data = array_merge( $jr_mt_plugin_data, jr_readme() );
|
40 |
+
global $jr_mt_themes_cache;
|
41 |
+
$jr_mt_themes_cache = wp_get_themes();
|
42 |
+
global $jr_mt_plugins_cache;
|
43 |
+
$jr_mt_plugins_cache = get_plugins();
|
44 |
+
add_thickbox();
|
45 |
+
echo '<div class="wrap">';
|
46 |
+
echo '<h2>' . $jr_mt_plugin_data['Name'] . '</h2>';
|
47 |
+
|
48 |
+
// Required because it is only called automatically for Admin Pages in the Settings section
|
49 |
+
settings_errors( 'jr_mt_settings' );
|
50 |
+
|
51 |
+
$theme = wp_get_theme()->Name;
|
52 |
+
global $jr_mt_options_cache;
|
53 |
+
|
54 |
+
$current_wp_version = get_bloginfo( 'version' );
|
55 |
+
|
56 |
+
if ( $jr_mt_plugin_data['read readme'] && version_compare( $current_wp_version, $jr_mt_plugin_data['Tested up to'], '>' ) ) {
|
57 |
+
/* WordPress version is too new:
|
58 |
+
When currently-installed version of Plugin was installed,
|
59 |
+
it did not support currently-installed version of WordPress.
|
60 |
+
So, check if a newer version of plugin is available. */
|
61 |
+
$current = FALSE;
|
62 |
+
// Check if latest version of the plugin supports this version of WordPress
|
63 |
+
if ( !function_exists( 'plugins_api' ) ) {
|
64 |
+
require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
|
65 |
+
}
|
66 |
+
$directory = plugins_api( 'plugin_information', array( 'slug' => $jr_mt_plugin_data['slug'],
|
67 |
+
'fields' => array( 'download_link' => TRUE,
|
68 |
+
'tested' => TRUE,
|
69 |
+
'version' => TRUE,
|
70 |
+
'error_data' => TRUE,
|
71 |
+
'tags' => FALSE,
|
72 |
+
'compatibility' => FALSE,
|
73 |
+
'sections' => FALSE
|
74 |
+
)
|
75 |
+
) );
|
76 |
+
if ( property_exists( $directory, 'errors' ) && ( $directory->error_data->plugins_api_failed == 'N;' ) ) {
|
77 |
+
// Plugin not found in WordPress Directory
|
78 |
+
echo '<h3>Warnings</h3><p>Here is the problem:<ul><li> » This Plugin (' . $jr_mt_plugin_data['Name']
|
79 |
+
. ') has not been tested with the version of WordPress you are currently running: ' . $current_wp_version
|
80 |
+
. '.</li><li> » This Plugin could not be found in the WordPress Plugin Directory. '
|
81 |
+
. 'If you are sure it should be there, the WordPress Plugin Directory may be currently unavailable or inaccessible from your web server.</li></ul></p>'
|
82 |
+
. '<p>The plugin will probably still work with your newer version of WordPress, but you need to be aware of the issue.</p>';
|
83 |
+
} else {
|
84 |
+
if ( version_compare( $current_wp_version, $directory->tested, '>' ) ) {
|
85 |
+
// Latest version of readme.txt for latest version of Plugin indicates that Plugin has not yet been tested for this version of WordPress
|
86 |
+
echo '<h3>Warning</h3><p>Here is the problem:<ul><li> » This Plugin (' . $jr_mt_plugin_data['Name']
|
87 |
+
. ') has not been tested with the version of WordPress you are currently running: ' . $current_wp_version
|
88 |
+
. '.</li></ul></p>'
|
89 |
+
. '<p>The plugin has been tested with Version ' . $directory->tested . ' of WordPress and '
|
90 |
+
. 'will probably still work with your newer version of WordPress, but you need to be aware of the issue.</p>';
|
91 |
+
} else {
|
92 |
+
if ( version_compare( $jr_mt_plugin_data['Version'], $directory->version, '=' ) ) {
|
93 |
+
/* The latest version of the Plugin has been installed,
|
94 |
+
but the readme.txt has been updated in the WordPress Plugin Directory
|
95 |
+
to indicate that it now supports the installed version of WordPress.
|
96 |
+
|
97 |
+
Latest version of Plugin has already been installed, but readme.txt is out of date,
|
98 |
+
so update readme.txt. ...if you can
|
99 |
+
*/
|
100 |
+
|
101 |
+
$errmsg_before = '<h3>Warning</h3><p>Here is the problem:<ul><li> » This version (' . $jr_mt_plugin_data['Version']
|
102 |
+
. ') of this Plugin (' . $jr_mt_plugin_data['Name']
|
103 |
+
. ') has been tested with the version of WordPress you are currently running (' . $current_wp_version
|
104 |
+
. '), but</li><li> » The currently installed readme.txt file for this plugin is out of date,'
|
105 |
+
. '</li><li> » The attempt to update the readme.txt from the WordPress Plugin Repository failed, and'
|
106 |
+
. '</li><li> » The specific error is: ';
|
107 |
+
$errmsg_after = '</li></ul></p>'
|
108 |
+
. '<p>Another attempt will be made to update readme.txt each time this Settings page is displayed.'
|
109 |
+
. ' Nonetheless, this plugin should work properly even if readme.txt is out of date.</p>';
|
110 |
+
|
111 |
+
if ( is_wp_error( $file_name = download_url( $directory->download_link ) ) ) {
|
112 |
+
// Error
|
113 |
+
echo $errmsg_before . 'The plugin failed to completely download from the WordPress Repository with 300 seconds' . $errmsg_after;
|
114 |
+
} else {
|
115 |
+
if ( function_exists( 'zip_open' ) ) {
|
116 |
+
if ( is_int( $resource_handle = zip_open( $file_name ) ) ) {
|
117 |
+
// Error
|
118 |
+
echo $errmsg_before
|
119 |
+
. "php function zip_open error number $resource_handle while attempting to open the plugin's"
|
120 |
+
. 'compressed .zip file successfully downloaded from the WordPress Plugin Repository'
|
121 |
+
. $errmsg_after;
|
122 |
+
} else {
|
123 |
+
$find_readme = TRUE;
|
124 |
+
while ( $find_readme && ( FALSE !== $dir_ent = zip_read( $resource_handle ) ) ) {
|
125 |
+
if ( is_int( $dir_ent ) ) {
|
126 |
+
// Error code
|
127 |
+
echo $errmsg_before
|
128 |
+
. "php function zip_read error number $dir_ent while attempting to read the plugin's"
|
129 |
+
. ' compressed .zip file successfully downloaded from the WordPress Plugin Repository'
|
130 |
+
. $errmsg_after;
|
131 |
+
// Get out of While loop
|
132 |
+
$find_readme = FALSE;
|
133 |
+
} else {
|
134 |
+
// Wait until the While loop gets to the readme.txt entry in the Plugin's Zip file
|
135 |
+
if ( zip_entry_name( $dir_ent ) == $jr_mt_plugin_data['slug'] . '/readme.txt' ) {
|
136 |
+
if ( FALSE === zip_entry_open( $resource_handle, $dir_ent, 'rb' ) ) {
|
137 |
+
// Error
|
138 |
+
echo $errmsg_before
|
139 |
+
. 'php function zip_entry_open failed to open readme.txt file compressed within plugin .zip file in WordPress Repository'
|
140 |
+
. $errmsg_after;
|
141 |
+
} else {
|
142 |
+
$filesize = zip_entry_filesize( $dir_ent );
|
143 |
+
if ( !is_int( $filesize ) || ( $filesize < 100 ) ) {
|
144 |
+
// Error
|
145 |
+
echo $errmsg_before
|
146 |
+
. 'Size, in bytes, of readme.txt file is being incorrectly reported by php function zip_entry_filesize as '
|
147 |
+
. var_export( $filesize, TRUE )
|
148 |
+
. $errmsg_after;
|
149 |
+
} else {
|
150 |
+
$readme_content = zip_entry_read( $dir_ent, $filesize );
|
151 |
+
if ( ( $readme_content === FALSE ) || ( $readme_content === '' ) ) {
|
152 |
+
// Error
|
153 |
+
echo $errmsg_before
|
154 |
+
. 'php function zip_entry_read failed to read readme.txt file compressed within plugin .zip file in WordPress Repository'
|
155 |
+
. $errmsg_after;
|
156 |
+
} else {
|
157 |
+
if ( FALSE === zip_entry_close( $dir_ent ) ) {
|
158 |
+
// Error
|
159 |
+
echo $errmsg_before
|
160 |
+
. 'php function zip_entry_close failed to close readme.txt file compressed within plugin .zip file in WordPress Repository'
|
161 |
+
. $errmsg_after;
|
162 |
+
} else {
|
163 |
+
// Alternate: file_put_contents( jr_mt_path() . 'readme.txt', $readme_content );
|
164 |
+
$write_return = jr_filesystem_text_write( $readme_content, 'readme.txt', jr_mt_path() );
|
165 |
+
if ( is_wp_error( $write_return ) || ( FALSE === $write_return ) ) {
|
166 |
+
// Error
|
167 |
+
echo $errmsg_before
|
168 |
+
. 'WP_filesystem failed to store readme.txt file as part of download/update process from WordPress Repository'
|
169 |
+
. $errmsg_after;
|
170 |
+
}
|
171 |
+
}
|
172 |
+
}
|
173 |
+
}
|
174 |
+
}
|
175 |
+
// Get out of While loop because we have found and processed readme.txt
|
176 |
+
$find_readme = FALSE;
|
177 |
+
}
|
178 |
+
}
|
179 |
+
}
|
180 |
+
zip_close( $resource_handle );
|
181 |
+
}
|
182 |
+
} else {
|
183 |
+
echo $errmsg_before
|
184 |
+
. "php zip_open function is not defined, so readme.txt could not be updated from WordPress Plugin Repository"
|
185 |
+
. $errmsg_after;
|
186 |
+
}
|
187 |
+
// Delete temporary download file
|
188 |
+
if ( !unlink( $file_name ) ) {
|
189 |
+
echo $errmsg_before
|
190 |
+
. "php unlink function failed to delete downloaded readme.txt in temporary download file $file_name"
|
191 |
+
. $errmsg_after;
|
192 |
+
}
|
193 |
+
}
|
194 |
+
$current = TRUE;
|
195 |
+
} else {
|
196 |
+
// Recommend updating Plugin to latest version which supports the version of WordPress being run,
|
197 |
+
// but the currently-installed version of the Plugin does not.
|
198 |
+
echo '<h3>Warning</h3><p>This plugin is out of date and should be updated for performance and reliability reasons.'
|
199 |
+
. ' Plugin updates are shown on the Plugins-Installed Plugins page and the Dashboard-Updates page here in the Admin panels.</p>';
|
200 |
+
}
|
201 |
+
}
|
202 |
+
}
|
203 |
+
} else {
|
204 |
+
// Currently-installed version of Plugin supports currently-installed version of WordPress
|
205 |
+
$current = TRUE;
|
206 |
+
}
|
207 |
+
|
208 |
+
global $jr_mt_plugins_cache;
|
209 |
+
|
210 |
+
$compatible = TRUE;
|
211 |
+
|
212 |
+
// Check for incompatible plugins that have been activated: BuddyPress and Theme Test Drive
|
213 |
+
global $jr_mt_incompat_plugins;
|
214 |
+
foreach ( $jr_mt_plugins_cache as $rel_path => $plugin_data ) {
|
215 |
+
if ( in_array( $plugin_data['Name'], $jr_mt_incompat_plugins ) && is_plugin_active( $rel_path ) ) {
|
216 |
+
if ( $compatible ) {
|
217 |
+
echo '<h3>Plugin Conflict Error Detected</h3>';
|
218 |
+
$compatible = FALSE;
|
219 |
+
}
|
220 |
+
echo '<p>This Plugin (' . $jr_mt_plugin_data['Name'] . ') cannot be used when the <b>' . $plugin_data['Name']
|
221 |
+
. '</b> plugin is Activated. If you wish to use the ' . $jr_mt_plugin_data['Name']
|
222 |
+
. ' plugin, please deactivate the ' . $plugin_data['Name']
|
223 |
+
. ' plugin (not just when using this Settings page, but whenever the '
|
224 |
+
. $jr_mt_plugin_data['Name'] . ' plugin is activated).</p>';
|
225 |
+
}
|
226 |
+
}
|
227 |
+
|
228 |
+
if ( $compatible ) {
|
229 |
+
?>
|
230 |
+
<h3>Overview</h3>
|
231 |
+
<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.
|
232 |
+
You can choose from any of the <b>Available Themes</b> listed on the Appearance-Themes Admin panel for:
|
233 |
+
<ul>
|
234 |
+
<li> » All Pages</li>
|
235 |
+
<li> » All Posts</li>
|
236 |
+
<li> » Everything (Advanced Settings)</li>
|
237 |
+
<li> » The Site Home</li>
|
238 |
+
<li> » A Specific Page</li>
|
239 |
+
<li> » A Specific Post</li>
|
240 |
+
<li> » Any other non-Admin page that has its own Permalink; for example, a specific Archive or Category page</li>
|
241 |
+
<li> » A Specific Query Keyword, or Keyword/Value pair, in any URL (<code>?keyword=value</code> or <code>&keyword=value</code>)</li>
|
242 |
+
<li> » All non-Admin pages after a Specific Query Keyword/Value pair is specified in any URL (Advanced Settings)</li>
|
243 |
+
</ul>
|
244 |
+
</p>
|
245 |
+
<h3>Important Notes</h3>
|
246 |
+
<?php
|
247 |
+
if ( function_exists('is_multisite') && is_multisite() ) {
|
248 |
+
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.";
|
249 |
+
}
|
250 |
+
echo '<p>';
|
251 |
+
echo "The Current Theme, defined to WordPress in Appearance-Themes admin panel, is <b>$theme</b>.";
|
252 |
+
$settings = get_option( 'jr_mt_settings' );
|
253 |
+
if ( trim( $settings['current'] ) ) {
|
254 |
+
echo " But it is being overridden in Advanced Settings (see below), which set the plugin's default Theme to <b>";
|
255 |
+
echo wp_get_theme( $settings['current'] )->Name;
|
256 |
+
echo '</b>. You will not normally need to specify this default Theme in any of the other Settings on this page, though you will need to specify the WordPress Current Theme wherever you want it appear. Or, if you specify, in the Advanced Settings section, a different Theme for All Pages, All Posts or Everything, and wish to use the default Theme for one or more specific Pages, Posts or other non-Admin pages.';
|
257 |
+
} else {
|
258 |
+
echo ' You will not normally need to specify it in any of the Settings on this page. The only exception would be if you specify, in the Advanced Settings section, a different Theme for All Pages, All Posts or Everything, and wish to use the Current Theme for one or more specific Pages, Posts or other non-Admin pages.';
|
259 |
+
}
|
260 |
+
echo '</p>';
|
261 |
+
if ( $jr_mt_plugin_data['read readme'] ) {
|
262 |
+
if ( $current ) {
|
263 |
+
echo '<p>This Plugin (' . $jr_mt_plugin_data['Name'] . ') has been tested with the version of WordPress you are currently running: '
|
264 |
+
. $current_wp_version . '</p>';
|
265 |
+
}
|
266 |
+
} else {
|
267 |
+
echo '<p>Compatibility checks could not be done because the plugin was unable to read its readme.txt file, likely a user/permissions hosting issue.</p>';
|
268 |
+
}
|
269 |
+
if ( jr_mt_plugin_update_available() ) {
|
270 |
+
echo '<p>A new version of this Plugin (' . $jr_mt_plugin_data['Name'] . ') is available from the WordPress Repository.'
|
271 |
+
. ' We strongly recommend updating ASAP because new versions fix problems that users like yourself have reported to us.'
|
272 |
+
. ' <a class="thickbox" title="' . $jr_mt_plugin_data['Name'] . '" href="' . network_admin_url()
|
273 |
+
. 'plugin-install.php?tab=plugin-information&plugin=' . $jr_mt_plugin_data['slug']
|
274 |
+
. '§ion=changelog&TB_iframe=true&width=640&height=768">Click here</a> for more details.</p>';
|
275 |
+
}
|
276 |
+
echo '<hr /><form action="options.php" method="POST">';
|
277 |
+
|
278 |
+
// Plugin Settings are displayed and entered here:
|
279 |
+
settings_fields( 'jr_mt_settings' );
|
280 |
+
do_settings_sections( 'jr_mt_settings_page' );
|
281 |
+
echo '<p><input name="save" type="submit" value="Save All Changes" class="button-primary" /></p></form>';
|
282 |
+
}
|
283 |
+
|
284 |
+
echo '<hr /><h3>System Information</h3><p>You are currently running:<ul>';
|
285 |
+
echo "<li> » The {$jr_mt_plugin_data['Name']} plugin Version {$jr_mt_plugin_data['Version']}</li>";
|
286 |
+
echo "<li> »» The Path to the plugin's directory is <code>" . rtrim( jr_mt_path(), '/' ) . '</code></li>';
|
287 |
+
echo "<li> »» The URL to the plugin's directory is <code>" . plugins_url() . "/{$jr_mt_plugin_data['slug']}</code></li>";
|
288 |
+
echo "<li> » WordPress Version $current_wp_version</li>";
|
289 |
+
echo '<li> »» WordPress language is set to ' , get_bloginfo( 'language' ) . '</li>';
|
290 |
+
echo '<li> » ' . php_uname( 's' ) . ' operating system, Release/Version ' . php_uname( 'r' ) . ' / ' . php_uname( 'v' ) . '</li>';
|
291 |
+
echo '<li> » ' . php_uname( 'm' ) . ' computer hardware</li>';
|
292 |
+
echo '<li> » Host name ' . php_uname( 'n' ) . '</li>';
|
293 |
+
echo '<li> » php Version ' . phpversion() . '</li>';
|
294 |
+
echo '<li> »» php memory_limit ' . ini_get('memory_limit') . '</li>';
|
295 |
+
echo '<li> » Zend engine Version ' . zend_version() . '</li>';
|
296 |
+
echo '<li> » Web Server software is ' . getenv( 'SERVER_SOFTWARE' ) . '</li>';
|
297 |
+
if ( function_exists( 'apache_get_version' ) && ( FALSE !== $apache = apache_get_version() ) ) {
|
298 |
+
echo "<li> »» Apache Version $apache</li>";
|
299 |
+
}
|
300 |
+
global $wpdb;
|
301 |
+
echo '<li> » MySQL Version ' . $wpdb->get_var( 'SELECT VERSION();', 0, 0 ) . '</li>';
|
302 |
+
|
303 |
+
echo '</ul></p>';
|
304 |
+
}
|
305 |
+
|
306 |
+
add_action( 'admin_init', 'jr_mt_admin_init' );
|
307 |
+
|
308 |
+
/**
|
309 |
+
* Register and define the settings
|
310 |
+
*
|
311 |
+
* Everything to be stored and/or can be set by the user
|
312 |
+
*
|
313 |
+
*/
|
314 |
+
function jr_mt_admin_init() {
|
315 |
+
register_setting( 'jr_mt_settings', 'jr_mt_settings', 'jr_mt_validate_settings' );
|
316 |
+
$settings = get_option( 'jr_mt_settings' );
|
317 |
+
if ( !empty( $settings['ids']) || !empty( $settings['query'] ) ) {
|
318 |
+
add_settings_section( 'jr_mt_delete_settings_section',
|
319 |
+
'Current Theme Selection Entries',
|
320 |
+
'jr_mt_delete_settings_expl',
|
321 |
+
'jr_mt_settings_page'
|
322 |
+
);
|
323 |
+
if ( !empty( $settings['ids'] ) ) {
|
324 |
+
add_settings_field( 'del_entry', 'Page/Post/Prefix Entries:', 'jr_mt_echo_delete_entry', 'jr_mt_settings_page', 'jr_mt_delete_settings_section' );
|
325 |
+
}
|
326 |
+
if ( !empty( $settings['query'] ) ) {
|
327 |
+
add_settings_field( 'del_query_entry', 'Query Keyword Entries:', 'jr_mt_echo_delete_query_entry', 'jr_mt_settings_page', 'jr_mt_delete_settings_section' );
|
328 |
+
}
|
329 |
+
}
|
330 |
+
add_settings_section( 'jr_mt_all_settings_section',
|
331 |
+
'<input name="save" type="submit" value="Save All Changes" class="button-primary" /></h3><h3>For All Pages, All Posts and/or Site Home',
|
332 |
+
'jr_mt_all_settings_expl',
|
333 |
+
'jr_mt_settings_page'
|
334 |
+
);
|
335 |
+
$suffix = array(
|
336 |
+
'Pages' => '<br />(Pages created with Add Page)',
|
337 |
+
'Posts' => ''
|
338 |
+
);
|
339 |
+
foreach ( array( 'Pages', 'Posts' ) as $thing ) {
|
340 |
+
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',
|
341 |
+
array( 'thing' => $thing ) );
|
342 |
+
}
|
343 |
+
add_settings_field( 'site_home',
|
344 |
+
'Select Theme for Site Home<br />(' . get_home_url() . ')',
|
345 |
+
'jr_mt_echo_site_home',
|
346 |
+
'jr_mt_settings_page',
|
347 |
+
'jr_mt_all_settings_section'
|
348 |
+
);
|
349 |
+
add_settings_section( 'jr_mt_single_settings_section',
|
350 |
+
'For An Individual Page, Post or other non-Admin page;<br />or a group of pages, specified by URL Prefix, optionally with Asterisk(s)',
|
351 |
+
'jr_mt_single_settings_expl',
|
352 |
+
'jr_mt_settings_page'
|
353 |
+
);
|
354 |
+
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' );
|
355 |
+
add_settings_field( 'add_theme', 'Theme', 'jr_mt_echo_add_theme', 'jr_mt_settings_page', 'jr_mt_single_settings_section' );
|
356 |
+
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' );
|
357 |
+
add_settings_section( 'jr_mt_querykw_section',
|
358 |
+
'For A Query Keyword on any Page, Post or other non-Admin page',
|
359 |
+
'jr_mt_querykw_expl',
|
360 |
+
'jr_mt_settings_page'
|
361 |
+
);
|
362 |
+
add_settings_field( 'add_querykw_theme', 'Theme', 'jr_mt_echo_add_querykw_theme', 'jr_mt_settings_page', 'jr_mt_querykw_section' );
|
363 |
+
add_settings_field( 'add_querykw_keyword', 'Query Keyword', 'jr_mt_echo_add_querykw_keyword', 'jr_mt_settings_page', 'jr_mt_querykw_section' );
|
364 |
+
add_settings_section( 'jr_mt_query_section',
|
365 |
+
'For A Query Keyword=Value on any Page, Post or other non-Admin page',
|
366 |
+
'jr_mt_query_expl',
|
367 |
+
'jr_mt_settings_page'
|
368 |
+
);
|
369 |
+
add_settings_field( 'add_query_theme', 'Theme', 'jr_mt_echo_add_query_theme', 'jr_mt_settings_page', 'jr_mt_query_section' );
|
370 |
+
add_settings_field( 'add_query_keyword', 'Query Keyword', 'jr_mt_echo_add_query_keyword', 'jr_mt_settings_page', 'jr_mt_query_section' );
|
371 |
+
add_settings_field( 'add_query_value', 'Query Value', 'jr_mt_echo_add_query_value', 'jr_mt_settings_page', 'jr_mt_query_section' );
|
372 |
+
add_settings_section( 'jr_mt_sticky_section',
|
373 |
+
'<input name="save" type="submit" value="Save All Changes" class="button-primary" /></h3><h2>Advanced Settings</h2><p><b>Warning:</b> As the name of this section implies, Advanced Settings should be fully understood or they may surprise you with unintended consequences, so please be careful.</p><h3>Sticky and Override',
|
374 |
+
'jr_mt_sticky_expl',
|
375 |
+
'jr_mt_settings_page'
|
376 |
+
);
|
377 |
+
add_settings_field( 'query_present', 'When to add Sticky Query to a URL', 'jr_mt_echo_query_present', 'jr_mt_settings_page', 'jr_mt_sticky_section' );
|
378 |
+
add_settings_field( 'sticky_query', 'Keyword=Value Entries:', 'jr_mt_echo_sticky_query_entry', 'jr_mt_settings_page', 'jr_mt_sticky_section' );
|
379 |
+
add_settings_section( 'jr_mt_everything_section',
|
380 |
+
'Theme for Everything',
|
381 |
+
'jr_mt_everything_expl',
|
382 |
+
'jr_mt_settings_page'
|
383 |
+
);
|
384 |
+
add_settings_field( 'current',
|
385 |
+
'Select Theme for Everything, to Override WordPress Current Theme (<b>' . wp_get_theme()->Name . '</b>)',
|
386 |
+
'jr_mt_echo_current',
|
387 |
+
'jr_mt_settings_page',
|
388 |
+
'jr_mt_everything_section'
|
389 |
+
);
|
390 |
+
}
|
391 |
+
|
392 |
+
/**
|
393 |
+
* Section text for Section2
|
394 |
+
*
|
395 |
+
* Display an explanation of this Section
|
396 |
+
*
|
397 |
+
*/
|
398 |
+
function jr_mt_delete_settings_expl() {
|
399 |
+
?>
|
400 |
+
<p>
|
401 |
+
In this section, all entries are displayed for Themes selected for individual Pages, Posts
|
402 |
+
and any other non-Admin pages that have their own Permalink; for example, specific Archive or Category pages.
|
403 |
+
Or groups of Pages, Posts or any other non-Admin pages that share the same <b>URL Prefix</b>
|
404 |
+
or <b>Query Keyword</b> (<code>?keyword=value</code> or <code>&keyword=value</code>).
|
405 |
+
</p>
|
406 |
+
<p>
|
407 |
+
You can delete any of these entries by filling in the check box beside each one
|
408 |
+
and clicking the <b>Save Changes</b> button.
|
409 |
+
To change the Theme for an entry, add the same entry with a different Theme in one of the sections below this one.</p>
|
410 |
+
|
411 |
+
<?php
|
412 |
+
}
|
413 |
+
|
414 |
+
function jr_mt_echo_delete_entry() {
|
415 |
+
$settings = get_option( 'jr_mt_settings' );
|
416 |
+
$first = TRUE;
|
417 |
+
foreach ( $settings['ids'] as $path_id => $opt_array ) {
|
418 |
+
if ( $first ) {
|
419 |
+
$first = FALSE;
|
420 |
+
} else {
|
421 |
+
echo '<br />';
|
422 |
+
}
|
423 |
+
echo "Delete <input type='checkbox' id='del_entry' name='jr_mt_settings[del_entry][]' value='$path_id' /> Theme="
|
424 |
+
. wp_get_theme( $opt_array['theme'] )->Name . '; ';
|
425 |
+
if ( $path_id == '' ) {
|
426 |
+
echo 'Site=<a href="' . get_home_url() . '" target="_blank">Home</a>';
|
427 |
+
} else {
|
428 |
+
switch ( $opt_array['type'] ) {
|
429 |
+
case '*':
|
430 |
+
echo 'Prefix*=<a href="' . get_home_url() . "/$path_id" . '" target="_blank">' . "$path_id</a>";
|
431 |
+
break;
|
432 |
+
case 'prefix':
|
433 |
+
echo 'Prefix=<a href="' . get_home_url() . "/$path_id" . '" target="_blank">' . "$path_id</a>";
|
434 |
+
break;
|
435 |
+
case 'cat':
|
436 |
+
echo 'Category=<a href="' . get_home_url() . '/?cat=' . $opt_array['id'] . '" target="_blank">' . get_cat_name( $opt_array['id'] ) . '</a>';
|
437 |
+
break;
|
438 |
+
case 'archive':
|
439 |
+
echo 'Archive=<a href="' . get_home_url() . '/?m=' . $opt_array['id'] . '" target="_blank">' . $opt_array['id'] . '</a>';
|
440 |
+
break;
|
441 |
+
default:
|
442 |
+
$p_array = get_posts( array( 'post_type' => 'any', 'include' => array( $path_id ) ) );
|
443 |
+
if ( empty( $p_array ) ) {
|
444 |
+
if ( $opt_array['type'] == 'admin' ) {
|
445 |
+
echo 'Admin=<a href="' . get_home_url() . '/' . $opt_array['rel_url'] . '" target="_blank">' . "$path_id</a>";
|
446 |
+
} else {
|
447 |
+
echo 'Path=<a href="' . get_home_url() . "/$path_id" . '" target="_blank">' . "$path_id</a>";
|
448 |
+
}
|
449 |
+
} else {
|
450 |
+
echo ucfirst( $p_array[0]->post_type ) . '=<a href="' . get_permalink( $path_id ) . '" target="_blank">' . $p_array[0]->post_title . '</a>';
|
451 |
+
}
|
452 |
+
}
|
453 |
+
}
|
454 |
+
}
|
455 |
+
}
|
456 |
+
|
457 |
+
function jr_mt_echo_delete_query_entry() {
|
458 |
+
global $jr_mt_kwvalsep;
|
459 |
+
$settings = get_option( 'jr_mt_settings' );
|
460 |
+
$three_dots = '…';
|
461 |
+
$first = TRUE;
|
462 |
+
foreach ( $settings['query'] as $keyword => $value_array ) {
|
463 |
+
foreach ( $value_array as $value => $theme ) {
|
464 |
+
if ( $first ) {
|
465 |
+
$first = FALSE;
|
466 |
+
} else {
|
467 |
+
echo '<br />';
|
468 |
+
}
|
469 |
+
echo "Delete <input type='checkbox' id='del_query_entry' name='jr_mt_settings[del_query_entry][]' value='$keyword$jr_mt_kwvalsep$value' /> Theme="
|
470 |
+
. wp_get_theme( $theme )->Name . '; '
|
471 |
+
. 'Query='
|
472 |
+
. '<code>'
|
473 |
+
. trim( get_home_url(), '\ /' )
|
474 |
+
. "/</code>$three_dots<code>/?"
|
475 |
+
. "<b><input type='text' readonly='readonly' disable='disabled' name='jr_mt_delkw' value='$keyword' size='"
|
476 |
+
. jr_mt_strlen( $keyword )
|
477 |
+
. "' /></b>"
|
478 |
+
. '=';
|
479 |
+
if ( '*' === $value ) {
|
480 |
+
echo '</code>' . $three_dots;
|
481 |
+
} else {
|
482 |
+
echo "<b><input type='text' readonly='readonly' disable='disabled' name='jr_mt_delkwval' value='$value' size='"
|
483 |
+
. jr_mt_strlen( $value )
|
484 |
+
. "' /></b></code>";
|
485 |
+
}
|
486 |
+
}
|
487 |
+
}
|
488 |
+
}
|
489 |
+
|
490 |
+
/**
|
491 |
+
* Section text for Section1
|
492 |
+
*
|
493 |
+
* Display an explanation of this Section
|
494 |
+
*
|
495 |
+
*/
|
496 |
+
function jr_mt_all_settings_expl() {
|
497 |
+
?>
|
498 |
+
<p>
|
499 |
+
In this section, you can select a different Theme for All Pages, All Posts and/or Site Home.
|
500 |
+
To remove a previously selected Theme, select the blank entry from the drop-down list.
|
501 |
+
</p>
|
502 |
+
<p>
|
503 |
+
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
|
504 |
+
any other non-Admin pages that have their own Permalink; for example, specific Archive or Category pages.
|
505 |
+
Or groups of Pages, Posts or any other non-Admin pages that share the same URL Prefix.
|
506 |
+
</p>
|
507 |
+
<p>
|
508 |
+
There is also a Query Keyword section
|
509 |
+
farther down this Settings page
|
510 |
+
that allows
|
511 |
+
you to select a Theme to use whenever a specified
|
512 |
+
Query Keyword (<code>?keyword=value</code> or <code>&keyword=value</code>)
|
513 |
+
appears in the URL of any Page, Post or other non-Admin page.
|
514 |
+
</p>
|
515 |
+
<?php
|
516 |
+
}
|
517 |
+
|
518 |
+
function jr_mt_echo_all_things( $thing ) {
|
519 |
+
$settings = get_option( 'jr_mt_settings' );
|
520 |
+
$field = 'all_' . strtolower( $thing['thing'] );
|
521 |
+
jr_mt_themes_field( $field, $settings[$field], 'jr_mt_settings', TRUE );
|
522 |
+
}
|
523 |
+
|
524 |
+
function jr_mt_echo_site_home() {
|
525 |
+
$settings = get_option( 'jr_mt_settings' );
|
526 |
+
jr_mt_themes_field( 'site_home', $settings['site_home'], 'jr_mt_settings', FALSE );
|
527 |
+
}
|
528 |
+
|
529 |
+
/**
|
530 |
+
* Section text for Section3
|
531 |
+
*
|
532 |
+
* Display an explanation of this Section
|
533 |
+
*
|
534 |
+
*/
|
535 |
+
function jr_mt_single_settings_expl() {
|
536 |
+
?>
|
537 |
+
<p>
|
538 |
+
Select a Theme for an individual Page, Post or
|
539 |
+
any other non-Admin page that has its own Permalink; for example, a specific Archive or Category page.
|
540 |
+
Or for a group of pages which have URLs that all begin with the same characters ("Prefix"),
|
541 |
+
optionally specifying an Asterisk ("*") to match all subdirectories at specific levels.
|
542 |
+
</p>
|
543 |
+
<p>
|
544 |
+
Then cut and paste the URL of the desired Page, Post, Prefix or other non-Admin page.
|
545 |
+
And click the <b>Save Changes</b> button to add the entry.
|
546 |
+
</p>
|
547 |
+
There are three types of Entries that you can specify here:
|
548 |
+
<ol>
|
549 |
+
<li>
|
550 |
+
<b>URL</b> - if Visitor URL matches this URL, use this Theme
|
551 |
+
</li>
|
552 |
+
<li>
|
553 |
+
<b>URL Prefix</b> - any Visitor URL that begins with this URL Prefix will use this Theme
|
554 |
+
</li>
|
555 |
+
<li>
|
556 |
+
<b>URL Prefix with Asterisk(s)</b> - URL Prefix that matches any subdirectory where Asterisk ("*") is specified
|
557 |
+
</li>
|
558 |
+
</ol>
|
559 |
+
For the third type, an Asterisk can only be specified to match the entire subdirectory name, not parts of the name:
|
560 |
+
<blockquote>
|
561 |
+
For example, using a Permalink structure that uses dates,
|
562 |
+
where a typical Post might be at URL
|
563 |
+
<code>http://example.com/wp/2014/04/13/daily-thoughts/</code>,
|
564 |
+
a URL Prefix with Asterisk entry of
|
565 |
+
<code>http://example.com/wp/*/04/*/d</code>
|
566 |
+
would match all April Posts with Titles that begin with the letter "d", no matter what year they were posted.
|
567 |
+
</blockquote>
|
568 |
+
</p>
|
569 |
+
<?php
|
570 |
+
}
|
571 |
+
|
572 |
+
function jr_mt_echo_add_is_prefix() {
|
573 |
+
?>
|
574 |
+
<input type="radio" id="add_is_prefix" name="jr_mt_settings[add_is_prefix]" value="false" checked="checked" /> URL<br/>
|
575 |
+
<input type="radio" id="add_is_prefix" name="jr_mt_settings[add_is_prefix]" value="prefix" /> URL Prefix<br/>
|
576 |
+
<input type="radio" id="add_is_prefix" name="jr_mt_settings[add_is_prefix]" value="*" /> URL Prefix with Asterisk ("*")
|
577 |
+
<?php
|
578 |
+
}
|
579 |
+
|
580 |
+
function jr_mt_echo_add_theme() {
|
581 |
+
jr_mt_themes_field( 'add_theme', '', 'jr_mt_settings', FALSE );
|
582 |
+
}
|
583 |
+
|
584 |
+
function jr_mt_echo_add_path_id() {
|
585 |
+
?>
|
586 |
+
<input id="add_path_id" name="jr_mt_settings[add_path_id]" type="text" size="100" maxlength="256" value="" />
|
587 |
+
<br />
|
588 |
+
(cut and paste URL here of Page, Post, Prefix or other)
|
589 |
+
<br />
|
590 |
+
URL must begin with
|
591 |
+
<?php
|
592 |
+
echo '<code>' . trim( get_home_url(), '\ /' ) . '/</code>';
|
593 |
+
}
|
594 |
+
|
595 |
+
/**
|
596 |
+
* Section text for Section5
|
597 |
+
*
|
598 |
+
* Display an explanation of this Section
|
599 |
+
*
|
600 |
+
*/
|
601 |
+
function jr_mt_querykw_expl() {
|
602 |
+
?>
|
603 |
+
<p>
|
604 |
+
Select a Theme to use
|
605 |
+
whenever the specified Query Keyword (<code>?keyword=</code> or <code>&keyword=</code>)
|
606 |
+
is found in the URL of
|
607 |
+
any Page, Post or
|
608 |
+
any other non-Admin page.
|
609 |
+
And click the <b>Save Changes</b> button to add the entry.
|
610 |
+
</p>
|
611 |
+
<p>
|
612 |
+
<b>
|
613 |
+
Note
|
614 |
+
</b>
|
615 |
+
that Query Keyword takes precedence over all other types of Theme selection entries.
|
616 |
+
For example,
|
617 |
+
<?php
|
618 |
+
echo '<code>' . trim( get_home_url(), '\ /' ) . '?firstname=dorothy</code>'
|
619 |
+
. ' would use the Theme specified for the <code>firstname</code> keyword, not the Theme specified for Site Home.</p>';
|
620 |
+
}
|
621 |
+
function jr_mt_echo_add_querykw_theme() {
|
622 |
+
jr_mt_themes_field( 'add_querykw_theme', '', 'jr_mt_settings', FALSE );
|
623 |
+
}
|
624 |
+
function jr_mt_echo_add_querykw_keyword() {
|
625 |
+
$three_dots = '…';
|
626 |
+
echo '<code>'
|
627 |
+
. trim( get_home_url(), '\ /' )
|
628 |
+
. "/</code>$three_dots<code>/?"
|
629 |
+
. '<input id="add_querykw_keyword" name="jr_mt_settings[add_querykw_keyword]" type="text" size="20" maxlength="64" value="" />=</code>'
|
630 |
+
. $three_dots;
|
631 |
+
}
|
632 |
+
|
633 |
+
/**
|
634 |
+
* Section text for Section5
|
635 |
+
*
|
636 |
+
* Display an explanation of this Section
|
637 |
+
*
|
638 |
+
*/
|
639 |
+
function jr_mt_query_expl() {
|
640 |
+
?>
|
641 |
+
<p>
|
642 |
+
Select a Theme to use
|
643 |
+
whenever the specified Query Keyword <b>and</b> Value (<code>?keyword=value</code> or <code>&keyword=value</code>)
|
644 |
+
are found in the URL of
|
645 |
+
any Page, Post or
|
646 |
+
any other non-Admin page.
|
647 |
+
And click the <b>Save Changes</b> button to add the entry.
|
648 |
+
</p>
|
649 |
+
<p>
|
650 |
+
<b>
|
651 |
+
Note
|
652 |
+
</b>
|
653 |
+
that Query Keyword=Value takes precedence over all other Theme selection entries,
|
654 |
+
including a Query Keyword entry for the same Keyword.
|
655 |
+
For example,
|
656 |
+
<?php
|
657 |
+
echo '<code>' . trim( get_home_url(), '\ /' ) . '?firstname=dorothy</code>'
|
658 |
+
. ' would use the Theme specified for the <code>firstname=dorothy</code> keyword=value pair,'
|
659 |
+
. ' not the Theme specified for Site Home nor even the Theme specified for the Keyword <code>firstname</code>.</p>';
|
660 |
+
}
|
661 |
+
function jr_mt_echo_add_query_theme() {
|
662 |
+
jr_mt_themes_field( 'add_query_theme', '', 'jr_mt_settings', FALSE );
|
663 |
+
}
|
664 |
+
function jr_mt_echo_add_query_keyword() {
|
665 |
+
$three_dots = '…';
|
666 |
+
echo '<code>'
|
667 |
+
. trim( get_home_url(), '\ /' )
|
668 |
+
. "/</code>$three_dots<code>/?"
|
669 |
+
. '<input id="add_query_keyword" name="jr_mt_settings[add_query_keyword]" type="text" size="20" maxlength="64" value="" /></code>';
|
670 |
+
}
|
671 |
+
function jr_mt_echo_add_query_value() {
|
672 |
+
echo '<code>'
|
673 |
+
. '='
|
674 |
+
. '<input id="add_query_value" name="jr_mt_settings[add_query_value]" type="text" size="20" maxlength="64" value="" /></code>';
|
675 |
+
}
|
676 |
+
|
677 |
+
/**
|
678 |
+
* Section text for Section6
|
679 |
+
*
|
680 |
+
* Display an explanation of this Section
|
681 |
+
*
|
682 |
+
*/
|
683 |
+
function jr_mt_sticky_expl() {
|
684 |
+
?>
|
685 |
+
<p>
|
686 |
+
If one of the
|
687 |
+
<b>
|
688 |
+
Keyword=Value Entries
|
689 |
+
</b>
|
690 |
+
shown below
|
691 |
+
(if any)
|
692 |
+
is present in the URL of a WordPress non-Admin webpage on the current WordPress Site
|
693 |
+
and that Entry is:
|
694 |
+
<ol>
|
695 |
+
<li>
|
696 |
+
<b>Sticky</b>,
|
697 |
+
then the specified Theme will continue to be displayed for subsequent
|
698 |
+
WordPress non-Admin webpages
|
699 |
+
viewed by the same Visitor
|
700 |
+
until an Override entry is encountered by the same Visitor.
|
701 |
+
</li>
|
702 |
+
<li>
|
703 |
+
<b>Override</b>,
|
704 |
+
then the specified Theme will be displayed,
|
705 |
+
effectively ending any previous Sticky Theme that was being displayed
|
706 |
+
for the same Visitor.
|
707 |
+
</li>
|
708 |
+
</ol>
|
709 |
+
<b>
|
710 |
+
Note
|
711 |
+
</b>
|
712 |
+
that,
|
713 |
+
as explained in the
|
714 |
+
Query Keyword=Value
|
715 |
+
section above,
|
716 |
+
Query Keyword=Value already takes precedence over all other Theme selection entries,
|
717 |
+
even without the Override checkbox selected.
|
718 |
+
Override is only intended to cancel a Sticky entry
|
719 |
+
and display the specified Theme on the current WordPress non-Admin webpage.
|
720 |
+
</p>
|
721 |
+
<p>
|
722 |
+
Implementation Notes:
|
723 |
+
<ol>
|
724 |
+
<li>
|
725 |
+
The term "Same Visitor",
|
726 |
+
used above,
|
727 |
+
refers to a single combination of
|
728 |
+
computer, browser and possibly computer user name,
|
729 |
+
if the visitor's computer has multiple accounts or user names.
|
730 |
+
A computer could be a smartphone, tablet, laptop, desktop or other Internet access device used by the Visitor.
|
731 |
+
</li>
|
732 |
+
<li>
|
733 |
+
When Sticky is active for a given Visitor,
|
734 |
+
the associated Query Keyword=Value is added to the
|
735 |
+
URL of links displayed on the current WordPress non-Admin webpage.
|
736 |
+
With the following exceptions:
|
737 |
+
<ul>
|
738 |
+
<li>
|
739 |
+
a)
|
740 |
+
Only links pointing to non-Admin webpages of the current WordPress Site are altered.
|
741 |
+
</li>
|
742 |
+
<li>
|
743 |
+
b)
|
744 |
+
The
|
745 |
+
"When to add Sticky Query to a URL"
|
746 |
+
setting below also controls when a Sticky Keyword=Value is added to a URL.
|
747 |
+
</li>
|
748 |
+
</ul>
|
749 |
+
<li>
|
750 |
+
Cookies are used for Sticky entries. If the visitor's browser refuses Cookies,
|
751 |
+
this setting will not work and no error messages will be displayed.
|
752 |
+
</li>
|
753 |
+
</ol>
|
754 |
+
</p>
|
755 |
+
<?php
|
756 |
+
}
|
757 |
+
|
758 |
+
function jr_mt_echo_query_present() {
|
759 |
+
$settings = get_option( 'jr_mt_settings' );
|
760 |
+
/*
|
761 |
+
FALSE if Setting "Append if no question mark ("?") found in URL", or
|
762 |
+
TRUE if Setting "Append if no Override keyword=value found in URL"
|
763 |
+
*/
|
764 |
+
echo '<input type="radio" id="query_present" name="jr_mt_settings[query_present]" value="false" ';
|
765 |
+
checked( $settings['query_present'], FALSE );
|
766 |
+
echo ' /> Append if no question mark ("?") found in URL<br/><input type="radio" id="query_present" name="jr_mt_settings[query_present]" value="true" ';
|
767 |
+
checked( $settings['query_present'] );
|
768 |
+
echo ' /> Append if no Override <code>keyword=value</code> found in URL';
|
769 |
+
}
|
770 |
+
|
771 |
+
function jr_mt_echo_sticky_query_entry() {
|
772 |
+
global $jr_mt_kwvalsep;
|
773 |
+
$settings = get_option( 'jr_mt_settings' );
|
774 |
+
$three_dots = '…';
|
775 |
+
$first = TRUE;
|
776 |
+
if ( !empty( $settings['query'] ) ) {
|
777 |
+
foreach ( $settings['query'] as $keyword => $value_array ) {
|
778 |
+
foreach ( $value_array as $value => $theme ) {
|
779 |
+
if ( '*' !== $value ) {
|
780 |
+
if ( $first ) {
|
781 |
+
$first = FALSE;
|
782 |
+
} else {
|
783 |
+
echo '<br />';
|
784 |
+
}
|
785 |
+
echo 'Sticky <input type="checkbox" id="sticky_query_entry" name="jr_mt_settings[sticky_query_entry][]" value="'
|
786 |
+
. "$keyword$jr_mt_kwvalsep$value"
|
787 |
+
. '" ';
|
788 |
+
checked( isset( $settings['remember']['query'][$keyword][$value] ) );
|
789 |
+
echo ' /> Override <input type="checkbox" id="override_query_entry" name="jr_mt_settings[override_query_entry][]" value="'
|
790 |
+
. "$keyword$jr_mt_kwvalsep$value"
|
791 |
+
. '" ';
|
792 |
+
checked( isset( $settings['override']['query'][$keyword][$value] ) );
|
793 |
+
echo ' /> Theme='
|
794 |
+
. wp_get_theme( $theme )->Name . '; '
|
795 |
+
. 'Query='
|
796 |
+
. '<code>'
|
797 |
+
. trim( get_home_url(), '\ /' )
|
798 |
+
. "/</code>$three_dots<code>/?"
|
799 |
+
. "<b><input type='text' readonly='readonly' disable='disabled' name='jr_mt_stkw' value='$keyword' size='"
|
800 |
+
. jr_mt_strlen( $keyword )
|
801 |
+
. "' /></b>"
|
802 |
+
. '='
|
803 |
+
. "<b><input type='text' readonly='readonly' disable='disabled' name='jr_mt_stkwval' value='$value' size='"
|
804 |
+
. jr_mt_strlen( $value )
|
805 |
+
. "' /></b></code>";
|
806 |
+
}
|
807 |
+
}
|
808 |
+
}
|
809 |
+
}
|
810 |
+
if ( $first ) {
|
811 |
+
echo 'None';
|
812 |
+
}
|
813 |
+
}
|
814 |
+
|
815 |
+
function jr_mt_everything_expl() {
|
816 |
+
?>
|
817 |
+
<p>
|
818 |
+
<b>Theme for Everything</b>
|
819 |
+
simplifies the use of a Theme with Admin panel settings that you need to change frequently,
|
820 |
+
when the Theme is only going to be used on one or more Pages or Posts.
|
821 |
+
The Theme can be set as the WordPress Current Theme through the Appearance-Themes admin panel,
|
822 |
+
and set for specific Pages or Posts using this plugin's settings (above),
|
823 |
+
with another Theme specified below as the plugin's default theme ("Theme for Everything").
|
824 |
+
</p>
|
825 |
+
<?php
|
826 |
+
}
|
827 |
+
|
828 |
+
function jr_mt_echo_current() {
|
829 |
+
$settings = get_option( 'jr_mt_settings' );
|
830 |
+
jr_mt_themes_field( 'current', $settings['current'], 'jr_mt_settings', TRUE );
|
831 |
+
echo '<br />(select blank entry for default: WordPress Current Theme defined in Appearance-Themes, currently <b>' . wp_get_theme()->Name . '</b>)';
|
832 |
+
}
|
833 |
+
|
834 |
+
function jr_mt_validate_settings( $input ) {
|
835 |
+
global $jr_mt_kwvalsep;
|
836 |
+
$valid = array();
|
837 |
+
foreach ( array( 'all_pages', 'all_posts', 'site_home', 'current' ) as $thing ) {
|
838 |
+
$valid[$thing] = $input[$thing];
|
839 |
+
}
|
840 |
+
|
841 |
+
$settings = get_option( 'jr_mt_settings' );
|
842 |
+
$ids = $settings['ids'];
|
843 |
+
$query = $settings['query'];
|
844 |
+
$remember = array( 'query' => array() );
|
845 |
+
if ( isset( $input['sticky_query_entry'] ) ) {
|
846 |
+
foreach ( $input['sticky_query_entry'] as $query_entry ) {
|
847 |
+
list( $keyword, $value ) = explode( $jr_mt_kwvalsep, $query_entry );
|
848 |
+
$remember['query'][$keyword][$value] = TRUE;
|
849 |
+
}
|
850 |
+
}
|
851 |
+
|
852 |
+
$override = array( 'query' => array() );
|
853 |
+
if ( isset( $input['override_query_entry'] ) ) {
|
854 |
+
foreach ( $input['override_query_entry'] as $query_entry ) {
|
855 |
+
list( $keyword, $value ) = explode( $jr_mt_kwvalsep, $query_entry );
|
856 |
+
$override['query'][$keyword][$value] = TRUE;
|
857 |
+
}
|
858 |
+
}
|
859 |
+
|
860 |
+
if ( isset ( $input['del_entry'] ) ) {
|
861 |
+
foreach ( $input['del_entry'] as $del_entry ) {
|
862 |
+
unset( $ids[$del_entry] );
|
863 |
+
}
|
864 |
+
}
|
865 |
+
if ( isset ( $input['del_query_entry'] ) ) {
|
866 |
+
foreach ( $input['del_query_entry'] as $del_entry ) {
|
867 |
+
list( $keyword, $value ) = explode( $jr_mt_kwvalsep, $del_entry );
|
868 |
+
unset( $query[$keyword][$value] );
|
869 |
+
if ( empty( $query[$keyword] ) ) {
|
870 |
+
unset( $query[$keyword] );
|
871 |
+
}
|
872 |
+
/* unset() does nothing if a variable or array element does not exist.
|
873 |
+
*/
|
874 |
+
unset( $remember['query'][$keyword][$value] );
|
875 |
+
if ( empty( $remember['query'][$keyword] ) ) {
|
876 |
+
unset( $remember['query'][$keyword] );
|
877 |
+
}
|
878 |
+
unset( $override['query'][$keyword][$value] );
|
879 |
+
if ( empty( $override['query'][$keyword] ) ) {
|
880 |
+
unset( $override['query'][$keyword] );
|
881 |
+
}
|
882 |
+
}
|
883 |
+
}
|
884 |
+
|
885 |
+
/* Handle troublesome %E2%80%8E UTF Left-to-right Mark (LRM) suffix first.
|
886 |
+
*/
|
887 |
+
if ( FALSE === stripos( $input['add_path_id'], '%E2%80%8E' ) ) {
|
888 |
+
if ( FALSE === stripos( rawurlencode( $input['add_path_id'] ), '%E2%80%8E' ) ) {
|
889 |
+
$url = $input['add_path_id'];
|
890 |
+
} else {
|
891 |
+
$url = rawurldecode( str_ireplace( '%E2%80%8E', '', rawurlencode( $input['add_path_id'] ) ) );
|
892 |
+
}
|
893 |
+
} else {
|
894 |
+
$url = str_ireplace( '%E2%80%8E', '', $input['add_path_id'] );
|
895 |
+
}
|
896 |
+
$url = rawurldecode( trim( $url ) );
|
897 |
+
|
898 |
+
if ( ( empty( $input['add_theme'] ) && !empty( $url ) ) || ( !empty( $input['add_theme'] ) && empty( $url ) ) ) {
|
899 |
+
add_settings_error(
|
900 |
+
'jr_mt_settings',
|
901 |
+
'jr_mt_emptyerror',
|
902 |
+
'Both URL and Theme must be specified to add an Individual entry',
|
903 |
+
'error'
|
904 |
+
);
|
905 |
+
} else {
|
906 |
+
if ( !empty( $url ) ) {
|
907 |
+
$validate_url = jr_mt_site_url( $url );
|
908 |
+
if ( $validate_url === TRUE ) {
|
909 |
+
if ( ( '*' !== $input['add_is_prefix'] ) && ( FALSE !== strpos( $url, '*' ) ) ) {
|
910 |
+
add_settings_error(
|
911 |
+
'jr_mt_settings',
|
912 |
+
'jr_mt_queryerror',
|
913 |
+
'Asterisk ("*") only allowed when "URL Prefix with Asterisk" selected: <code>' . $url . '</code>',
|
914 |
+
'error'
|
915 |
+
);
|
916 |
+
} else {
|
917 |
+
extract( jr_mt_url_to_id( $url ) );
|
918 |
+
if ( 'false' === $input['add_is_prefix'] ) {
|
919 |
+
if ( $home ) {
|
920 |
+
add_settings_error(
|
921 |
+
'jr_mt_settings',
|
922 |
+
'jr_mt_homeerror',
|
923 |
+
'Please use "Select Theme for Site Home" field instead of specifying Site Home URL as an individual entry.',
|
924 |
+
'error'
|
925 |
+
);
|
926 |
+
} else {
|
927 |
+
if ( $type == 'admin' ) {
|
928 |
+
add_settings_error(
|
929 |
+
'jr_mt_settings',
|
930 |
+
'jr_mt_adminerror',
|
931 |
+
'Admin Page URLs are not allowed because no known Themes alter the appearance of Admin pages: <code>' . $url . '</code>',
|
932 |
+
'error'
|
933 |
+
);
|
934 |
+
} else {
|
935 |
+
if ( $id === FALSE ) {
|
936 |
+
$key = $page_url;
|
937 |
+
} else {
|
938 |
+
$key = $id;
|
939 |
+
}
|
940 |
+
}
|
941 |
+
}
|
942 |
+
} else {
|
943 |
+
if ( parse_url( $url, PHP_URL_QUERY ) === NULL ) {
|
944 |
+
if ( '*' === $input['add_is_prefix'] ) {
|
945 |
+
$asterisk_not_alone = FALSE;
|
946 |
+
$no_asterisk = TRUE;
|
947 |
+
$rel_url_dirs = explode( '/', str_replace( '\\', '/', $rel_url ) );
|
948 |
+
foreach ( $rel_url_dirs as $dir ) {
|
949 |
+
if ( $no_asterisk ) {
|
950 |
+
if ( FALSE !== strpos( $dir, '*' ) ) {
|
951 |
+
$no_asterisk = FALSE;
|
952 |
+
if ( '*' !== $dir ) {
|
953 |
+
$asterisk_not_alone = TRUE;
|
954 |
+
}
|
955 |
+
}
|
956 |
+
}
|
957 |
+
}
|
958 |
+
if ( $no_asterisk ) {
|
959 |
+
add_settings_error(
|
960 |
+
'jr_mt_settings',
|
961 |
+
'jr_mt_queryerror',
|
962 |
+
'No Asterisk ("*") specified but "URL Prefix with Asterisk" selected: <code>' . $url . '</code>',
|
963 |
+
'error'
|
964 |
+
);
|
965 |
+
} else {
|
966 |
+
if ( $asterisk_not_alone ) {
|
967 |
+
add_settings_error(
|
968 |
+
'jr_mt_settings',
|
969 |
+
'jr_mt_queryerror',
|
970 |
+
'An Asterisk ("*") may only replace a full subdirectory name, not just a portion of it: <code>' . $url . '</code>',
|
971 |
+
'error'
|
972 |
+
);
|
973 |
+
}
|
974 |
+
}
|
975 |
+
}
|
976 |
+
} else {
|
977 |
+
add_settings_error(
|
978 |
+
'jr_mt_settings',
|
979 |
+
'jr_mt_queryerror',
|
980 |
+
'?key=val&key=val Queries are not supported in a URL Prefix: <code>' . $url . '</code>',
|
981 |
+
'error'
|
982 |
+
);
|
983 |
+
}
|
984 |
+
$type = $input['add_is_prefix'];
|
985 |
+
$key = $rel_url;
|
986 |
+
}
|
987 |
+
$errors = get_settings_errors();
|
988 |
+
if ( empty( $errors ) ) {
|
989 |
+
$ids[$key] = array(
|
990 |
+
'theme' => $input['add_theme'],
|
991 |
+
'type' => $type,
|
992 |
+
'id' => $id,
|
993 |
+
'page_url' => $page_url,
|
994 |
+
'rel_url' => $rel_url,
|
995 |
+
'url' => $url
|
996 |
+
);
|
997 |
+
}
|
998 |
+
/*
|
999 |
+
$errors = get_settings_errors();
|
1000 |
+
if ( empty( $errors ) ) {
|
1001 |
+
// Here is where to check if URL gives a 404, but it doesn't work, always getting 302, and obliterating Settings Saved message
|
1002 |
+
if ( 404 == $respcode = wp_remote_retrieve_response_code( wp_remote_head( $url ) ) ) {
|
1003 |
+
add_settings_error(
|
1004 |
+
'jr_mt_settings',
|
1005 |
+
'jr_mt_urlerror',
|
1006 |
+
"Warning: URL specified ('$url') generated error response $respcode",
|
1007 |
+
'error'
|
1008 |
+
);
|
1009 |
+
}
|
1010 |
+
}
|
1011 |
+
*/
|
1012 |
+
}
|
1013 |
+
} else {
|
1014 |
+
add_settings_error(
|
1015 |
+
'jr_mt_settings',
|
1016 |
+
'jr_mt_urlerror',
|
1017 |
+
'URL specified for Individual page/post: <code>' . $url . '</code>' . $validate_url,
|
1018 |
+
'updated'
|
1019 |
+
);
|
1020 |
+
}
|
1021 |
+
}
|
1022 |
+
}
|
1023 |
+
|
1024 |
+
/* Make sure reserved characters are not used
|
1025 |
+
in URL Query keyword or value fields on Settings page.
|
1026 |
+
*/
|
1027 |
+
function jr_mt_query_chars( $element, $where ) {
|
1028 |
+
foreach (
|
1029 |
+
array(
|
1030 |
+
'=' => 'Equals Sign' ,
|
1031 |
+
'?' => 'Question Mark' ,
|
1032 |
+
'&' => 'Ampersand' ,
|
1033 |
+
' ' => 'Blank' ,
|
1034 |
+
'#' => 'Number Sign' ,
|
1035 |
+
'/' => 'Slash' ,
|
1036 |
+
'\\' => 'Backslash' ,
|
1037 |
+
'[' => 'Square Bracket',
|
1038 |
+
']' => 'Square Bracket',
|
1039 |
+
) as $char => $name ) {
|
1040 |
+
if ( FALSE !== strpos( $element, $char ) ) {
|
1041 |
+
add_settings_error(
|
1042 |
+
'jr_mt_settings',
|
1043 |
+
'jr_mt_queryerror',
|
1044 |
+
'Illegal character used in '
|
1045 |
+
. $where
|
1046 |
+
. ': '
|
1047 |
+
. $name
|
1048 |
+
. ' ("' . $char . '") in "'
|
1049 |
+
. $element
|
1050 |
+
. '"',
|
1051 |
+
'error'
|
1052 |
+
);
|
1053 |
+
return FALSE;
|
1054 |
+
}
|
1055 |
+
}
|
1056 |
+
return TRUE;
|
1057 |
+
}
|
1058 |
+
/* Data Sanitization needed here
|
1059 |
+
*/
|
1060 |
+
$keyword = jr_mt_prep_query_keyword( $input['add_querykw_keyword'] );
|
1061 |
+
if ( !empty( $input['add_querykw_theme'] ) && !empty( $keyword ) ) {
|
1062 |
+
if ( jr_mt_query_chars( $keyword, 'Query Keyword' ) ) {
|
1063 |
+
/* If there is an existing entry for the Keyword,
|
1064 |
+
then replace it.
|
1065 |
+
Otherwise, create a new entry.
|
1066 |
+
*/
|
1067 |
+
$query[$keyword]['*'] = $input['add_querykw_theme'];
|
1068 |
+
}
|
1069 |
+
} else {
|
1070 |
+
if ( !( empty( $input['add_querykw_theme'] ) && empty( $keyword ) ) ) {
|
1071 |
+
add_settings_error(
|
1072 |
+
'jr_mt_settings',
|
1073 |
+
'jr_mt_emptyerror',
|
1074 |
+
'Both Query Keyword and Theme must be specified to add an Individual Query Keyword entry',
|
1075 |
+
'error'
|
1076 |
+
);
|
1077 |
+
}
|
1078 |
+
}
|
1079 |
+
|
1080 |
+
/* Data Sanitization needed here
|
1081 |
+
*/
|
1082 |
+
$keyword = jr_mt_prep_query_keyword( $input['add_query_keyword'] );
|
1083 |
+
$value = jr_mt_prep_query_value( $input['add_query_value'] );
|
1084 |
+
if ( !empty( $input['add_query_theme'] ) && !empty( $keyword ) && !empty( $value ) ) {
|
1085 |
+
if ( jr_mt_query_chars( $keyword, 'Query Keyword' ) && jr_mt_query_chars( $value, 'Query Value' ) ) {
|
1086 |
+
/* If there is an existing entry for the Keyword and Value pair,
|
1087 |
+
then replace it.
|
1088 |
+
Otherwise, create a new entry.
|
1089 |
+
*/
|
1090 |
+
$query[$keyword][$value] = $input['add_query_theme'];
|
1091 |
+
}
|
1092 |
+
} else {
|
1093 |
+
if ( !( empty( $input['add_query_theme'] ) && empty( $keyword ) && empty( $value ) ) ) {
|
1094 |
+
add_settings_error(
|
1095 |
+
'jr_mt_settings',
|
1096 |
+
'jr_mt_emptyerror',
|
1097 |
+
'Query Keyword, Value and Theme must all be specified to add an Individual Query entry',
|
1098 |
+
'error'
|
1099 |
+
);
|
1100 |
+
}
|
1101 |
+
}
|
1102 |
+
|
1103 |
+
if ( 'true' === $input['query_present'] ) {
|
1104 |
+
$valid['query_present'] = TRUE;
|
1105 |
+
} else {
|
1106 |
+
if ( 'false' === $input['query_present'] ) {
|
1107 |
+
$valid['query_present'] = FALSE;
|
1108 |
+
}
|
1109 |
+
}
|
1110 |
+
|
1111 |
+
$errors = get_settings_errors();
|
1112 |
+
if ( empty( $errors ) ) {
|
1113 |
+
add_settings_error(
|
1114 |
+
'jr_mt_settings',
|
1115 |
+
'jr_mt_saved',
|
1116 |
+
'Settings Saved',
|
1117 |
+
'updated'
|
1118 |
+
);
|
1119 |
+
}
|
1120 |
+
$valid['ids'] = $ids;
|
1121 |
+
$valid['query'] = $query;
|
1122 |
+
$valid['remember'] = $remember;
|
1123 |
+
$valid['override'] = $override;
|
1124 |
+
return $valid;
|
1125 |
+
}
|
1126 |
+
|
1127 |
+
// $theme_name is the name of the Theme's folder within the Theme directory
|
1128 |
+
function jr_mt_themes_field( $field_name, $theme_name, $setting, $excl_current_theme ) {
|
1129 |
+
echo "<select id='$field_name' name='$setting" . "[$field_name]' size='1'>";
|
1130 |
+
if ( empty( $theme_name ) ) {
|
1131 |
+
$selected = 'selected="selected"';
|
1132 |
+
} else {
|
1133 |
+
$selected = '';
|
1134 |
+
}
|
1135 |
+
echo "<option value='' $selected></option>";
|
1136 |
+
global $jr_mt_themes_cache;
|
1137 |
+
foreach ( $jr_mt_themes_cache as $folder => $theme_obj ) {
|
1138 |
+
if ( $excl_current_theme ) {
|
1139 |
+
if ( ( jr_mt_current_theme( 'stylesheet' ) == $theme_obj['stylesheet'] ) && ( jr_mt_current_theme( 'template' ) == $theme_obj['template'] ) ) {
|
1140 |
+
// Skip the Current Theme
|
1141 |
+
continue;
|
1142 |
+
}
|
1143 |
+
}
|
1144 |
+
if ( $theme_name == $folder ) {
|
1145 |
+
$selected = 'selected="selected"';
|
1146 |
+
} else {
|
1147 |
+
$selected = '';
|
1148 |
+
}
|
1149 |
+
$name = $theme_obj->Name;
|
1150 |
+
echo "<option value='$folder' $selected>$name</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