Theme searching. First pass. see #14936
git-svn-id: https://develop.svn.wordpress.org/trunk@15644 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
b7be962c6b
commit
e541559b37
@ -3857,6 +3857,9 @@ class WP_Plugin_Install_Table extends WP_List_Table {
|
|||||||
|
|
||||||
class WP_Themes_Table extends WP_List_Table {
|
class WP_Themes_Table extends WP_List_Table {
|
||||||
|
|
||||||
|
var $search = array();
|
||||||
|
var $features = array();
|
||||||
|
|
||||||
function WP_Themes_Table() {
|
function WP_Themes_Table() {
|
||||||
parent::__construct( array(
|
parent::__construct( array(
|
||||||
'screen' => 'themes',
|
'screen' => 'themes',
|
||||||
@ -3874,6 +3877,18 @@ class WP_Themes_Table extends WP_List_Table {
|
|||||||
$ct = current_theme_info();
|
$ct = current_theme_info();
|
||||||
|
|
||||||
$themes = get_allowed_themes();
|
$themes = get_allowed_themes();
|
||||||
|
|
||||||
|
$search = !empty( $_REQUEST['s'] ) ? trim( stripslashes( $_REQUEST['s'] ) ) : '';
|
||||||
|
|
||||||
|
if ( '' !== $this->search ) {
|
||||||
|
$this->search = array_merge( $this->search, array_filter( array_map( 'trim', explode( ',', $search ) ) ) );
|
||||||
|
$this->search = array_unique( $this->search );
|
||||||
|
foreach ( $themes as $key => $theme ) {
|
||||||
|
if ( !$this->search_theme( $theme ) )
|
||||||
|
unset( $themes[ $key ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unset( $themes[$ct->name] );
|
unset( $themes[$ct->name] );
|
||||||
uksort( $themes, "strnatcasecmp" );
|
uksort( $themes, "strnatcasecmp" );
|
||||||
|
|
||||||
@ -4002,6 +4017,42 @@ foreach ( $cols as $col => $theme_name ) {
|
|||||||
</tr>
|
</tr>
|
||||||
<?php } // end foreach $table
|
<?php } // end foreach $table
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function search_theme( $theme ) {
|
||||||
|
$matched = 0;
|
||||||
|
|
||||||
|
// Match all phrases
|
||||||
|
if ( count( $this->search ) > 0 ) {
|
||||||
|
foreach ( $this->search as $word ) {
|
||||||
|
$matched = 0;
|
||||||
|
|
||||||
|
// In a tag?
|
||||||
|
if ( in_array( $word, array_map( 'sanitize_title_with_dashes', $theme['Tags'] ) ) )
|
||||||
|
$matched = 1;
|
||||||
|
|
||||||
|
// In one of the fields?
|
||||||
|
foreach ( array( 'Name', 'Title', 'Description', 'Author', 'Template', 'Stylesheet' ) AS $field ) {
|
||||||
|
if ( stripos( $theme[$field], $word ) !== false )
|
||||||
|
$matched++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $matched == 0 )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now search the features
|
||||||
|
if ( count( $this->features ) > 0 ) {
|
||||||
|
foreach ( $this->features as $word ) {
|
||||||
|
// In a tag?
|
||||||
|
if ( !in_array( $word, array_map( 'sanitize_title_with_dashes', $theme['Tags'] ) ) )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only get here if each word exists in the tags or one of the fields
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class WP_Theme_Install_Table extends WP_List_Table {
|
class WP_Theme_Install_Table extends WP_List_Table {
|
||||||
|
@ -103,6 +103,15 @@ if ( ! current_user_can( 'switch_themes' ) ) {
|
|||||||
?>
|
?>
|
||||||
<h3><?php _e('Available Themes'); ?></h3>
|
<h3><?php _e('Available Themes'); ?></h3>
|
||||||
|
|
||||||
|
<form class="search-form" action="" method="get">
|
||||||
|
<p class="search-box">
|
||||||
|
<label class="screen-reader-text" for="theme-search-input"><?php _e('Search Themes'); ?>:</label>
|
||||||
|
<input type="text" id="tag-search-input" name="s" value="<?php _admin_search_query(); ?>" />
|
||||||
|
<input type="submit" value="<?php esc_attr_e('Search Themes'); ?>" class="button" />
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
<br class="clear" />
|
||||||
|
|
||||||
<?php $wp_list_table->display(); ?>
|
<?php $wp_list_table->display(); ?>
|
||||||
|
|
||||||
<br class="clear" />
|
<br class="clear" />
|
||||||
|
Loading…
Reference in New Issue
Block a user