Making WordPress.org


Ignore:
Timestamp:
06/02/2016 06:55:49 AM (9 years ago)
Author:
dd32
Message:

Plugin Directory: First swipe at handlers for api.wordpress.org/plugins/info/*.
The API handlers are designed to be stand-alone scripts which run only with an object cache for caching, When cached data is unavailable, WordPress is included to fetch the data from a rest api endpoint.

See #1579

File:
1 edited

Legend:

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

    r3228 r3289  
    44use WordPressdotorg\Plugin_Directory\Template;
    55use WordPressdotorg\Plugin_Directory\API\Base;
     6use WP_REST_Server;
    67
    78/**
     
    1415    function __construct() {
    1516        register_rest_route( 'plugins/v1', '/plugin/(?P<plugin_slug>[^/]+)/?', array(
    16             'methods'  => \WP_REST_Server::READABLE,
     17            'methods'  => WP_REST_Server::READABLE,
    1718            'callback' => array( $this, 'plugin_info' ),
    1819            'args' => array(
     
    3132     */
    3233    function plugin_info( $request ) {
    33         /*
    34          * NOTE: Don't try to implement things such as the `fields` support in this endpoint.
    35          *        It's highly unlikely we'll expose the REST API via api.wordpress.org as it is,
    36          *        it'll probably have something in front of it.
    37          *
    38          * NOTE: Don't use any data from the client, such as the user_agent, just stick to what is presented in the GET payload.
    39          *       It can't be cached if it's using data from other sources.
    40          */
    4134        $plugin_slug = $request['plugin_slug'];
    4235
     
    7669        $result['contributors'] = array();
    7770
    78         foreach ( (array)get_post_meta( $post_id, 'contributors', true ) as $contributor ) {
    79             $user = get_user_by( 'slug', $contributor );
     71        $contributors = get_post_meta( $post_id, 'contributors', true ) ?: array( (int) $post->post_author );
     72        foreach ( $contributors as $contributor ) {
     73            $user = is_int( $contributor ) ? get_user_by( 'id', $contributor ) : get_user_by( 'slug', $contributor );
    8074            if ( ! $user ) {
    8175                continue;
    8276            }
    8377
    84             $result['contributors'][ $contributor ] = array(
     78            $result['contributors'][ $user->user_nicename ] = array(
    8579                'profile' => $this->get_user_profile_link( $user ),
    8680                'avatar' => get_avatar_url( $user, array( 'default' => 'monsterid', 'rating' => 'g' ) ),
Note: See TracChangeset for help on using the changeset viewer.