Make WordPress Core


Ignore:
Timestamp:
07/18/2014 07:34:47 PM (12 years ago)
Author:
helen
Message:

Plugin install: display cards in groups if the API returns them with the appropriate information. props tellyworth. fixes #28673.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-plugin-install-list-table.php

    r29219 r29225  
    1010class WP_Plugin_Install_List_Table extends WP_List_Table {
    1111
     12        var $order = 'ASC';
     13        var $orderby = null;
     14        var $groups = array();
     15
    1216        public function ajax_user_can() {
    1317                return current_user_can('install_plugins');
    … …  
    8690
    8791                        case 'featured':
     92                                $args['fields']['group'] = true;
     93                                $this->orderby = 'group';
     94                                // No break!
    8895                        case 'popular':
    8996                        case 'new':
    … …  
    131138                $this->items = $api->plugins;
    132139
     140                if ( $this->orderby ) {
     141                        uasort( $this->items, array( $this, '_order_callback' ) );
     142                }
     143
    133144                $this->set_pagination_args( array(
    134145                        'total_items' => $api->info['results'],
    135146                        'per_page' => $args['per_page'],
    136147                ) );
     148
     149                if ( isset( $api->info['groups'] ) )
     150                        $this->groups = $api->info['groups'];
    137151        }
    138152
    … …  
    244258        }
    245259
     260        public function _order_callback( $plugin_a, $plugin_b ) {
     261
     262                $orderby = $this->orderby;
     263                if ( !isset( $plugin_a->$orderby, $plugin_b->$orderby ) )
     264                        return 0;
     265
     266                $a = $plugin_a->$orderby;
     267                $b = $plugin_b->$orderby;
     268
     269                if ( $a == $b )
     270                        return 0;
     271
     272                if ( 'DESC' == $this->order )
     273                        return ( $a < $b ) ? 1 : -1;
     274                else
     275                        return ( $a < $b ) ? -1 : 1;
     276        }
     277
     278
    246279        public function display_rows() {
    247280                $plugins_allowedtags = array(
    … …  
    259292                }
    260293
     294                $group = null;
     295
    261296                foreach ( (array) $this->items as $plugin ) {
    262297                        if ( is_object( $plugin ) )
    263298                                $plugin = (array) $plugin;
    264299
     300                        // Display the group heading if there is one
     301                        if ( isset( $plugin['group'] ) && $plugin['group'] != $group ) {
     302                                if ( isset( $this->groups[ $plugin['group'] ] ) )
     303                                        $group_name = translate( $this->groups[ $plugin['group'] ] ); // Does this need context?
     304                                else
     305                                        $group_name = $plugin['group'];
     306
     307                                // Starting a new group, close off the divs of the last one
     308                                if ( ! empty( $group ) ) {
     309                                        echo '</div></div>';
     310                                }
     311
     312                                echo '<div class="plugin-group"><h3>' . esc_html( $group_name ) . '</h3>';
     313                                // needs an extra wrapping div for nth-child selectors to work
     314                                echo '<div class="plugin-items">';
     315
     316                                $group = $plugin['group'];
     317                        }
    265318                        $title = wp_kses( $plugin['name'], $plugins_allowedtags );
    266319
Note: See TracChangeset for help on using the changeset viewer.