Making WordPress.org

Changeset 2982


Ignore:
Timestamp:
04/19/2016 08:08:25 PM (9 years ago)
Author:
obenland
Message:

Plugin Directory: Add plugin count to dashboard widget.

Not high priority, but I had time on a flight and thought it would be neat.

See #1570.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/class-customizations.php

    r2929 r2982  
    2828        add_action( 'add_meta_boxes', array( $this, 'register_admin_metaboxes' ), 10, 2 );
    2929        add_action( 'do_meta_boxes', array( $this, 'replace_title_global' ) );
     30        add_filter( 'dashboard_glance_items', array( $this, 'plugin_glance_items' ) );
    3031
    3132        add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
     
    6465            $title = sprintf( $title, get_the_title() ); // esc_html() on output
    6566        }
     67    }
     68
     69    /**
     70     * Filters the array of extra elements to list in the 'At a Glance'
     71     * dashboard widget.
     72     *
     73     * @param array $items Array of extra 'At a Glance' widget items.
     74     * @return array
     75     */
     76    public function plugin_glance_items( $items ) {
     77        $post_type = 'plugin';
     78        $num_posts = wp_count_posts( $post_type );
     79
     80        if ( $num_posts && $num_posts->publish ) {
     81            $text             = sprintf( _n( '%s Plugin', '%s Plugins', $num_posts->publish ), number_format_i18n( $num_posts->publish ) );
     82            $post_type_object = get_post_type_object( $post_type );
     83
     84            if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
     85                $item = sprintf( '<a class="plugin-count" href="edit.php?post_type=%1$s">%2$s</a>', $post_type, $text );
     86            } else {
     87                $item = sprintf( '<span class="plugin-count">%s</span>', $text );
     88            }
     89
     90            $items[] = $item . '<style>#dashboard_right_now .plugin-count:before { content: "\f106"; }</style>';
     91        }
     92
     93        return $items;
    6694    }
    6795
Note: See TracChangeset for help on using the changeset viewer.