Making WordPress.org


Ignore:
Timestamp:
04/26/2016 07:33:28 AM (9 years ago)
Author:
dd32
Message:

Plugin Directory: Add a Review Widget to the theme, and all the other required things for Widgets.
This adds a namespace to the theme and begins to reduce the duplication of template functionality between wp-admin and the theme.

See #1584.
Fixes #1575.

File:
1 edited

Legend:

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

    r2998 r3009  
    2222        add_action( 'init', array( $this, 'init' ) );
    2323        add_action( 'init', array( $this, 'register_shortcodes' ) );
     24        add_action( 'widgets_init', array( $this, 'register_widgets' ) );
    2425        add_filter( 'post_type_link', array( $this, 'package_link' ), 10, 2 );
    2526        add_filter( 'pre_insert_term', array( $this, 'pre_insert_term_prevent' ) );
     
    3233
    3334        // Shim in postmeta support for data which doesn't yet live in postmeta
    34         add_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ), 10, 4 );
     35        add_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ), 10, 3 );
    3536
    3637        // Load the API routes
     
    196197    }
    197198
     199    public function register_widgets() {
     200        register_widget( __NAMESPACE__ . '\Widgets\Metadata' );
     201        register_widget( __NAMESPACE__ . '\Widgets\Ratings' );
     202    }
     203
    198204    /**
    199205     * Upon plugin activation, set up the current site for acting
     
    423429     * @param int               $object_id Object ID.
    424430     * @param string            $meta_key  Meta key.
    425      * @param bool              $single    Whether to return only the first value of the specified $meta_key.
    426      */
    427     public function filter_shim_postmeta( $value, $object_id, $meta_key, $single ) {
     431     */
     432    public function filter_shim_postmeta( $value, $object_id, $meta_key ) {
    428433        switch ( $meta_key ) {
    429434            case 'downloads':
     
    431436                $count = Template::get_downloads_count( $post );
    432437
    433                 return $single ? $count : array( $count );             
     438                return array( $count );             
    434439                break;
    435440            case 'rating':
     
    441446                $rating = wporg_get_rating_avg( 'plugin', $post->post_name );
    442447
    443                 return $single ? $rating : array( $rating );
     448                return array( $rating );
     449                break;
     450            case 'ratings':
     451                $post = get_post( $object_id );
     452                if ( ! function_exists( 'wporg_get_rating_counts' ) ) {
     453                    break;
     454                }
     455                $ratings = wporg_get_rating_counts( 'plugin', $post->post_name );
     456
     457                return array( $ratings );
    444458                break;
    445459        }
Note: See TracChangeset for help on using the changeset viewer.