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

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