WordPress.org

Make WordPress Core

Ticket #9527: 9527.6.diff

File 9527.6.diff, 6.1 KB (added by DD32, 9 years ago)
  • 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 );
     
    231232
    232233        //Translate, Apply Markup, Sanitize HTML
    233234        $plugin_data = _get_plugin_data_markup_translate($plugin_data, true, true);
     235        $all_plugins[ $plugin_file ] = $plugin_data;
    234236
    235237        //Filter into individual sections
    236238        if ( is_plugin_active($plugin_file) ) {
     
    245247        $upgrade_plugins[ $plugin_file ] = $plugin_data;
    246248}
    247249
    248 $total_plugins = count($all_plugins);
     250$total_all_plugins = count($all_plugins);
    249251$total_inactive_plugins = count($inactive_plugins);
    250252$total_active_plugins = count($active_plugins);
    251253$total_recent_plugins = count($recent_plugins);
    252254$total_upgrade_plugins = count($upgrade_plugins);
    253255
    254 $status = ( isset($_GET['plugin_status']) ) ? $_GET['plugin_status'] : 'all';
    255 if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade')) )
     256//Searching.
     257if ( isset($_GET['s']) ) {
     258        function _search_plugins_filter_callback($plugin) {
     259                static $term;
     260                if ( is_null($term) )
     261                        $term = stripslashes($_GET['s']);
     262                if (    stripos($plugin['Name'], $term) !== false ||
     263                                stripos($plugin['Description'], $term) !== false ||
     264                                stripos($plugin['Author'], $term) !== false ||
     265                                stripos($plugin['PluginURI'], $term) !== false ||
     266                                stripos($plugin['AuthorURI'], $term) !== false ||
     267                                stripos($plugin['Version'], $term) !== false )
     268                        return true;
     269                else
     270                        return false;
     271        }
     272        $_GET['plugin_status'] = 'search';
     273        $search_plugins = array_filter($all_plugins, '_search_plugins_filter_callback');
     274        $total_search_plugins = count($search_plugins);
     275}
     276
     277$status = isset($_GET['plugin_status']) ? $_GET['plugin_status'] : 'all';
     278if ( !in_array($status, array('all', 'active', 'inactive', 'recent', 'upgrade', 'search')) )
    256279        $status = 'all';
    257280$plugin_array_name = "${status}_plugins";
    258281$plugins = &$$plugin_array_name;
    259282
     283//Paging.
     284$page = isset($_GET['paged']) ? $_GET['paged'] : 1;
     285$total_this_page = "total_{$status}_plugins";
     286$total_this_page = $$total_this_page;
     287$plugins_per_page = apply_filters('plugins_per_page', 20, $status);
     288
     289$start = ($page - 1) * $plugins_per_page;
     290
     291$page_links = paginate_links( array(
     292        'base' => add_query_arg( 'paged', '%#%' ),
     293        'format' => '',
     294        'prev_text' => __('&laquo;'),
     295        'next_text' => __('&raquo;'),
     296        'total' => ceil($total_this_page / $plugins_per_page),
     297        'current' => $page
     298));
     299$page_links_text = sprintf( '<span class="displaying-num">' . __( 'Displaying %s&#8211;%s of %s' ) . '</span>%s',
     300        number_format_i18n( $start + 1 ),
     301        number_format_i18n( min( $page * $plugins_per_page, $total_this_page ) ),
     302        '<span class="total-type-count">' . number_format_i18n( $total_this_page ) . '</span>',
     303        $page_links
     304);
     305
    260306/**
    261307 * @ignore
    262308 *
     
    362408}
    363409?>
    364410
     411<form method="get" action="">
     412<p class="search-box">
     413        <label class="hidden" for="plugin-search-input"><?php _e( 'Search Plugins' ); ?>:</label>
     414        <input type="text" id="plugin-search-input" name="s" value="<?php _admin_search_query(); ?>" />
     415        <input type="submit" value="<?php _e( 'Search Plugins' ); ?>" class="button" />
     416</p>
     417</form>
     418
    365419<form method="post" action="<?php echo admin_url('plugins.php') ?>">
    366420<?php wp_nonce_field('bulk-manage-plugins') ?>
    367421
     
    369423<?php
    370424$status_links = array();
    371425$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>';
     426$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>';
    373427if ( ! empty($active_plugins) ) {
    374428        $class = ( 'active' == $status ) ? ' class="current"' : '';
    375429        $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>';
     
    386440        $class = ( 'upgrade' == $status ) ? ' class="current"' : '';
    387441        $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>';
    388442}
     443if ( ! empty($search_plugins) ) {
     444        $class = ( 'search' == $status ) ? ' class="current"' : '';
     445        $term = isset($_REQUEST['s']) ? urlencode(stripslashes($_REQUEST['s'])) : '';
     446        $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>';
     447}
    389448echo implode( " |</li>\n", $status_links ) . '</li>';
    390449unset( $status_links );
    391450?>
    392451</ul>
    393452
    394453<div class="tablenav">
    395 <?php print_plugin_actions($status) ?>
     454<?php
     455if ( $page_links )
     456        echo '<div class="tablenav-pages">', $page_links_text, '</div>';
     457
     458print_plugin_actions($status);
     459?>
    396460</div>
    397461<div class="clear"></div>
    398 <?php print_plugins_table($plugins, $status) ?>
     462<?php
     463        if ( $total_this_page > $plugins_per_page )
     464                $plugins = array_slice($plugins, $start, $plugins_per_page);
     465       
     466        print_plugins_table($plugins, $status);
     467?>
     468<div class="tablenav">
     469<?php
     470if ( $page_links )
     471        echo "<div class='tablenav-pages'>$page_links_text</div>";
     472?>
     473<div class="alignleft actions">
     474<!-- TODO lower bulk actions. -->
     475</div>
     476</div>
    399477</form>
    400478
    401479<?php if ( empty($all_plugins) ) : ?>