Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme.php

    r42242 r42343  
    194194                        if ( self::$persistently_cache ) {
    195195                                wp_cache_add_global_groups( 'themes' );
    196                                 if ( is_int( self::$persistently_cache ) )
     196                                if ( is_int( self::$persistently_cache ) ) {
    197197                                        self::$cache_expiration = self::$persistently_cache;
     198                                }
    198199                        } else {
    199200                                wp_cache_add_non_persistent_groups( 'themes' );
    … …  
    211212
    212213                $this->cache_hash = md5( $this->theme_root . '/' . $this->stylesheet );
    213                 $theme_file = $this->stylesheet . '/style.css';
     214                $theme_file       = $this->stylesheet . '/style.css';
    214215
    215216                $cache = $this->cache_get( 'theme' );
    … …  
    217218                if ( is_array( $cache ) ) {
    218219                        foreach ( array( 'errors', 'headers', 'template' ) as $key ) {
    219                                 if ( isset( $cache[ $key ] ) )
     220                                if ( isset( $cache[ $key ] ) ) {
    220221                                        $this->$key = $cache[ $key ];
    221                         }
    222                         if ( $this->errors )
     222                                }
     223                        }
     224                        if ( $this->errors ) {
    223225                                return;
    224                         if ( isset( $cache['theme_root_template'] ) )
     226                        }
     227                        if ( isset( $cache['theme_root_template'] ) ) {
    225228                                $theme_root_template = $cache['theme_root_template'];
     229                        }
    226230                } elseif ( ! file_exists( $this->theme_root . '/' . $theme_file ) ) {
    227231                        $this->headers['Name'] = $this->stylesheet;
    228                         if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet ) )
     232                        if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet ) ) {
    229233                                $this->errors = new WP_Error( 'theme_not_found', sprintf( __( 'The theme directory "%s" does not exist.' ), esc_html( $this->stylesheet ) ) );
    230                         else
     234                        } else {
    231235                                $this->errors = new WP_Error( 'theme_no_stylesheet', __( 'Stylesheet is missing.' ) );
     236                        }
    232237                        $this->template = $this->stylesheet;
    233                         $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
    234                         if ( ! file_exists( $this->theme_root ) ) // Don't cache this one.
     238                        $this->cache_add(
     239                                'theme', array(
     240                                        'headers'    => $this->headers,
     241                                        'errors'     => $this->errors,
     242                                        'stylesheet' => $this->stylesheet,
     243                                        'template'   => $this->template,
     244                                )
     245                        );
     246                        if ( ! file_exists( $this->theme_root ) ) { // Don't cache this one.
    235247                                $this->errors->add( 'theme_root_missing', __( 'ERROR: The themes directory is either empty or doesn’t exist. Please check your installation.' ) );
     248                        }
    236249                        return;
    237250                } elseif ( ! is_readable( $this->theme_root . '/' . $theme_file ) ) {
    238251                        $this->headers['Name'] = $this->stylesheet;
    239                         $this->errors = new WP_Error( 'theme_stylesheet_not_readable', __( 'Stylesheet is not readable.' ) );
    240                         $this->template = $this->stylesheet;
    241                         $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
     252                        $this->errors          = new WP_Error( 'theme_stylesheet_not_readable', __( 'Stylesheet is not readable.' ) );
     253                        $this->template        = $this->stylesheet;
     254                        $this->cache_add(
     255                                'theme', array(
     256                                        'headers'    => $this->headers,
     257                                        'errors'     => $this->errors,
     258                                        'stylesheet' => $this->stylesheet,
     259                                        'template'   => $this->template,
     260                                )
     261                        );
    242262                        return;
    243263                } else {
    … …  
    246266                        // Properly identify default themes that are inside a directory within wp-content/themes.
    247267                        if ( $default_theme_slug = array_search( $this->headers['Name'], self::$default_themes ) ) {
    248                                 if ( basename( $this->stylesheet ) != $default_theme_slug )
     268                                if ( basename( $this->stylesheet ) != $default_theme_slug ) {
    249269                                        $this->headers['Name'] .= '/' . $this->stylesheet;
     270                                }
    250271                        }
    251272                }
    … …  
    254275                        /* translators: %s: Template */
    255276                        $this->errors = new WP_Error( 'theme_child_invalid', sprintf( __( 'The theme defines itself as its parent theme. Please check the %s header.' ), '<code>Template</code>' ) );
    256                         $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet ) );
     277                        $this->cache_add(
     278                                'theme', array(
     279                                        'headers'    => $this->headers,
     280                                        'errors'     => $this->errors,
     281                                        'stylesheet' => $this->stylesheet,
     282                                )
     283                        );
    257284
    258285                        return;
    … …  
    271298                                );
    272299                                $this->errors = new WP_Error( 'theme_no_index', $error_message );
    273                                 $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
     300                                $this->cache_add(
     301                                        'theme', array(
     302                                                'headers'    => $this->headers,
     303                                                'errors'     => $this->errors,
     304                                                'stylesheet' => $this->stylesheet,
     305                                                'template'   => $this->template,
     306                                        )
     307                                );
    274308                                return;
    275309                        }
    … …  
    290324                                // Parent theme is missing.
    291325                                $this->errors = new WP_Error( 'theme_no_parent', sprintf( __( 'The parent theme is missing. Please install the "%s" parent theme.' ), esc_html( $this->template ) ) );
    292                                 $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
     326                                $this->cache_add(
     327                                        'theme', array(
     328                                                'headers'    => $this->headers,
     329                                                'errors'     => $this->errors,
     330                                                'stylesheet' => $this->stylesheet,
     331                                                'template'   => $this->template,
     332                                        )
     333                                );
    293334                                $this->parent = new WP_Theme( $this->template, $this->theme_root, $this );
    294335                                return;
    … …  
    302343                                $_child->parent = null;
    303344                                $_child->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), esc_html( $_child->template ) ) );
    304                                 $_child->cache_add( 'theme', array( 'headers' => $_child->headers, 'errors' => $_child->errors, 'stylesheet' => $_child->stylesheet, 'template' => $_child->template ) );
     345                                $_child->cache_add(
     346                                        'theme', array(
     347                                                'headers'    => $_child->headers,
     348                                                'errors'     => $_child->errors,
     349                                                'stylesheet' => $_child->stylesheet,
     350                                                'template'   => $_child->template,
     351                                        )
     352                                );
    305353                                // The two themes actually reference each other with the Template header.
    306354                                if ( $_child->stylesheet == $this->template ) {
    307355                                        $this->errors = new WP_Error( 'theme_parent_invalid', sprintf( __( 'The "%s" theme is not a valid parent theme.' ), esc_html( $this->template ) ) );
    308                                         $this->cache_add( 'theme', array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template ) );
     356                                        $this->cache_add(
     357                                                'theme', array(
     358                                                        'headers'    => $this->headers,
     359                                                        'errors'     => $this->errors,
     360                                                        'stylesheet' => $this->stylesheet,
     361                                                        'template'   => $this->template,
     362                                                )
     363                                        );
    309364                                }
    310365                                return;
    … …  
    316371                // We're good. If we didn't retrieve from cache, set it.
    317372                if ( ! is_array( $cache ) ) {
    318                         $cache = array( 'headers' => $this->headers, 'errors' => $this->errors, 'stylesheet' => $this->stylesheet, 'template' => $this->template );
     373                        $cache = array(
     374                                'headers'    => $this->headers,
     375                                'errors'     => $this->errors,
     376                                'stylesheet' => $this->stylesheet,
     377                                'template'   => $this->template,
     378                        );
    319379                        // If the parent theme is in another root, we'll want to cache this. Avoids an entire branch of filesystem calls above.
    320                         if ( isset( $theme_root_template ) )
     380                        if ( isset( $theme_root_template ) ) {
    321381                                $cache['theme_root_template'] = $theme_root_template;
     382                        }
    322383                        $this->cache_add( 'theme', $cache );
    323384                }
    … …  
    332393         */
    333394        public function __toString() {
    334                 return (string) $this->display('Name');
     395                return (string) $this->display( 'Name' );
    335396        }
    336397
    … …  
    347408        public function __isset( $offset ) {
    348409                static $properties = array(
    349                         'name', 'title', 'version', 'parent_theme', 'template_dir', 'stylesheet_dir', 'template', 'stylesheet',
    350                         'screenshot', 'description', 'author', 'tags', 'theme_root', 'theme_root_uri',
     410                        'name',
     411                        'title',
     412                        'version',
     413                        'parent_theme',
     414                        'template_dir',
     415                        'stylesheet_dir',
     416                        'template',
     417                        'stylesheet',
     418                        'screenshot',
     419                        'description',
     420                        'author',
     421                        'tags',
     422                        'theme_root',
     423                        'theme_root_uri',
    351424                );
    352425
    … …  
    364437        public function __get( $offset ) {
    365438                switch ( $offset ) {
    366                         case 'name' :
    367                         case 'title' :
    368                                 return $this->get('Name');
    369                         case 'version' :
    370                                 return $this->get('Version');
    371                         case 'parent_theme' :
    372                                 return $this->parent() ? $this->parent()->get('Name') : '';
    373                         case 'template_dir' :
     439                        case 'name':
     440                        case 'title':
     441                                return $this->get( 'Name' );
     442                        case 'version':
     443                                return $this->get( 'Version' );
     444                        case 'parent_theme':
     445                                return $this->parent() ? $this->parent()->get( 'Name' ) : '';
     446                        case 'template_dir':
    374447                                return $this->get_template_directory();
    375                         case 'stylesheet_dir' :
     448                        case 'stylesheet_dir':
    376449                                return $this->get_stylesheet_directory();
    377                         case 'template' :
     450                        case 'template':
    378451                                return $this->get_template();
    379                         case 'stylesheet' :
     452                        case 'stylesheet':
    380453                                return $this->get_stylesheet();
    381                         case 'screenshot' :
     454                        case 'screenshot':
    382455                                return $this->get_screenshot( 'relative' );
    383456                        // 'author' and 'description' did not previously return translated data.
    384                         case 'description' :
    385                                 return $this->display('Description');
    386                         case 'author' :
    387                                 return $this->display('Author');
    388                         case 'tags' :
     457                        case 'description':
     458                                return $this->display( 'Description' );
     459                        case 'author':
     460                                return $this->display( 'Author' );
     461                        case 'tags':
    389462                                return $this->get( 'Tags' );
    390                         case 'theme_root' :
     463                        case 'theme_root':
    391464                                return $this->get_theme_root();
    392                         case 'theme_root_uri' :
     465                        case 'theme_root_uri':
    393466                                return $this->get_theme_root_uri();
    394467                        // For cases where the array was converted to an object.
    395                         default :
     468                        default:
    396469                                return $this->offsetGet( $offset );
    397470                }
    … …  
    429502        public function offsetExists( $offset ) {
    430503                static $keys = array(
    431                         'Name', 'Version', 'Status', 'Title', 'Author', 'Author Name', 'Author URI', 'Description',
    432                         'Template', 'Stylesheet', 'Template Files', 'Stylesheet Files', 'Template Dir', 'Stylesheet Dir',
    433                         'Screenshot', 'Tags', 'Theme Root', 'Theme Root URI', 'Parent Theme',
     504                        'Name',
     505                        'Version',
     506                        'Status',
     507                        'Title',
     508                        'Author',
     509                        'Author Name',
     510                        'Author URI',
     511                        'Description',
     512                        'Template',
     513                        'Stylesheet',
     514                        'Template Files',
     515                        'Stylesheet Files',
     516                        'Template Dir',
     517                        'Stylesheet Dir',
     518                        'Screenshot',
     519                        'Tags',
     520                        'Theme Root',
     521                        'Theme Root URI',
     522                        'Parent Theme',
    434523                );
    435524
    … …  
    454543        public function offsetGet( $offset ) {
    455544                switch ( $offset ) {
    456                         case 'Name' :
    457                         case 'Title' :
     545                        case 'Name':
     546                        case 'Title':
    458547                                /*
    459548                                 * See note above about using translated data. get() is not ideal.
    460549                                 * It is only for backward compatibility. Use display().
    461550                                 */
    462                                 return $this->get('Name');
    463                         case 'Author' :
    464                                 return $this->display( 'Author');
    465                         case 'Author Name' :
    466                                 return $this->display( 'Author', false);
    467                         case 'Author URI' :
    468                                 return $this->display('AuthorURI');
    469                         case 'Description' :
    470                                 return $this->display( 'Description');
    471                         case 'Version' :
    472                         case 'Status' :
     551                                return $this->get( 'Name' );
     552                        case 'Author':
     553                                return $this->display( 'Author' );
     554                        case 'Author Name':
     555                                return $this->display( 'Author', false );
     556                        case 'Author URI':
     557                                return $this->display( 'AuthorURI' );
     558                        case 'Description':
     559                                return $this->display( 'Description' );
     560                        case 'Version':
     561                        case 'Status':
    473562                                return $this->get( $offset );
    474                         case 'Template' :
     563                        case 'Template':
    475564                                return $this->get_template();
    476                         case 'Stylesheet' :
     565                        case 'Stylesheet':
    477566                                return $this->get_stylesheet();
    478                         case 'Template Files' :
     567                        case 'Template Files':
    479568                                return $this->get_files( 'php', 1, true );
    480                         case 'Stylesheet Files' :
     569                        case 'Stylesheet Files':
    481570                                return $this->get_files( 'css', 0, false );
    482                         case 'Template Dir' :
     571                        case 'Template Dir':
    483572                                return $this->get_template_directory();
    484                         case 'Stylesheet Dir' :
     573                        case 'Stylesheet Dir':
    485574                                return $this->get_stylesheet_directory();
    486                         case 'Screenshot' :
     575                        case 'Screenshot':
    487576                                return $this->get_screenshot( 'relative' );
    488                         case 'Tags' :
    489                                 return $this->get('Tags');
    490                         case 'Theme Root' :
     577                        case 'Tags':
     578                                return $this->get( 'Tags' );
     579                        case 'Theme Root':
    491580                                return $this->get_theme_root();
    492                         case 'Theme Root URI' :
     581                        case 'Theme Root URI':
    493582                                return $this->get_theme_root_uri();
    494                         case 'Parent Theme' :
    495                                 return $this->parent() ? $this->parent()->get('Name') : '';
    496                         default :
     583                        case 'Parent Theme':
     584                                return $this->parent() ? $this->parent()->get( 'Name' ) : '';
     585                        default:
    497586                                return null;
    498587                }
    … …  
    570659         */
    571660        public function cache_delete() {
    572                 foreach ( array( 'theme', 'screenshot', 'headers', 'post_templates' ) as $key )
     661                foreach ( array( 'theme', 'screenshot', 'headers', 'post_templates' ) as $key ) {
    573662                        wp_cache_delete( $key . '-' . $this->cache_hash, 'themes' );
     663                }
    574664                $this->template = $this->textdomain_loaded = $this->theme_root_uri = $this->parent = $this->errors = $this->headers_sanitized = $this->name_translated = null;
    575                 $this->headers = array();
     665                $this->headers  = array();
    576666                $this->__construct( $this->stylesheet, $this->theme_root );
    577667        }
    … …  
    594684         */
    595685        public function get( $header ) {
    596                 if ( ! isset( $this->headers[ $header ] ) )
     686                if ( ! isset( $this->headers[ $header ] ) ) {
    597687                        return false;
     688                }
    598689
    599690                if ( ! isset( $this->headers_sanitized ) ) {
    600691                        $this->headers_sanitized = $this->cache_get( 'headers' );
    601                         if ( ! is_array( $this->headers_sanitized ) )
     692                        if ( ! is_array( $this->headers_sanitized ) ) {
    602693                                $this->headers_sanitized = array();
    603                 }
    604 
    605                 if ( isset( $this->headers_sanitized[ $header ] ) )
     694                        }
     695                }
     696
     697                if ( isset( $this->headers_sanitized[ $header ] ) ) {
    606698                        return $this->headers_sanitized[ $header ];
     699                }
    607700
    608701                // If themes are a persistent group, sanitize everything and cache it. One cache add is better than many cache sets.
    609702                if ( self::$persistently_cache ) {
    610                         foreach ( array_keys( $this->headers ) as $_header )
     703                        foreach ( array_keys( $this->headers ) as $_header ) {
    611704                                $this->headers_sanitized[ $_header ] = $this->sanitize_header( $_header, $this->headers[ $_header ] );
     705                        }
    612706                        $this->cache_add( 'headers', $this->headers_sanitized );
    613707                } else {
    … …  
    634728                }
    635729
    636                 if ( $translate && ( empty( $value ) || ! $this->load_textdomain() ) )
     730                if ( $translate && ( empty( $value ) || ! $this->load_textdomain() ) ) {
    637731                        $translate = false;
    638 
    639                 if ( $translate )
     732                }
     733
     734                if ( $translate ) {
    640735                        $value = $this->translate_header( $header, $value );
    641 
    642                 if ( $markup )
     736                }
     737
     738                if ( $markup ) {
    643739                        $value = $this->markup_header( $header, $value, $translate );
     740                }
    644741
    645742                return $value;
    … …  
    660757        private function sanitize_header( $header, $value ) {
    661758                switch ( $header ) {
    662                         case 'Status' :
     759                        case 'Status':
    663760                                if ( ! $value ) {
    664761                                        $value = 'publish';
    … …  
    666763                                }
    667764                                // Fall through otherwise.
    668                         case 'Name' :
     765                        case 'Name':
    669766                                static $header_tags = array(
    670767                                        'abbr'    => array( 'title' => true ),
    … …  
    674771                                        'strong'  => true,
    675772                                );
    676                                 $value = wp_kses( $value, $header_tags );
     773                                $value              = wp_kses( $value, $header_tags );
    677774                                break;
    678                         case 'Author' :
     775                        case 'Author':
    679776                                // There shouldn't be anchor tags in Author, but some themes like to be challenging.
    680                         case 'Description' :
     777                        case 'Description':
    681778                                static $header_tags_with_a = array(
    682                                         'a'       => array( 'href' => true, 'title' => true ),
     779                                        'a'       => array(
     780                                                'href'  => true,
     781                                                'title' => true,
     782                                        ),
    683783                                        'abbr'    => array( 'title' => true ),
    684784                                        'acronym' => array( 'title' => true ),
    … …  
    687787                                        'strong'  => true,
    688788                                );
    689                                 $value = wp_kses( $value, $header_tags_with_a );
     789                                $value                     = wp_kses( $value, $header_tags_with_a );
    690790                                break;
    691                         case 'ThemeURI' :
    692                         case 'AuthorURI' :
     791                        case 'ThemeURI':
     792                        case 'AuthorURI':
    693793                                $value = esc_url_raw( $value );
    694794                                break;
    695                         case 'Tags' :
     795                        case 'Tags':
    696796                                $value = array_filter( array_map( 'trim', explode( ',', strip_tags( $value ) ) ) );
    697797                                break;
    698                         case 'Version' :
     798                        case 'Version':
    699799                                $value = strip_tags( $value );
    700800                                break;
    … …  
    707807         * Mark up a theme header.
    708808         *
    709     * @since 3.4.0
     809        * @since 3.4.0
    710810         *
    711811         * @staticvar string $comma
    … …  
    718818        private function markup_header( $header, $value, $translate ) {
    719819                switch ( $header ) {
    720                         case 'Name' :
     820                        case 'Name':
    721821                                if ( empty( $value ) ) {
    722822                                        $value = esc_html( $this->get_stylesheet() );
    723823                                }
    724824                                break;
    725                         case 'Description' :
     825                        case 'Description':
    726826                                $value = wptexturize( $value );
    727827                                break;
    728                         case 'Author' :
    729                                 if ( $this->get('AuthorURI') ) {
     828                        case 'Author':
     829                                if ( $this->get( 'AuthorURI' ) ) {
    730830                                        $value = sprintf( '<a href="%1$s">%2$s</a>', $this->display( 'AuthorURI', true, $translate ), $value );
    731831                                } elseif ( ! $value ) {
    … …  
    733833                                }
    734834                                break;
    735                         case 'Tags' :
     835                        case 'Tags':
    736836                                static $comma = null;
    737837                                if ( ! isset( $comma ) ) {
    … …  
    741841                                $value = implode( $comma, $value );
    742842                                break;
    743                         case 'ThemeURI' :
    744                         case 'AuthorURI' :
     843                        case 'ThemeURI':
     844                        case 'AuthorURI':
    745845                                $value = esc_url( $value );
    746846                                break;
    … …  
    763863        private function translate_header( $header, $value ) {
    764864                switch ( $header ) {
    765                         case 'Name' :
     865                        case 'Name':
    766866                                // Cached for sorting reasons.
    767                                 if ( isset( $this->name_translated ) )
     867                                if ( isset( $this->name_translated ) ) {
    768868                                        return $this->name_translated;
    769                                 $this->name_translated = translate( $value, $this->get('TextDomain' ) );
     869                                }
     870                                $this->name_translated = translate( $value, $this->get( 'TextDomain' ) );
    770871                                return $this->name_translated;
    771                         case 'Tags' :
     872                        case 'Tags':
    772873                                if ( empty( $value ) || ! function_exists( 'get_theme_feature_list' ) ) {
    773874                                        return $value;
    … …  
    778879                                        $tags_list = array(
    779880                                                // As of 4.6, deprecated tags which are only used to provide translation for older themes.
    780                                                 'black' => __( 'Black' ), 'blue' => __( 'Blue' ), 'brown'  => __( 'Brown' ),
    781                                                 'gray' => __( 'Gray' ), 'green'  => __( 'Green' ), 'orange' => __( 'Orange' ),
    782                                                 'pink' => __( 'Pink' ), 'purple' => __( 'Purple' ), 'red' => __( 'Red' ),
    783                                                 'silver' => __( 'Silver' ), 'tan' => __( 'Tan' ), 'white' => __( 'White' ),
    784                                                 'yellow' => __( 'Yellow' ), 'dark' => __( 'Dark' ), 'light' => __( 'Light' ),
    785                                                 'fixed-layout' => __( 'Fixed Layout' ), 'fluid-layout' => __( 'Fluid Layout' ),
    786                                                 'responsive-layout' => __( 'Responsive Layout' ), 'blavatar' => __( 'Blavatar' ),
    787                                                 'photoblogging' => __( 'Photoblogging' ), 'seasonal' => __( 'Seasonal' ),
     881                                                'black'             => __( 'Black' ),
     882                                                'blue'              => __( 'Blue' ),
     883                                                'brown'             => __( 'Brown' ),
     884                                                'gray'              => __( 'Gray' ),
     885                                                'green'             => __( 'Green' ),
     886                                                'orange'            => __( 'Orange' ),
     887                                                'pink'              => __( 'Pink' ),
     888                                                'purple'            => __( 'Purple' ),
     889                                                'red'               => __( 'Red' ),
     890                                                'silver'            => __( 'Silver' ),
     891                                                'tan'               => __( 'Tan' ),
     892                                                'white'             => __( 'White' ),
     893                                                'yellow'            => __( 'Yellow' ),
     894                                                'dark'              => __( 'Dark' ),
     895                                                'light'             => __( 'Light' ),
     896                                                'fixed-layout'      => __( 'Fixed Layout' ),
     897                                                'fluid-layout'      => __( 'Fluid Layout' ),
     898                                                'responsive-layout' => __( 'Responsive Layout' ),
     899                                                'blavatar'          => __( 'Blavatar' ),
     900                                                'photoblogging'     => __( 'Photoblogging' ),
     901                                                'seasonal'          => __( 'Seasonal' ),
    788902                                        );
    789903
    … …  
    804918                                return $value;
    805919
    806                         default :
    807                                 $value = translate( $value, $this->get('TextDomain') );
     920                        default:
     921                                $value = translate( $value, $this->get( 'TextDomain' ) );
    808922                }
    809923                return $value;
    … …  
    849963         */
    850964        public function get_stylesheet_directory() {
    851                 if ( $this->errors() && in_array( 'theme_root_missing', $this->errors()->get_error_codes() ) )
     965                if ( $this->errors() && in_array( 'theme_root_missing', $this->errors()->get_error_codes() ) ) {
    852966                        return '';
     967                }
    853968
    854969                return $this->theme_root . '/' . $this->stylesheet;
    … …  
    866981         */
    867982        public function get_template_directory() {
    868                 if ( $this->parent() )
     983                if ( $this->parent() ) {
    869984                        $theme_root = $this->parent()->theme_root;
    870                 else
     985                } else {
    871986                        $theme_root = $this->theme_root;
     987                }
    872988
    873989                return $theme_root . '/' . $this->template;
    … …  
    8991015         */
    9001016        public function get_template_directory_uri() {
    901                 if ( $this->parent() )
     1017                if ( $this->parent() ) {
    9021018                        $theme_root_uri = $this->parent()->get_theme_root_uri();
    903                 else
     1019                } else {
    9041020                        $theme_root_uri = $this->get_theme_root_uri();
     1021                }
    9051022
    9061023                return $theme_root_uri . '/' . str_replace( '%2F', '/', rawurlencode( $this->template ) );
    … …  
    9321049         */
    9331050        public function get_theme_root_uri() {
    934                 if ( ! isset( $this->theme_root_uri ) )
     1051                if ( ! isset( $this->theme_root_uri ) ) {
    9351052                        $this->theme_root_uri = get_theme_root_uri( $this->stylesheet, $this->theme_root );
     1053                }
    9361054                return $this->theme_root_uri;
    9371055        }
    … …  
    9531071                $screenshot = $this->cache_get( 'screenshot' );
    9541072                if ( $screenshot ) {
    955                         if ( 'relative' == $uri )
     1073                        if ( 'relative' == $uri ) {
    9561074                                return $screenshot;
     1075                        }
    9571076                        return $this->get_stylesheet_directory_uri() . '/' . $screenshot;
    9581077                } elseif ( 0 === $screenshot ) {
    … …  
    9631082                        if ( file_exists( $this->get_stylesheet_directory() . "/screenshot.$ext" ) ) {
    9641083                                $this->cache_add( 'screenshot', 'screenshot.' . $ext );
    965                                 if ( 'relative' == $uri )
     1084                                if ( 'relative' == $uri ) {
    9661085                                        return 'screenshot.' . $ext;
     1086                                }
    9671087                                return $this->get_stylesheet_directory_uri() . '/' . 'screenshot.' . $ext;
    9681088                        }
    … …  
    10131133                        $post_templates = array();
    10141134
    1015                         $files = (array) $this->get_files( 'php', 1, true);
     1135                        $files = (array) $this->get_files( 'php', 1, true );
    10161136
    10171137                        foreach ( $files as $file => $full_path ) {
    … …  
    11101230
    11111231                if ( $extensions ) {
    1112                         $extensions = (array) $extensions;
     1232                        $extensions  = (array) $extensions;
    11131233                        $_extensions = implode( '|', $extensions );
    11141234                }
    … …  
    11201240
    11211241                $results = scandir( $path );
    1122                 $files = array();
     1242                $files   = array();
    11231243
    11241244                /**
    … …  
    11391259                                        continue;
    11401260                                }
    1141                                 $found = self::scandir( $path . '/' . $result, $extensions, $depth - 1 , $relative_path . $result );
     1261                                $found = self::scandir( $path . '/' . $result, $extensions, $depth - 1, $relative_path . $result );
    11421262                                $files = array_merge_recursive( $files, $found );
    11431263                        } elseif ( ! $extensions || preg_match( '~\.(' . $_extensions . ')$~', $result ) ) {
    … …  
    11581278         *
    11591279         * @return bool True if the textdomain was successfully loaded or has already been loaded.
    1160          *      False if no textdomain was specified in the file headers, or if the domain could not be loaded.
     1280         *  False if no textdomain was specified in the file headers, or if the domain could not be loaded.
    11611281         */
    11621282        public function load_textdomain() {
    1163                 if ( isset( $this->textdomain_loaded ) )
     1283                if ( isset( $this->textdomain_loaded ) ) {
    11641284                        return $this->textdomain_loaded;
    1165 
    1166                 $textdomain = $this->get('TextDomain');
     1285                }
     1286
     1287                $textdomain = $this->get( 'TextDomain' );
    11671288                if ( ! $textdomain ) {
    11681289                        $this->textdomain_loaded = false;
    … …  
    11761297
    11771298                $path = $this->get_stylesheet_directory();
    1178                 if ( $domainpath = $this->get('DomainPath') )
     1299                if ( $domainpath = $this->get( 'DomainPath' ) ) {
    11791300                        $path .= $domainpath;
    1180                 else
     1301                } else {
    11811302                        $path .= '/languages';
     1303                }
    11821304
    11831305                $this->textdomain_loaded = load_theme_textdomain( $textdomain, $path );
    … …  
    11911313         *
    11921314         * @param string $check Optional. Whether to check only the 'network'-wide settings, the 'site'
    1193          *      settings, or 'both'. Defaults to 'both'.
     1315         *  settings, or 'both'. Defaults to 'both'.
    11941316         * @param int $blog_id Optional. Ignored if only network-wide settings are checked. Defaults to current site.
    11951317         * @return bool Whether the theme is allowed for the network. Returns true in single-site.
    11961318         */
    11971319        public function is_allowed( $check = 'both', $blog_id = null ) {
    1198                 if ( ! is_multisite() )
     1320                if ( ! is_multisite() ) {
    11991321                        return true;
     1322                }
    12001323
    12011324                if ( 'both' == $check || 'network' == $check ) {
    12021325                        $allowed = self::get_allowed_on_network();
    1203                         if ( ! empty( $allowed[ $this->get_stylesheet() ] ) )
     1326                        if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) {
    12041327                                return true;
     1328                        }
    12051329                }
    12061330
    12071331                if ( 'both' == $check || 'site' == $check ) {
    12081332                        $allowed = self::get_allowed_on_site( $blog_id );
    1209                         if ( ! empty( $allowed[ $this->get_stylesheet() ] ) )
     1333                        if ( ! empty( $allowed[ $this->get_stylesheet() ] ) ) {
    12101334                                return true;
     1335                        }
    12111336                }
    12121337
    … …  
    13031428                static $allowed_themes = array();
    13041429
    1305                 if ( ! $blog_id || ! is_multisite() )
     1430                if ( ! $blog_id || ! is_multisite() ) {
    13061431                        $blog_id = get_current_blog_id();
     1432                }
    13071433
    13081434                if ( isset( $allowed_themes[ $blog_id ] ) ) {
    … …  
    13431469                        } else {
    13441470                                $converted = array();
    1345                                 $themes = wp_get_themes();
     1471                                $themes    = wp_get_themes();
    13461472                                foreach ( $themes as $stylesheet => $theme_data ) {
    1347                                         if ( isset( $allowed_themes[ $blog_id ][ $theme_data->get('Name') ] ) )
     1473                                        if ( isset( $allowed_themes[ $blog_id ][ $theme_data->get( 'Name' ) ] ) ) {
    13481474                                                $converted[ $stylesheet ] = true;
     1475                                        }
    13491476                                }
    13501477                                $allowed_themes[ $blog_id ] = $converted;
Note: See TracChangeset for help on using the changeset viewer.