Completed
Branch master (2a3d9e)
by Andrey
01:48
created
toolbar-theme-switcher.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -176,7 +176,7 @@
 block discarded – undo
176 176
 	 * Returns field from theme data if cookie is set to valid theme.
177 177
 	 *
178 178
 	 * @param string $field_name
179
-	 * @param mixed  $default
179
+	 * @param string  $default
180 180
 	 *
181 181
 	 * @deprecated
182 182
 	 *
Please login to merge, or discard this patch.
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
44 44
 	 */
45 45
 	static function on_load() {
46 46
 
47
-		add_action( 'setup_theme', array( __CLASS__, 'setup_theme' ) );
48
-		add_action( 'init', array( __CLASS__, 'init' ) );
47
+		add_action('setup_theme', array(__CLASS__, 'setup_theme'));
48
+		add_action('init', array(__CLASS__, 'init'));
49 49
 	}
50 50
 
51 51
 	/**
@@ -55,29 +55,29 @@  discard block
 block discarded – undo
55 55
 
56 56
 		global $pagenow;
57 57
 
58
-		if ( ( is_admin() && 'themes.php' == $pagenow ) || ! self::can_switch_themes() ) {
58
+		if ((is_admin() && 'themes.php' == $pagenow) || ! self::can_switch_themes()) {
59 59
 			return;
60 60
 		}
61 61
 
62
-		if ( isset( $_GET['tts_reset'] ) ) {
63
-			setcookie( self::get_cookie_name(), '', 1 );
62
+		if (isset($_GET['tts_reset'])) {
63
+			setcookie(self::get_cookie_name(), '', 1);
64 64
 			nocache_headers();
65
-			wp_safe_redirect( home_url() );
65
+			wp_safe_redirect(home_url());
66 66
 			die;
67 67
 		}
68 68
 
69 69
 		self::load_cookie();
70 70
 
71
-		if ( empty( self::$theme ) ) {
71
+		if (empty(self::$theme)) {
72 72
 			return;
73 73
 		}
74 74
 
75
-		add_filter( 'pre_option_template', array( self::$theme, 'get_template' ) );
76
-		add_filter( 'pre_option_stylesheet', array( self::$theme, 'get_stylesheet' ) );
77
-		add_filter( 'pre_option_stylesheet_root', array( self::$theme, 'get_theme_root' ) );
75
+		add_filter('pre_option_template', array(self::$theme, 'get_template'));
76
+		add_filter('pre_option_stylesheet', array(self::$theme, 'get_stylesheet'));
77
+		add_filter('pre_option_stylesheet_root', array(self::$theme, 'get_theme_root'));
78 78
 		$parent = self::$theme->parent();
79
-		add_filter( 'pre_option_template_root', array( empty( $parent ) ? self::$theme : $parent, 'get_theme_root' ) );
80
-		add_filter( 'pre_option_current_theme', '__return_false' );
79
+		add_filter('pre_option_template_root', array(empty($parent) ? self::$theme : $parent, 'get_theme_root'));
80
+		add_filter('pre_option_current_theme', '__return_false');
81 81
 	}
82 82
 
83 83
 	/**
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
 	 */
88 88
 	static function can_switch_themes() {
89 89
 
90
-		$capability = apply_filters( 'tts_capability', 'switch_themes' );
90
+		$capability = apply_filters('tts_capability', 'switch_themes');
91 91
 
92
-		return apply_filters( 'tts_can_switch_themes', current_user_can( $capability ) );
92
+		return apply_filters('tts_can_switch_themes', current_user_can($capability));
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,15 +99,15 @@  discard block
 block discarded – undo
99 99
 
100 100
 		$cookie_name = self::get_cookie_name();
101 101
 
102
-		if ( empty( $_COOKIE[ $cookie_name ] ) ) {
102
+		if (empty($_COOKIE[$cookie_name])) {
103 103
 			return;
104 104
 		}
105 105
 
106
-		$theme = wp_get_theme( $_COOKIE[ $cookie_name ] );
106
+		$theme = wp_get_theme($_COOKIE[$cookie_name]);
107 107
 
108 108
 		if (
109 109
 			$theme->exists()
110
-			&& $theme->get( 'Name' ) != get_option( 'current_theme' )
110
+			&& $theme->get('Name') != get_option('current_theme')
111 111
 			&& $theme->is_allowed()
112 112
 		) {
113 113
 			self::$theme = $theme;
@@ -123,8 +123,8 @@  discard block
 block discarded – undo
123 123
 
124 124
 		static $hash;
125 125
 
126
-		if ( empty( $hash ) ) {
127
-			$hash = 'wordpress_tts_theme_' . md5( home_url( '', 'http' ) );
126
+		if (empty($hash)) {
127
+			$hash = 'wordpress_tts_theme_' . md5(home_url('', 'http'));
128 128
 		}
129 129
 
130 130
 		return $hash;
@@ -139,9 +139,9 @@  discard block
 block discarded – undo
139 139
 	 *
140 140
 	 * @return bool
141 141
 	 */
142
-	static function is_allowed( $theme ) {
142
+	static function is_allowed($theme) {
143 143
 
144
-		return array_key_exists( $theme->get( 'Name' ), self::get_allowed_themes() );
144
+		return array_key_exists($theme->get('Name'), self::get_allowed_themes());
145 145
 	}
146 146
 
147 147
 	/**
@@ -153,9 +153,9 @@  discard block
 block discarded – undo
153 153
 	 *
154 154
 	 * @return string
155 155
 	 */
156
-	static function template( $template ) {
156
+	static function template($template) {
157 157
 
158
-		return self::get_theme_field( 'Template', $template );
158
+		return self::get_theme_field('Template', $template);
159 159
 	}
160 160
 
161 161
 	/**
@@ -167,9 +167,9 @@  discard block
 block discarded – undo
167 167
 	 *
168 168
 	 * @return string
169 169
 	 */
170
-	static function stylesheet( $stylesheet ) {
170
+	static function stylesheet($stylesheet) {
171 171
 
172
-		return self::get_theme_field( 'Stylesheet', $stylesheet );
172
+		return self::get_theme_field('Stylesheet', $stylesheet);
173 173
 	}
174 174
 
175 175
 	/**
@@ -182,10 +182,10 @@  discard block
 block discarded – undo
182 182
 	 *
183 183
 	 * @return mixed
184 184
 	 */
185
-	static function get_theme_field( $field_name, $default = false ) {
185
+	static function get_theme_field($field_name, $default = false) {
186 186
 
187
-		if ( ! empty( self::$theme ) ) {
188
-			return self::$theme->get( $field_name );
187
+		if ( ! empty(self::$theme)) {
188
+			return self::$theme->get($field_name);
189 189
 		}
190 190
 
191 191
 		return $default;
@@ -200,20 +200,20 @@  discard block
 block discarded – undo
200 200
 
201 201
 		static $themes;
202 202
 
203
-		if ( isset( $themes  ) ) {
203
+		if (isset($themes)) {
204 204
 			return $themes;
205 205
 		}
206 206
 
207
-		$wp_themes = wp_get_themes( array( 'allowed' => true ) );
207
+		$wp_themes = wp_get_themes(array('allowed' => true));
208 208
 
209 209
 		/** @var WP_Theme $theme */
210
-		foreach ( $wp_themes as $theme ) {
210
+		foreach ($wp_themes as $theme) {
211 211
 
212 212
 			// make keys names (rather than slugs) for backwards compat
213
-			$themes[ $theme->get( 'Name' ) ] = $theme;
213
+			$themes[$theme->get('Name')] = $theme;
214 214
 		}
215 215
 
216
-		$themes = apply_filters( 'tts_allowed_themes', $themes );
216
+		$themes = apply_filters('tts_allowed_themes', $themes);
217 217
 
218 218
 		return $themes;
219 219
 	}
@@ -223,12 +223,12 @@  discard block
 block discarded – undo
223 223
 	 */
224 224
 	static function init() {
225 225
 
226
-		if ( self::can_switch_themes() ) {
227
-			add_action( 'admin_bar_menu', array( __CLASS__, 'admin_bar_menu' ), 90 );
228
-			add_action( 'wp_ajax_tts_set_theme', array( __CLASS__, 'set_theme' ) );
226
+		if (self::can_switch_themes()) {
227
+			add_action('admin_bar_menu', array(__CLASS__, 'admin_bar_menu'), 90);
228
+			add_action('wp_ajax_tts_set_theme', array(__CLASS__, 'set_theme'));
229 229
 		}
230 230
 
231
-		load_plugin_textdomain( 'toolbar-theme-switcher', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' );
231
+		load_plugin_textdomain('toolbar-theme-switcher', false, dirname(plugin_basename(__FILE__)) . '/lang');
232 232
 	}
233 233
 
234 234
 	/**
@@ -236,25 +236,25 @@  discard block
 block discarded – undo
236 236
 	 *
237 237
 	 * @param WP_Admin_Bar $wp_admin_bar
238 238
 	 */
239
-	static function admin_bar_menu( $wp_admin_bar ) {
239
+	static function admin_bar_menu($wp_admin_bar) {
240 240
 		$themes  = self::get_allowed_themes();
241
-		$current = empty( self::$theme ) ? wp_get_theme() : self::$theme;
242
-		$title   = apply_filters( 'tts_root_title', sprintf( __( 'Theme: %s', 'toolbar-theme-switcher' ), $current->display( 'Name' ) ) );
241
+		$current = empty(self::$theme) ? wp_get_theme() : self::$theme;
242
+		$title   = apply_filters('tts_root_title', sprintf(__('Theme: %s', 'toolbar-theme-switcher'), $current->display('Name')));
243 243
 
244
-		$wp_admin_bar->add_menu( array(
244
+		$wp_admin_bar->add_menu(array(
245 245
 			'id'    => 'toolbar_theme_switcher',
246 246
 			'title' => $title,
247
-			'href'  => admin_url( 'themes.php' ),
248
-		) );
247
+			'href'  => admin_url('themes.php'),
248
+		));
249 249
 
250 250
 		/** @var WP_Theme $theme */
251
-		foreach ( $themes as $theme ) {
252
-			$wp_admin_bar->add_menu( array(
251
+		foreach ($themes as $theme) {
252
+			$wp_admin_bar->add_menu(array(
253 253
 				'id'     => $theme['Stylesheet'],
254
-				'title'  => $theme->display( 'Name' ),
255
-				'href'   => $current == $theme ? null : add_query_arg( array( 'action' => 'tts_set_theme', 'theme' => urlencode( $theme->get_stylesheet() ) ), admin_url( 'admin-ajax.php' ) ),
254
+				'title'  => $theme->display('Name'),
255
+				'href'   => $current == $theme ? null : add_query_arg(array('action' => 'tts_set_theme', 'theme' => urlencode($theme->get_stylesheet())), admin_url('admin-ajax.php')),
256 256
 				'parent' => 'toolbar_theme_switcher',
257
-			) );
257
+			));
258 258
 		}
259 259
 	}
260 260
 
@@ -264,13 +264,13 @@  discard block
 block discarded – undo
264 264
 	static function set_theme() {
265 265
 
266 266
 		$stylesheet = $_REQUEST['theme'];
267
-		$theme      = wp_get_theme( $stylesheet );
267
+		$theme      = wp_get_theme($stylesheet);
268 268
 
269
-		if ( $theme->exists() && $theme->is_allowed() ) {
270
-			setcookie( self::get_cookie_name(), $theme->get_stylesheet(), strtotime( '+1 year' ), COOKIEPATH );
269
+		if ($theme->exists() && $theme->is_allowed()) {
270
+			setcookie(self::get_cookie_name(), $theme->get_stylesheet(), strtotime('+1 year'), COOKIEPATH);
271 271
 		}
272 272
 
273
-		wp_safe_redirect( wp_get_referer() );
273
+		wp_safe_redirect(wp_get_referer());
274 274
 		die;
275 275
 	}
276 276
 }
277 277
\ No newline at end of file
Please login to merge, or discard this patch.