@@ -13,8 +13,8 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | public static function on_load() { |
| 15 | 15 | |
| 16 | - add_action( 'setup_theme', array( __CLASS__, 'setup_theme' ) ); |
|
| 17 | - add_action( 'init', array( __CLASS__, 'init' ) ); |
|
| 16 | + add_action('setup_theme', array(__CLASS__, 'setup_theme')); |
|
| 17 | + add_action('init', array(__CLASS__, 'init')); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
@@ -24,29 +24,29 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | global $pagenow; |
| 26 | 26 | |
| 27 | - if ( ( is_admin() && 'themes.php' == $pagenow ) || ! self::can_switch_themes() ) { |
|
| 27 | + if ((is_admin() && 'themes.php' == $pagenow) || ! self::can_switch_themes()) { |
|
| 28 | 28 | return; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - if ( ! empty( filter_input( INPUT_GET, 'tts_reset' ) ) ) { |
|
| 32 | - setcookie( self::get_cookie_name(), '', 1 ); |
|
| 31 | + if ( ! empty(filter_input(INPUT_GET, 'tts_reset'))) { |
|
| 32 | + setcookie(self::get_cookie_name(), '', 1); |
|
| 33 | 33 | nocache_headers(); |
| 34 | - wp_safe_redirect( home_url() ); |
|
| 34 | + wp_safe_redirect(home_url()); |
|
| 35 | 35 | die; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | self::load_cookie(); |
| 39 | 39 | |
| 40 | - if ( empty( self::$theme ) ) { |
|
| 40 | + if (empty(self::$theme)) { |
|
| 41 | 41 | return; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - add_filter( 'pre_option_template', array( self::$theme, 'get_template' ) ); |
|
| 45 | - add_filter( 'pre_option_stylesheet', array( self::$theme, 'get_stylesheet' ) ); |
|
| 46 | - add_filter( 'pre_option_stylesheet_root', array( self::$theme, 'get_theme_root' ) ); |
|
| 44 | + add_filter('pre_option_template', array(self::$theme, 'get_template')); |
|
| 45 | + add_filter('pre_option_stylesheet', array(self::$theme, 'get_stylesheet')); |
|
| 46 | + add_filter('pre_option_stylesheet_root', array(self::$theme, 'get_theme_root')); |
|
| 47 | 47 | $parent = self::$theme->parent(); |
| 48 | - add_filter( 'pre_option_template_root', array( empty( $parent ) ? self::$theme : $parent, 'get_theme_root' ) ); |
|
| 49 | - add_filter( 'pre_option_current_theme', '__return_false' ); |
|
| 48 | + add_filter('pre_option_template_root', array(empty($parent) ? self::$theme : $parent, 'get_theme_root')); |
|
| 49 | + add_filter('pre_option_current_theme', '__return_false'); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -56,9 +56,9 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | public static function can_switch_themes() { |
| 58 | 58 | |
| 59 | - $capability = apply_filters( 'tts_capability', 'switch_themes' ); |
|
| 59 | + $capability = apply_filters('tts_capability', 'switch_themes'); |
|
| 60 | 60 | |
| 61 | - return apply_filters( 'tts_can_switch_themes', current_user_can( $capability ) ); |
|
| 61 | + return apply_filters('tts_can_switch_themes', current_user_can($capability)); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -66,17 +66,17 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public static function load_cookie() { |
| 68 | 68 | |
| 69 | - $theme_name = filter_input( INPUT_COOKIE, self::get_cookie_name() ); |
|
| 69 | + $theme_name = filter_input(INPUT_COOKIE, self::get_cookie_name()); |
|
| 70 | 70 | |
| 71 | - if ( ! $theme_name ) { |
|
| 71 | + if ( ! $theme_name) { |
|
| 72 | 72 | return; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - $theme = wp_get_theme( $theme_name ); |
|
| 75 | + $theme = wp_get_theme($theme_name); |
|
| 76 | 76 | |
| 77 | 77 | if ( |
| 78 | 78 | $theme->exists() |
| 79 | - && $theme->get( 'Name' ) !== get_option( 'current_theme' ) |
|
| 79 | + && $theme->get('Name') !== get_option('current_theme') |
|
| 80 | 80 | && $theme->is_allowed() |
| 81 | 81 | ) { |
| 82 | 82 | self::$theme = $theme; |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | |
| 93 | 93 | static $hash; |
| 94 | 94 | |
| 95 | - if ( empty( $hash ) ) { |
|
| 96 | - $hash = 'wordpress_tts_theme_' . md5( home_url( '', 'http' ) ); |
|
| 95 | + if (empty($hash)) { |
|
| 96 | + $hash = 'wordpress_tts_theme_' . md5(home_url('', 'http')); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | return $hash; |
@@ -108,20 +108,20 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | static $themes; |
| 110 | 110 | |
| 111 | - if ( isset( $themes ) ) { |
|
| 111 | + if (isset($themes)) { |
|
| 112 | 112 | return $themes; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - $wp_themes = wp_get_themes( array( 'allowed' => true ) ); |
|
| 115 | + $wp_themes = wp_get_themes(array('allowed' => true)); |
|
| 116 | 116 | |
| 117 | 117 | /** @var WP_Theme $theme */ |
| 118 | - foreach ( $wp_themes as $theme ) { |
|
| 118 | + foreach ($wp_themes as $theme) { |
|
| 119 | 119 | |
| 120 | 120 | // Make keys names (rather than slugs) for backwards compat. |
| 121 | - $themes[ $theme->get( 'Name' ) ] = $theme; |
|
| 121 | + $themes[$theme->get('Name')] = $theme; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - $themes = apply_filters( 'tts_allowed_themes', $themes ); |
|
| 124 | + $themes = apply_filters('tts_allowed_themes', $themes); |
|
| 125 | 125 | |
| 126 | 126 | return $themes; |
| 127 | 127 | } |
@@ -131,12 +131,12 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | public static function init() { |
| 133 | 133 | |
| 134 | - if ( self::can_switch_themes() ) { |
|
| 135 | - add_action( 'admin_bar_menu', array( __CLASS__, 'admin_bar_menu' ), 90 ); |
|
| 136 | - add_action( 'wp_ajax_tts_set_theme', array( __CLASS__, 'set_theme' ) ); |
|
| 134 | + if (self::can_switch_themes()) { |
|
| 135 | + add_action('admin_bar_menu', array(__CLASS__, 'admin_bar_menu'), 90); |
|
| 136 | + add_action('wp_ajax_tts_set_theme', array(__CLASS__, 'set_theme')); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - load_plugin_textdomain( 'toolbar-theme-switcher', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' ); |
|
| 139 | + load_plugin_textdomain('toolbar-theme-switcher', false, dirname(plugin_basename(__FILE__)) . '/lang'); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
@@ -144,35 +144,35 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | * @param WP_Admin_Bar $wp_admin_bar Admin bar instance. |
| 146 | 146 | */ |
| 147 | - public static function admin_bar_menu( $wp_admin_bar ) { |
|
| 147 | + public static function admin_bar_menu($wp_admin_bar) { |
|
| 148 | 148 | $themes = self::get_allowed_themes(); |
| 149 | - $current = empty( self::$theme ) ? wp_get_theme() : self::$theme; |
|
| 150 | - unset( $themes[ $current->get( 'Name' ) ] ); |
|
| 151 | - uksort( $themes, array( __CLASS__, 'sort_core_themes' ) ); |
|
| 149 | + $current = empty(self::$theme) ? wp_get_theme() : self::$theme; |
|
| 150 | + unset($themes[$current->get('Name')]); |
|
| 151 | + uksort($themes, array(__CLASS__, 'sort_core_themes')); |
|
| 152 | 152 | |
| 153 | - $title = apply_filters( 'tts_root_title', sprintf( __( 'Theme: %s', 'toolbar-theme-switcher' ), $current->display( 'Name' ) ) ); |
|
| 153 | + $title = apply_filters('tts_root_title', sprintf(__('Theme: %s', 'toolbar-theme-switcher'), $current->display('Name'))); |
|
| 154 | 154 | |
| 155 | - $wp_admin_bar->add_menu( array( |
|
| 155 | + $wp_admin_bar->add_menu(array( |
|
| 156 | 156 | 'id' => 'toolbar_theme_switcher', |
| 157 | 157 | 'title' => $title, |
| 158 | - 'href' => admin_url( 'themes.php' ), |
|
| 159 | - ) ); |
|
| 158 | + 'href' => admin_url('themes.php'), |
|
| 159 | + )); |
|
| 160 | 160 | |
| 161 | - $ajax_url = admin_url( 'admin-ajax.php' ); |
|
| 161 | + $ajax_url = admin_url('admin-ajax.php'); |
|
| 162 | 162 | |
| 163 | - foreach ( $themes as $theme ) { |
|
| 163 | + foreach ($themes as $theme) { |
|
| 164 | 164 | |
| 165 | - $href = add_query_arg( array( |
|
| 165 | + $href = add_query_arg(array( |
|
| 166 | 166 | 'action' => 'tts_set_theme', |
| 167 | - 'theme' => urlencode( $theme->get_stylesheet() ), |
|
| 168 | - ), $ajax_url ); |
|
| 167 | + 'theme' => urlencode($theme->get_stylesheet()), |
|
| 168 | + ), $ajax_url); |
|
| 169 | 169 | |
| 170 | - $wp_admin_bar->add_menu( array( |
|
| 170 | + $wp_admin_bar->add_menu(array( |
|
| 171 | 171 | 'id' => $theme['Stylesheet'], |
| 172 | - 'title' => $theme->display( 'Name' ), |
|
| 172 | + 'title' => $theme->display('Name'), |
|
| 173 | 173 | 'href' => $href, |
| 174 | 174 | 'parent' => 'toolbar_theme_switcher', |
| 175 | - ) ); |
|
| 175 | + )); |
|
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * |
| 185 | 185 | * @return int |
| 186 | 186 | */ |
| 187 | - public static function sort_core_themes( $theme_a, $theme_b ) { |
|
| 187 | + public static function sort_core_themes($theme_a, $theme_b) { |
|
| 188 | 188 | |
| 189 | 189 | static $twenties = array( |
| 190 | 190 | 'Twenty Ten', |
@@ -200,17 +200,17 @@ discard block |
||
| 200 | 200 | 'Twenty Twenty', |
| 201 | 201 | ); |
| 202 | 202 | |
| 203 | - if ( 0 === strpos( $theme_a, 'Twenty' ) && 0 === strpos( $theme_b, 'Twenty' ) ) { |
|
| 203 | + if (0 === strpos($theme_a, 'Twenty') && 0 === strpos($theme_b, 'Twenty')) { |
|
| 204 | 204 | |
| 205 | - $index_a = array_search( $theme_a, $twenties, true ); |
|
| 206 | - $index_b = array_search( $theme_b, $twenties, true ); |
|
| 205 | + $index_a = array_search($theme_a, $twenties, true); |
|
| 206 | + $index_b = array_search($theme_b, $twenties, true); |
|
| 207 | 207 | |
| 208 | - if ( false !== $index_a && false !== $index_b ) { |
|
| 209 | - return ( $index_a < $index_b ) ? - 1 : 1; |
|
| 208 | + if (false !== $index_a && false !== $index_b) { |
|
| 209 | + return ($index_a < $index_b) ? -1 : 1; |
|
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - return strcasecmp( $theme_a, $theme_b ); |
|
| 213 | + return strcasecmp($theme_a, $theme_b); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
@@ -218,14 +218,14 @@ discard block |
||
| 218 | 218 | */ |
| 219 | 219 | public static function set_theme() { |
| 220 | 220 | |
| 221 | - $stylesheet = filter_input( INPUT_GET, 'theme' ); |
|
| 222 | - $theme = wp_get_theme( $stylesheet ); |
|
| 221 | + $stylesheet = filter_input(INPUT_GET, 'theme'); |
|
| 222 | + $theme = wp_get_theme($stylesheet); |
|
| 223 | 223 | |
| 224 | - if ( $theme->exists() && $theme->is_allowed() ) { |
|
| 225 | - setcookie( self::get_cookie_name(), $theme->get_stylesheet(), strtotime( '+1 year' ), COOKIEPATH ); |
|
| 224 | + if ($theme->exists() && $theme->is_allowed()) { |
|
| 225 | + setcookie(self::get_cookie_name(), $theme->get_stylesheet(), strtotime('+1 year'), COOKIEPATH); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | - wp_safe_redirect( wp_get_referer() ); |
|
| 228 | + wp_safe_redirect(wp_get_referer()); |
|
| 229 | 229 | die; |
| 230 | 230 | } |
| 231 | 231 | |
@@ -239,9 +239,9 @@ discard block |
||
| 239 | 239 | * |
| 240 | 240 | * @return bool |
| 241 | 241 | */ |
| 242 | - public static function is_allowed( $theme ) { |
|
| 242 | + public static function is_allowed($theme) { |
|
| 243 | 243 | |
| 244 | - return array_key_exists( $theme->get( 'Name' ), self::get_allowed_themes() ); |
|
| 244 | + return array_key_exists($theme->get('Name'), self::get_allowed_themes()); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | * |
| 254 | 254 | * @return string |
| 255 | 255 | */ |
| 256 | - public static function template( $template ) { |
|
| 256 | + public static function template($template) { |
|
| 257 | 257 | |
| 258 | - return self::get_theme_field( 'Template', $template ); |
|
| 258 | + return self::get_theme_field('Template', $template); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -267,9 +267,9 @@ discard block |
||
| 267 | 267 | * |
| 268 | 268 | * @return string |
| 269 | 269 | */ |
| 270 | - public static function stylesheet( $stylesheet ) { |
|
| 270 | + public static function stylesheet($stylesheet) { |
|
| 271 | 271 | |
| 272 | - return self::get_theme_field( 'Stylesheet', $stylesheet ); |
|
| 272 | + return self::get_theme_field('Stylesheet', $stylesheet); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -282,10 +282,10 @@ discard block |
||
| 282 | 282 | * |
| 283 | 283 | * @return mixed |
| 284 | 284 | */ |
| 285 | - public static function get_theme_field( $field_name, $default = false ) { |
|
| 285 | + public static function get_theme_field($field_name, $default = false) { |
|
| 286 | 286 | |
| 287 | - if ( ! empty( self::$theme ) ) { |
|
| 288 | - return self::$theme->get( $field_name ); |
|
| 287 | + if ( ! empty(self::$theme)) { |
|
| 288 | + return self::$theme->get($field_name); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | return $default; |