PluginProbe
Theme Switcha – Easily Switch Themes for Development and Testing / trunk
Theme Switcha – Easily Switch Themes for Development and Testing vtrunk
3.4.5 trunk 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.3.1 3.3.2 All 33 releases
theme-switcha / theme-switcha.php

theme-switcha.php in Theme Switcha – Easily Switch Themes for Development and Testing trunk, at theme-switcha.php

255 lines 9.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Theme Switcha
4 Plugin URI: https://perishablepress.com/theme-switcha/
5 Description: Theme switching done right.
6 Tags: theme, switch, switcher, theme switcher, preview
7 Author: Jeff Starr
8 Contributors: specialk
9 Author URI: https://plugin-planet.com/
10 Donate link: https://monzillamedia.com/donate.html
11 Requires at least: 4.7
12 Tested up to: 7.1
13 Stable tag: 3.4.5
14 Version: 3.4.5
15 Requires PHP: 5.6.20
16 Text Domain: theme-switcha
17 Domain Path: /languages
18 License: GPL v3 or later
19
20 This program is free software; you can redistribute it and/or
21 modify it under the terms of the GNU General Public License
22 as published by the Free Software Foundation; either version
23 2 of the License, or (at your option) any later version.
24
25 This program is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 GNU General Public License for more details.
29
30 You should have received a copy of the GNU General Public License
31 with this program. If not, visit: https://www.gnu.org/licenses/
32
33 Copyright 2016-2026 Monzilla Media. All rights reserved.
34 */
35
36 if (!defined('ABSPATH')) die();
37
38 if (!class_exists('Theme_Switcha')) {
39
40 final class Theme_Switcha {
41
42 private static $instance;
43
44 public static function instance() {
45
46 if (!isset(self::$instance) && !(self::$instance instanceof Theme_Switcha)) {
47
48 self::$instance = new Theme_Switcha;
49 self::$instance->constants();
50 self::$instance->includes();
51
52 register_activation_hook(__FILE__, 'theme_switcha_dismiss_notice_activate');
53
54 add_action('admin_init', array(self::$instance, 'check_existing'));
55 add_action('admin_init', array(self::$instance, 'check_version'));
56 add_action('init', array(self::$instance, 'load_i18n'));
57 add_filter('plugin_action_links', array(self::$instance, 'action_links'), 10, 2);
58 add_filter('plugin_row_meta', array(self::$instance, 'plugin_links'), 10, 2);
59 add_filter('admin_footer_text', array(self::$instance, 'footer_text'), 10, 1);
60
61 add_action('admin_bar_menu', 'theme_switcha_toolbar_add_menu', 1000);
62 add_action('admin_enqueue_scripts', 'theme_switcha_enqueue_resources_admin');
63 add_action('admin_print_scripts', 'theme_switcha_print_js_vars_admin');
64 add_action('admin_notices', 'theme_switcha_admin_notice');
65 add_action('admin_init', 'theme_switcha_register_settings');
66 add_action('admin_init', 'theme_switcha_reset_options');
67 add_action('admin_menu', 'theme_switcha_menu_pages');
68 add_action('admin_menu', 'theme_switcha_disable_widget');
69 add_action('admin_init', 'theme_switcha_dismiss_notice_save');
70 add_action('admin_init', 'theme_switcha_dismiss_notice_version');
71
72 add_action('wp_dashboard_setup', 'theme_switcha_dashboard_widget');
73 add_action('plugins_loaded', 'theme_switcha_add_filters');
74 add_action('init', 'theme_switcha_check_cookie');
75 add_filter('widget_text', 'do_shortcode', 10);
76
77 }
78
79 return self::$instance;
80 }
81
82 public static function options() {
83
84 $options = array(
85 'enable_plugin' => false,
86 'enable_admin' => false,
87 'allowed_users' => 'admin',
88 'cookie_expire' => 3600,
89 'passkey' => uniqid(mt_rand()),
90 'disable_widget' => false,
91 );
92
93 return apply_filters('theme_switcha_options', $options);
94 }
95
96 private function constants() {
97
98 if (!defined('THEME_SWITCHA_REQUIRE')) define('THEME_SWITCHA_REQUIRE', '4.7');
99 if (!defined('THEME_SWITCHA_VERSION')) define('THEME_SWITCHA_VERSION', '3.4.5');
100 if (!defined('THEME_SWITCHA_NAME')) define('THEME_SWITCHA_NAME', 'Theme Switcha');
101 if (!defined('THEME_SWITCHA_AUTHOR')) define('THEME_SWITCHA_AUTHOR', 'Jeff Starr');
102 if (!defined('THEME_SWITCHA_HOME')) define('THEME_SWITCHA_HOME', 'https://perishablepress.com/theme-switcha/');
103 if (!defined('THEME_SWITCHA_URL')) define('THEME_SWITCHA_URL', plugin_dir_url(__FILE__));
104 if (!defined('THEME_SWITCHA_DIR')) define('THEME_SWITCHA_DIR', plugin_dir_path(__FILE__));
105 if (!defined('THEME_SWITCHA_FILE')) define('THEME_SWITCHA_FILE', plugin_basename(__FILE__));
106 if (!defined('THEME_SWITCHA_SLUG')) define('THEME_SWITCHA_SLUG', basename(dirname(__FILE__)));
107
108 }
109
110 private function includes() {
111
112 require_once THEME_SWITCHA_DIR .'inc/plugin-core.php';
113 require_once THEME_SWITCHA_DIR .'inc/resources-enqueue.php';
114 require_once THEME_SWITCHA_DIR .'inc/settings-display.php';
115 require_once THEME_SWITCHA_DIR .'inc/settings-register.php';
116 require_once THEME_SWITCHA_DIR .'inc/settings-reset.php';
117
118 }
119
120 public function action_links($links, $file) {
121
122 if ($file == THEME_SWITCHA_FILE && current_user_can('manage_options')) {
123
124 $add_links = '<a href="'. admin_url('options-general.php?page=theme_switcha_settings') .'">'. esc_html__('Settings', 'theme-switcha') .'</a>';
125 array_unshift($links, $add_links);
126
127 }
128
129 return $links;
130 }
131
132 public function plugin_links($links, $file) {
133
134 if ($file == THEME_SWITCHA_FILE) {
135
136 $home_href = 'https://perishablepress.com/theme-switcha/';
137 $home_title = esc_attr__('Plugin Homepage', 'theme-switcha');
138 $home_text = esc_html__('Homepage', 'theme-switcha');
139
140 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $home_href .'" title="'. $home_title .'">'. $home_text .'</a>';
141
142 $rate_href = 'https://wordpress.org/support/plugin/'. THEME_SWITCHA_SLUG .'/reviews/?rate=5#new-post';
143 $rate_title = esc_html__('Click here to rate and review this plugin at WordPress.org', 'theme-switcha');
144 $rate_text = esc_html__('Rate this plugin', 'theme-switcha') .'&nbsp;&raquo;';
145
146 $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $rate_href .'" title="'. $rate_title .'">'. $rate_text .'</a>';
147
148 $pro_href = 'https://plugin-planet.com/theme-switcha-pro/';
149 $pro_title = esc_html__('Get Theme Switcha Pro!', 'theme-switcha');
150 $pro_text = esc_html__('Go&nbsp;Pro', 'theme-switcha');
151 $pro_style = 'padding:1px 5px;color:#eee;background:#333;border-radius:1px;';
152
153 // $links[] = '<a target="_blank" rel="noopener noreferrer" href="'. $pro_href .'" title="'. $pro_title .'" style="'. $pro_style .'">'. $pro_text .'</a>';
154
155 }
156 return $links;
157 }
158
159 function footer_text($text) {
160
161 $screen_id = theme_switcha_get_current_screen_id();
162
163 $ids = array('settings_page_theme_switcha_settings');
164
165 if ($screen_id && apply_filters('theme_switcha_admin_footer_text', in_array($screen_id, $ids))) {
166
167 $text = __('Like this plugin? Give it a', 'theme-switcha');
168
169 $text .= ' <a target="_blank" rel="noopener noreferrer" href="https://wordpress.org/support/plugin/theme-switcha/reviews/?rate=5#new-post">';
170
171 $text .= __('�
172
173
174
175
176 rating&nbsp;&raquo;', 'theme-switcha') .'</a>';
177
178 }
179
180 return $text;
181
182 }
183
184 public function check_existing() {
185
186 if (class_exists('Theme_Switcha_Pro')) {
187 if (is_plugin_active(THEME_SWITCHA_FILE)) {
188 deactivate_plugins(THEME_SWITCHA_FILE);
189
190 $msg = '<strong>'. esc_html__('Warning:', 'theme-switcha') .'</strong> ';
191 $msg .= esc_html__('Pro version of ', 'theme-switcha') . THEME_SWITCHA_NAME;
192 $msg .= esc_html__(' currently active. Free and Pro versions cannot be activated at the same time. ', 'theme-switcha');
193 $msg .= esc_html__('Please return to the', 'theme-switcha');
194 $msg .= ' <a href="'. admin_url() .'">'. esc_html__('WP Admin Area', 'theme-switcha') .'</a> ';
195 $msg .= esc_html__('and try again.', 'theme-switcha');
196
197 wp_die($msg);
198 }
199 }
200 }
201
202 public function check_version() {
203
204 $wp_version = get_bloginfo('version');
205
206 if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
207 if (version_compare($wp_version, THEME_SWITCHA_REQUIRE, '<')) {
208 if (is_plugin_active(THEME_SWITCHA_FILE)) {
209 deactivate_plugins(THEME_SWITCHA_FILE);
210
211 $msg = '<strong>'. THEME_SWITCHA_NAME .'</strong> ';
212 $msg .= esc_html__('requires WordPress ', 'theme-switcha') . THEME_SWITCHA_REQUIRE;
213 $msg .= esc_html__(' or higher, and has been deactivated. ', 'theme-switcha');
214 $msg .= esc_html__('Please return to the', 'theme-switcha');
215 $msg .= ' <a href="'. admin_url('plugins.php') .'">'. esc_html__('WordPress Admin Area', 'theme-switcha') .'</a> ';
216 $msg .= esc_html__('to upgrade WordPress and try again.', 'theme-switcha');
217
218 wp_die($msg);
219 }
220 }
221 }
222 }
223
224 public function load_i18n() {
225 load_plugin_textdomain('theme-switcha', false, dirname(THEME_SWITCHA_FILE) .'/languages/');
226 }
227
228 public function __clone() {
229 _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin&rsquo; huh?', 'theme-switcha'), THEME_SWITCHA_VERSION);
230 }
231
232 public function __wakeup() {
233 _doing_it_wrong(__FUNCTION__, esc_html__('Cheatin&rsquo; huh?', 'theme-switcha'), THEME_SWITCHA_VERSION);
234 }
235
236 }
237 }
238
239 if (class_exists('Theme_Switcha')) {
240
241 $theme_switcha_options = get_option('theme_switcha_options', Theme_Switcha::options());
242 $theme_switcha_options = apply_filters('theme_switcha_get_options', $theme_switcha_options);
243
244 if (!function_exists('theme_switcha')) {
245
246 function theme_switcha() {
247
248 return Theme_Switcha::instance();
249 }
250 }
251
252 theme_switcha();
253
254 }
255