forked from jkrug/wordpress-toxid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththeme-switcher.php
106 lines (83 loc) · 2.91 KB
/
theme-switcher.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/*
Plugin Name: TOXID Themeswitcher
Plugin URI: http://toxid.org/
Description: Switch theme for TOXID-cURL.
Version: 1.1
Author: Joscha Krug
Author URI: http://www.marmalade.de
mostly copied from Theme-Switcher-Plugin by
Author: Ryan Boren
Author URI: http://ryan.boren.me/
Adapted from Ryan Boren theme switcher.
http://ryan.boren.me/
*/
class ThemeSwitcher {
function ThemeSwitcher()
{
add_filter('stylesheet', array(&$this, 'get_stylesheet'));
add_filter('template', array(&$this, 'get_template'));
add_filter('preview_page_link', array(&$this, 'add_preview_theme'));
add_filter('preview_post_link', array(&$this, 'add_preview_theme'));
add_action('admin_init', array(&$this, 'init_admin'));
}
function add_preview_theme($link)
{
$theme = urlencode(get_option('toxid_preview_theme'));
$link .= (strpos($link, '?') === false ? '?' : '&') . 'wptheme=' . $theme;
return $link;
}
function init_admin()
{
register_setting('general', 'toxid_preview_theme');
add_settings_section('toxid-settings', 'TOXID', '__return_false', 'general');
add_settings_field('toxid_preview_theme', 'Theme used for previews', array(&$this, 'admin_toxid_preview_theme_field'), 'general', 'toxid-settings');
}
function admin_toxid_preview_theme_field()
{
$themes = array_keys(get_themes());
$currentTheme = get_option('toxid_preview_theme');
echo '<select name="toxid_preview_theme">';
echo '<option>' . __('None') . '</option>';
foreach ($themes as $theme) {
printf('<option value="%s" %s>%s</option>', esc_attr($theme), ($theme == $currentTheme ? 'selected' : ''), esc_html($theme));
}
echo '</select>';
}
function get_stylesheet($stylesheet = '') {
$theme = $this->get_theme();
if (empty($theme)) {
return $stylesheet;
}
$theme = get_theme($theme);
// Don't let people peek at unpublished themes.
if (isset($theme['Status']) && $theme['Status'] != 'publish')
return $template;
if (empty($theme)) {
return $stylesheet;
}
return $theme['Stylesheet'];
}
function get_template($template) {
$theme = $this->get_theme();
if (empty($theme)) {
return $template;
}
$theme = get_theme($theme);
if ( empty( $theme ) ) {
return $template;
}
// Don't let people peek at unpublished themes.
if (isset($theme['Status']) && $theme['Status'] != 'publish')
return $template;
return $theme['Template'];
}
function get_theme() {
if ( ! empty($_GET["wptheme"] ) ) {
return $_GET["wptheme"];
} else {
return '';
}
}
}
$theme_switcher = new ThemeSwitcher();