WordPress.org

Make WordPress Core

Ticket #9527: 9527.4.diff

File 9527.4.diff, 5.9 KB (added by DD32, 5 years ago)

Paging + Searching based on stripos

  • wp-admin/plugins.php

     
    211211<?php 
    212212 
    213213$all_plugins = get_plugins(); 
     214$search_plugins = array(); 
    214215$active_plugins = array(); 
    215216$inactive_plugins = array(); 
    216217$recent_plugins = array(); 
    217 $recently_activated = (array) get_option('recently_activated'); 
     218$recently_activated = get_option('recently_activated', array()); 
    218219$upgrade_plugins = array(); 
    219220 
    220221set_transient( 'plugin_slugs', array_keys($all_plugins), 86400 ); 
     
    245246        $upgrade_plugins[ $plugin_file ] = $plugin_data; 
    246247} 
    247248 
    248 $total_plugins = count($all_plugins); 
     249$total_all_plugins = count($all_plugins); 
    249250$total_inactive_plugins = count($inactive_plugins); 
    250251$total_active_plugins = count($active_plugins); 
    251252$total_recent_plugins = count($recent_plugins); 
    252253$total_upgrade_plugins = count($upgrade_plugins); 
    253254 
    254 $status = ( isset($_GET['plugin_status']) ) ? $_GET['plugin_status'] : 'all'; 
    255 if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade')) ) 
     255//Searching. 
     256if ( isset($_GET['s']) ) { 
     257        function _search_plugins_filter_callback($plugin) { 
     258                static $term; 
     259                if ( is_null($term) ) 
     260                        $term = stripslashes($_GET['s']); 
     261                if (    stripos($plugin['Name'], $term) || 
     262                                stripos($plugin['Description'], $term) || 
     263                                stripos($plugin['Author'], $term) || 
     264                                stripos($plugin['PluginURI'], $term) || 
     265                                stripos($plugin['AuthorURI'], $term) || 
     266                                stripos($plugin['Version'], $term) ) 
     267                        return true; 
     268                else 
     269                        return false; 
     270        } 
     271        $_GET['plugin_status'] = 'search'; 
     272        $search_plugins = array_filter($all_plugins, '_search_plugins_filter_callback'); 
     273        $total_search_plugins = count($search_plugins); 
     274} 
     275 
     276$status = isset($_GET['plugin_status']) ? $_GET['plugin_status'] : 'all'; 
     277if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade', 'search')) ) 
    256278        $status = 'all'; 
    257279$plugin_array_name = "${status}_plugins"; 
    258280$plugins = &$$plugin_array_name; 
    259281 
     282//Paging. 
     283$page = isset($_GET['paged']) ? $_GET['paged'] : 1; 
     284$total_this_page = "total_{$status}_plugins"; 
     285$total_this_page = $$total_this_page; 
     286$plugins_per_page = apply_filters('plugins_per_page', 20, $status); 
     287 
     288$start = ($page - 1) * $plugins_per_page; 
     289 
     290$page_links = paginate_links( array( 
     291        'base' => add_query_arg( 'paged', '%#%' ), 
     292        'format' => '', 
     293        'prev_text' => __('&laquo;'), 
     294        'next_text' => __('&raquo;'), 
     295        'total' => ceil($total_this_page / $plugins_per_page), 
     296        'current' => $page 
     297)); 
     298$page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s', 
     299        number_format_i18n( $start + 1 ), 
     300        number_format_i18n( min( $page * $plugins_per_page, $total_this_page ) ), 
     301        '<span class="total-type-count">' . number_format_i18n( $total_this_page ) . '</span>', 
     302        $page_links 
     303); 
     304 
    260305/** 
    261306 * @ignore 
    262307 * 
     
    362407} 
    363408?> 
    364409 
     410<form method="get" action=""> 
     411<p class="search-box"> 
     412        <label class="hidden" for="plugin-search-input"><?php _e( 'Search Plugins' ); ?>:</label> 
     413        <input type="text" id="plugin-search-input" name="s" value="<?php _admin_search_query(); ?>" /> 
     414        <input type="submit" value="<?php _e( 'Search Plugins' ); ?>" class="button" /> 
     415</p> 
     416</form> 
     417 
    365418<form method="post" action="<?php echo admin_url('plugins.php') ?>"> 
    366419<?php wp_nonce_field('bulk-manage-plugins') ?> 
    367420 
     
    369422<?php 
    370423$status_links = array(); 
    371424$class = ( 'all' == $status ) ? ' class="current"' : ''; 
    372 $status_links[] = "<li><a href='plugins.php' $class>" . sprintf( _n( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_plugins ), number_format_i18n( $total_plugins ) ) . '</a>'; 
     425$status_links[] = "<li><a href='plugins.php' $class>" . sprintf( _n( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_all_plugins ), number_format_i18n( $total_all_plugins ) ) . '</a>'; 
    373426if ( ! empty($active_plugins) ) { 
    374427        $class = ( 'active' == $status ) ? ' class="current"' : ''; 
    375428        $status_links[] = "<li><a href='plugins.php?plugin_status=active' $class>" . sprintf( _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $total_active_plugins ), number_format_i18n( $total_active_plugins ) ) . '</a>'; 
     
    386439        $class = ( 'upgrade' == $status ) ? ' class="current"' : ''; 
    387440        $status_links[] = "<li><a href='plugins.php?plugin_status=upgrade' $class>" . sprintf( _n( 'Upgrade Available <span class="count">(%s)</span>', 'Upgrade Available <span class="count">(%s)</span>', $total_upgrade_plugins ), number_format_i18n( $total_upgrade_plugins ) ) . '</a>'; 
    388441} 
     442if ( ! empty($search_plugins) ) { 
     443        $class = ( 'search' == $status ) ? ' class="current"' : ''; 
     444        $term = isset($_REQUEST['s']) ? urlencode(stripslashes($_REQUEST['s'])) : ''; 
     445        $status_links[] = "<li><a href='plugins.php?s=$term' $class>" . sprintf( _n( 'Search Results <span class="count">(%s)</span>', 'Search Results <span class="count">(%s)</span>', $total_search_plugins ), number_format_i18n( $total_search_plugins ) ) . '</a>'; 
     446} 
    389447echo implode( " |</li>\n", $status_links ) . '</li>'; 
    390448unset( $status_links ); 
    391449?> 
    392450</ul> 
    393451 
    394452<div class="tablenav"> 
    395 <?php print_plugin_actions($status) ?> 
     453<?php 
     454if ( $page_links ) 
     455        echo '<div class="tablenav-pages">', $page_links_text, '</div>'; 
     456 
     457print_plugin_actions($status); 
     458?> 
    396459</div> 
    397460<div class="clear"></div> 
    398 <?php print_plugins_table($plugins, $status) ?> 
     461<?php 
     462        if ( $total_this_page > $plugins_per_page ) 
     463                $plugins = array_slice($plugins, $start, $plugins_per_page); 
     464         
     465        print_plugins_table($plugins, $status); 
     466?> 
     467<div class="tablenav"> 
     468<?php 
     469if ( $page_links ) 
     470        echo "<div class='tablenav-pages'>$page_links_text</div>"; 
     471?> 
     472<div class="alignleft actions"> 
     473<!-- TODO lower bulk actions. --> 
     474</div> 
     475</div> 
    399476</form> 
    400477 
    401478<?php if ( empty($all_plugins) ) : ?>