WordPress.org

Making WordPress.org

Changeset 3289


Ignore:
Timestamp:
06/02/16 06:55:49 (19 months 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

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
6 added
3 edited
1 moved

Legend:

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

    r3020 r3289  
    1414        new Routes\Internal_Stats(); 
    1515        new Routes\Plugin(); 
     16        new Routes\Popular_Categories(); 
     17        new Routes\Query_Plugins(); 
    1618    } 
    1719 
  • 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' ) ), 
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r3226 r3289  
    373373        } 
    374374        if ( 'plugin_built_for' == $term->taxonomy ) { 
    375             return $this->package_link( false, $this->get_plugin_post( $term->slug ) ); 
     375            // Term slug = Post Slug = /%postname%/ 
     376            return trailingslashit( home_url( $term->slug ) ); 
    376377        } 
    377378 
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/standalone/downloads.php

    r3288 r3289  
    1212 */ 
    1313 
    14 include __DIR__ . '/class-autoloader.php'; 
    15 Autoloader\register_class_path( __NAMESPACE__, __DIR__ ); 
    16  
     14include dirname( __DIR__ ) . '/class-autoloader.php'; 
     15Autoloader\register_class_path( __NAMESPACE__, dirname( __DIR__ ) ); 
    1716$serve = new Zip\Serve(); 
Note: See TracChangeset for help on using the changeset viewer.