@@ -276,7 +276,7 @@ |
||
| 276 | 276 | * Returns field from theme data if cookie is set to valid theme. |
| 277 | 277 | * |
| 278 | 278 | * @param string $field_name |
| 279 | - * @param mixed $default |
|
| 279 | + * @param string $default |
|
| 280 | 280 | * |
| 281 | 281 | * @deprecated :2.0 |
| 282 | 282 | * |
@@ -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,23 +24,23 @@ 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 | 31 | self::check_reset(); |
| 32 | 32 | self::load_cookie(); |
| 33 | 33 | |
| 34 | - if ( empty( self::$theme ) ) { |
|
| 34 | + if (empty(self::$theme)) { |
|
| 35 | 35 | return; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - add_filter( 'pre_option_template', array( self::$theme, 'get_template' ) ); |
|
| 39 | - add_filter( 'pre_option_stylesheet', array( self::$theme, 'get_stylesheet' ) ); |
|
| 40 | - add_filter( 'pre_option_stylesheet_root', array( self::$theme, 'get_theme_root' ) ); |
|
| 38 | + add_filter('pre_option_template', array(self::$theme, 'get_template')); |
|
| 39 | + add_filter('pre_option_stylesheet', array(self::$theme, 'get_stylesheet')); |
|
| 40 | + add_filter('pre_option_stylesheet_root', array(self::$theme, 'get_theme_root')); |
|
| 41 | 41 | $parent = self::$theme->parent(); |
| 42 | - add_filter( 'pre_option_template_root', array( empty( $parent ) ? self::$theme : $parent, 'get_theme_root' ) ); |
|
| 43 | - add_filter( 'pre_option_current_theme', '__return_false' ); |
|
| 42 | + add_filter('pre_option_template_root', array(empty($parent) ? self::$theme : $parent, 'get_theme_root')); |
|
| 43 | + add_filter('pre_option_current_theme', '__return_false'); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -48,10 +48,10 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public static function check_reset() { |
| 50 | 50 | |
| 51 | - if ( ! empty( filter_input( INPUT_GET, 'tts_reset' ) ) ) { |
|
| 52 | - setcookie( self::get_cookie_name(), '', 1 ); |
|
| 51 | + if ( ! empty(filter_input(INPUT_GET, 'tts_reset'))) { |
|
| 52 | + setcookie(self::get_cookie_name(), '', 1); |
|
| 53 | 53 | nocache_headers(); |
| 54 | - wp_safe_redirect( home_url() ); |
|
| 54 | + wp_safe_redirect(home_url()); |
|
| 55 | 55 | die; |
| 56 | 56 | } |
| 57 | 57 | } |
@@ -63,9 +63,9 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | public static function can_switch_themes() { |
| 65 | 65 | |
| 66 | - $capability = apply_filters( 'tts_capability', 'switch_themes' ); |
|
| 66 | + $capability = apply_filters('tts_capability', 'switch_themes'); |
|
| 67 | 67 | |
| 68 | - return apply_filters( 'tts_can_switch_themes', current_user_can( $capability ) ); |
|
| 68 | + return apply_filters('tts_can_switch_themes', current_user_can($capability)); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -73,17 +73,17 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public static function load_cookie() { |
| 75 | 75 | |
| 76 | - $theme_name = filter_input( INPUT_COOKIE, self::get_cookie_name() ); |
|
| 76 | + $theme_name = filter_input(INPUT_COOKIE, self::get_cookie_name()); |
|
| 77 | 77 | |
| 78 | - if ( ! $theme_name ) { |
|
| 78 | + if ( ! $theme_name) { |
|
| 79 | 79 | return; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - $theme = wp_get_theme( $theme_name ); |
|
| 82 | + $theme = wp_get_theme($theme_name); |
|
| 83 | 83 | |
| 84 | 84 | if ( |
| 85 | 85 | $theme->exists() |
| 86 | - && $theme->get( 'Name' ) !== get_option( 'current_theme' ) |
|
| 86 | + && $theme->get('Name') !== get_option('current_theme') |
|
| 87 | 87 | && $theme->is_allowed() |
| 88 | 88 | ) { |
| 89 | 89 | self::$theme = $theme; |
@@ -99,8 +99,8 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | static $hash; |
| 101 | 101 | |
| 102 | - if ( empty( $hash ) ) { |
|
| 103 | - $hash = 'wordpress_tts_theme_' . md5( home_url( '', 'http' ) ); |
|
| 102 | + if (empty($hash)) { |
|
| 103 | + $hash = 'wordpress_tts_theme_' . md5(home_url('', 'http')); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | return $hash; |
@@ -115,20 +115,20 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | static $themes; |
| 117 | 117 | |
| 118 | - if ( isset( $themes ) ) { |
|
| 118 | + if (isset($themes)) { |
|
| 119 | 119 | return $themes; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - $wp_themes = wp_get_themes( array( 'allowed' => true ) ); |
|
| 122 | + $wp_themes = wp_get_themes(array('allowed' => true)); |
|
| 123 | 123 | |
| 124 | 124 | /** @var WP_Theme $theme */ |
| 125 | - foreach ( $wp_themes as $theme ) { |
|
| 125 | + foreach ($wp_themes as $theme) { |
|
| 126 | 126 | |
| 127 | 127 | // Make keys names (rather than slugs) for backwards compat. |
| 128 | - $themes[ $theme->get( 'Name' ) ] = $theme; |
|
| 128 | + $themes[$theme->get('Name')] = $theme; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - $themes = apply_filters( 'tts_allowed_themes', $themes ); |
|
| 131 | + $themes = apply_filters('tts_allowed_themes', $themes); |
|
| 132 | 132 | |
| 133 | 133 | return $themes; |
| 134 | 134 | } |
@@ -138,12 +138,12 @@ discard block |
||
| 138 | 138 | */ |
| 139 | 139 | public static function init() { |
| 140 | 140 | |
| 141 | - if ( self::can_switch_themes() ) { |
|
| 142 | - add_action( 'admin_bar_menu', array( __CLASS__, 'admin_bar_menu' ), 90 ); |
|
| 143 | - add_action( 'wp_ajax_tts_set_theme', array( __CLASS__, 'set_theme' ) ); |
|
| 141 | + if (self::can_switch_themes()) { |
|
| 142 | + add_action('admin_bar_menu', array(__CLASS__, 'admin_bar_menu'), 90); |
|
| 143 | + add_action('wp_ajax_tts_set_theme', array(__CLASS__, 'set_theme')); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - load_plugin_textdomain( 'toolbar-theme-switcher', false, dirname( plugin_basename( __FILE__ ) ) . '/lang' ); |
|
| 146 | + load_plugin_textdomain('toolbar-theme-switcher', false, dirname(plugin_basename(__FILE__)) . '/lang'); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -151,35 +151,35 @@ discard block |
||
| 151 | 151 | * |
| 152 | 152 | * @param WP_Admin_Bar $wp_admin_bar Admin bar instance. |
| 153 | 153 | */ |
| 154 | - public static function admin_bar_menu( $wp_admin_bar ) { |
|
| 154 | + public static function admin_bar_menu($wp_admin_bar) { |
|
| 155 | 155 | $themes = self::get_allowed_themes(); |
| 156 | - $current = empty( self::$theme ) ? wp_get_theme() : self::$theme; |
|
| 157 | - unset( $themes[ $current->get( 'Name' ) ] ); |
|
| 158 | - uksort( $themes, array( __CLASS__, 'sort_core_themes' ) ); |
|
| 156 | + $current = empty(self::$theme) ? wp_get_theme() : self::$theme; |
|
| 157 | + unset($themes[$current->get('Name')]); |
|
| 158 | + uksort($themes, array(__CLASS__, 'sort_core_themes')); |
|
| 159 | 159 | |
| 160 | - $title = apply_filters( 'tts_root_title', sprintf( __( 'Theme: %s', 'toolbar-theme-switcher' ), $current->display( 'Name' ) ) ); |
|
| 160 | + $title = apply_filters('tts_root_title', sprintf(__('Theme: %s', 'toolbar-theme-switcher'), $current->display('Name'))); |
|
| 161 | 161 | |
| 162 | - $wp_admin_bar->add_menu( array( |
|
| 162 | + $wp_admin_bar->add_menu(array( |
|
| 163 | 163 | 'id' => 'toolbar_theme_switcher', |
| 164 | 164 | 'title' => $title, |
| 165 | - 'href' => admin_url( 'themes.php' ), |
|
| 166 | - ) ); |
|
| 165 | + 'href' => admin_url('themes.php'), |
|
| 166 | + )); |
|
| 167 | 167 | |
| 168 | - $ajax_url = admin_url( 'admin-ajax.php' ); |
|
| 168 | + $ajax_url = admin_url('admin-ajax.php'); |
|
| 169 | 169 | |
| 170 | - foreach ( $themes as $theme ) { |
|
| 170 | + foreach ($themes as $theme) { |
|
| 171 | 171 | |
| 172 | - $href = add_query_arg( array( |
|
| 172 | + $href = add_query_arg(array( |
|
| 173 | 173 | 'action' => 'tts_set_theme', |
| 174 | - 'theme' => urlencode( $theme->get_stylesheet() ), |
|
| 175 | - ), $ajax_url ); |
|
| 174 | + 'theme' => urlencode($theme->get_stylesheet()), |
|
| 175 | + ), $ajax_url); |
|
| 176 | 176 | |
| 177 | - $wp_admin_bar->add_menu( array( |
|
| 177 | + $wp_admin_bar->add_menu(array( |
|
| 178 | 178 | 'id' => $theme['Stylesheet'], |
| 179 | - 'title' => $theme->display( 'Name' ), |
|
| 179 | + 'title' => $theme->display('Name'), |
|
| 180 | 180 | 'href' => $href, |
| 181 | 181 | 'parent' => 'toolbar_theme_switcher', |
| 182 | - ) ); |
|
| 182 | + )); |
|
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | * |
| 192 | 192 | * @return int |
| 193 | 193 | */ |
| 194 | - public static function sort_core_themes( $theme_a, $theme_b ) { |
|
| 194 | + public static function sort_core_themes($theme_a, $theme_b) { |
|
| 195 | 195 | |
| 196 | 196 | static $twenties = array( |
| 197 | 197 | 'Twenty Ten', |
@@ -207,17 +207,17 @@ discard block |
||
| 207 | 207 | 'Twenty Twenty', |
| 208 | 208 | ); |
| 209 | 209 | |
| 210 | - if ( 0 === strpos( $theme_a, 'Twenty' ) && 0 === strpos( $theme_b, 'Twenty' ) ) { |
|
| 210 | + if (0 === strpos($theme_a, 'Twenty') && 0 === strpos($theme_b, 'Twenty')) { |
|
| 211 | 211 | |
| 212 | - $index_a = array_search( $theme_a, $twenties, true ); |
|
| 213 | - $index_b = array_search( $theme_b, $twenties, true ); |
|
| 212 | + $index_a = array_search($theme_a, $twenties, true); |
|
| 213 | + $index_b = array_search($theme_b, $twenties, true); |
|
| 214 | 214 | |
| 215 | - if ( false !== $index_a && false !== $index_b ) { |
|
| 216 | - return ( $index_a < $index_b ) ? - 1 : 1; |
|
| 215 | + if (false !== $index_a && false !== $index_b) { |
|
| 216 | + return ($index_a < $index_b) ? -1 : 1; |
|
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - return strcasecmp( $theme_a, $theme_b ); |
|
| 220 | + return strcasecmp($theme_a, $theme_b); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -225,14 +225,14 @@ discard block |
||
| 225 | 225 | */ |
| 226 | 226 | public static function set_theme() { |
| 227 | 227 | |
| 228 | - $stylesheet = filter_input( INPUT_GET, 'theme' ); |
|
| 229 | - $theme = wp_get_theme( $stylesheet ); |
|
| 228 | + $stylesheet = filter_input(INPUT_GET, 'theme'); |
|
| 229 | + $theme = wp_get_theme($stylesheet); |
|
| 230 | 230 | |
| 231 | - if ( $theme->exists() && $theme->is_allowed() ) { |
|
| 232 | - setcookie( self::get_cookie_name(), $theme->get_stylesheet(), strtotime( '+1 year' ), COOKIEPATH ); |
|
| 231 | + if ($theme->exists() && $theme->is_allowed()) { |
|
| 232 | + setcookie(self::get_cookie_name(), $theme->get_stylesheet(), strtotime('+1 year'), COOKIEPATH); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - wp_safe_redirect( wp_get_referer() ); |
|
| 235 | + wp_safe_redirect(wp_get_referer()); |
|
| 236 | 236 | die; |
| 237 | 237 | } |
| 238 | 238 | |
@@ -246,9 +246,9 @@ discard block |
||
| 246 | 246 | * |
| 247 | 247 | * @return bool |
| 248 | 248 | */ |
| 249 | - public static function is_allowed( $theme ) { |
|
| 249 | + public static function is_allowed($theme) { |
|
| 250 | 250 | |
| 251 | - return array_key_exists( $theme->get( 'Name' ), self::get_allowed_themes() ); |
|
| 251 | + return array_key_exists($theme->get('Name'), self::get_allowed_themes()); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -260,9 +260,9 @@ discard block |
||
| 260 | 260 | * |
| 261 | 261 | * @return string |
| 262 | 262 | */ |
| 263 | - public static function template( $template ) { |
|
| 263 | + public static function template($template) { |
|
| 264 | 264 | |
| 265 | - return self::get_theme_field( 'Template', $template ); |
|
| 265 | + return self::get_theme_field('Template', $template); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -274,9 +274,9 @@ discard block |
||
| 274 | 274 | * |
| 275 | 275 | * @return string |
| 276 | 276 | */ |
| 277 | - public static function stylesheet( $stylesheet ) { |
|
| 277 | + public static function stylesheet($stylesheet) { |
|
| 278 | 278 | |
| 279 | - return self::get_theme_field( 'Stylesheet', $stylesheet ); |
|
| 279 | + return self::get_theme_field('Stylesheet', $stylesheet); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -289,10 +289,10 @@ discard block |
||
| 289 | 289 | * |
| 290 | 290 | * @return mixed |
| 291 | 291 | */ |
| 292 | - public static function get_theme_field( $field_name, $default = false ) { |
|
| 292 | + public static function get_theme_field($field_name, $default = false) { |
|
| 293 | 293 | |
| 294 | - if ( ! empty( self::$theme ) ) { |
|
| 295 | - return self::$theme->get( $field_name ); |
|
| 294 | + if ( ! empty(self::$theme)) { |
|
| 295 | + return self::$theme->get($field_name); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | return $default; |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | DEALINGS IN THE SOFTWARE. |
| 30 | 30 | */ |
| 31 | 31 | |
| 32 | -if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
|
|
| 32 | +if (file_exists(__DIR__ . '/vendor/autoload.php')) {
|
|
| 33 | 33 | require __DIR__ . '/vendor/autoload.php'; |
| 34 | 34 | } |
| 35 | 35 | |