PluginProbe
Theme Switcha – Easily Switch Themes for Development and Testing / 2.6
Theme Switcha – Easily Switch Themes for Development and Testing v2.6
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 2.6, at theme-switcha.php

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