Making WordPress.org


Ignore:
Timestamp:
04/21/2016 05:57:55 AM (9 years ago)
Author:
dd32
Message:

Plugin Directory: Add a shim to allow us to retrieve the downloads count from postmeta (although the count is stored elsewhere for now).

See #1596

File:
1 edited

Legend:

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

    r2985 r2991  
    2929
    3030        add_filter( 'map_meta_cap', array( __NAMESPACE__ . '\Capabilities', 'map_meta_cap' ), 10, 4 );
     31
     32        // Shim in postmeta support for data which doesn't yet live in postmeta
     33        add_filter( 'get_post_metadata', array( $this, 'filter_shim_postmeta' ), 10, 4 );
    3134
    3235        // Load the API routes
     
    405408    }
    406409
     410
     411    /**
     412     * Shim in some postmeta values which get retrieved from other locations temporarily.
     413     *
     414     * @param null|array|string $value     The value get_metadata() should return - a single metadata value,
     415     *                                     or an array of values.
     416     * @param int               $object_id Object ID.
     417     * @param string            $meta_key  Meta key.
     418     * @param bool              $single    Whether to return only the first value of the specified $meta_key.
     419     */
     420    public function filter_shim_postmeta( $value, $object_id, $meta_key, $single ) {
     421        switch ( $meta_key ) {
     422            case 'downloads':
     423                $post = get_post( $object_id );
     424                $count = Template::get_downloads_count( $post );
     425
     426                return $single ? $count : array( $count );             
     427                break;
     428        }
     429        return $value;
     430    }
     431
    407432    /**
    408433     * Returns an array of pages based on section comments in the content.
Note: See TracChangeset for help on using the changeset viewer.