WordPress.org

Make WordPress Core

Changeset 20027


Ignore:
Timestamp:
02/28/2012 08:51:19 PM (6 years ago)
Author:
nacin
Message:

Faster theme searching. Only calculate what is necessary -- if the theme doesn't have all of the features, bail. If a word matches a tag or header, jump to the next word, we don't care how many times it matches. see #20103.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-themes-list-table.php

    r20026 r20027  
    191191
    192192    function search_theme( $theme ) {
    193         $matched = 0;
     193        // Search the features
     194        if ( $this->features ) {
     195            foreach ( $this->features as $word ) {
     196                if ( ! in_array( $word, $theme['Tags'] ) )
     197                    return false;
     198            }
     199        }
    194200
    195201        // Match all phrases
    196         if ( count( $this->search ) > 0 ) {
     202        if ( $this->search ) {
    197203            foreach ( $this->search as $word ) {
    198                 $matched = 0;
    199 
    200                 // In a tag?
    201204                if ( in_array( $word, $theme['Tags'] ) )
    202                     $matched = 1;
    203 
    204                 // In one of the fields?
    205                 foreach ( array( 'Name', 'Title', 'Description', 'Author', 'Template', 'Stylesheet' ) AS $field ) {
    206                     if ( stripos( $theme[$field], $word ) !== false )
    207                         $matched++;
    208                 }
    209 
    210                 if ( $matched == 0 )
    211                     return false;
    212             }
    213         }
    214 
    215         // Now search the features
    216         if ( count( $this->features ) > 0 ) {
    217             foreach ( $this->features as $word ) {
    218                 // In a tag?
    219                 if ( !in_array( $word, $theme['Tags'] ) )
    220                     return false;
    221             }
    222         }
    223 
    224         // Only get here if each word exists in the tags or one of the fields
     205                    continue;
     206            }
     207
     208            foreach ( array( 'Name', 'Title', 'Description', 'Author', 'Template', 'Stylesheet' ) as $header ) {
     209                if ( false !== stripos( $theme[ $header ], $word ) )
     210                    continue 2;
     211            }
     212
     213            return false;
     214        }
     215
    225216        return true;
    226217    }
Note: See TracChangeset for help on using the changeset viewer.