Make WordPress Core


Ignore:
Timestamp:
02/01/2018 05:16:15 AM (7 years ago)
Author:
dd32
Message:

Plugins: Use api.wordpress.org/plugins/info/1.2/ for querying plugins & plugin information.

See #43192.
Fixes #29274.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/plugin-install.php

    r42459 r42631  
    100100 */
    101101function plugins_api( $action, $args = array() ) {
     102    // include an unmodified $wp_version
     103    include( ABSPATH . WPINC . '/version.php' );
    102104
    103105    if ( is_array( $args ) ) {
     
    105107    }
    106108
    107     if ( ! isset( $args->per_page ) ) {
    108         $args->per_page = 24;
     109    if ( 'query_plugins' == $action ) {
     110        if ( ! isset( $args->per_page ) ) {
     111            $args->per_page = 24;
     112        }
    109113    }
    110114
    111115    if ( ! isset( $args->locale ) ) {
    112116        $args->locale = get_user_locale();
     117    }
     118
     119    if ( ! isset( $args->wp_version ) ) {
     120        $args->wp_version = substr( $wp_version, 0, 3 ); // X.y
    113121    }
    114122
     
    142150
    143151    if ( false === $res ) {
    144         // include an unmodified $wp_version
    145         include( ABSPATH . WPINC . '/version.php' );
    146 
    147         $url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
     152
     153        $url = 'http://api.wordpress.org/plugins/info/1.2/';
     154        $url = add_query_arg(
     155            array(
     156                'action'  => $action,
     157                'request' => $args,
     158            ),
     159            $url
     160        );
     161
     162        $http_url = $url;
    148163        if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
    149164            $url = set_url_scheme( $url, 'https' );
     
    153168            'timeout'    => 15,
    154169            'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url( '/' ),
    155             'body'       => array(
    156                 'action'  => $action,
    157                 'request' => serialize( $args ),
    158             ),
    159170        );
    160         $request   = wp_remote_post( $url, $http_args );
     171        $request   = wp_remote_get( $url, $http_args );
    161172
    162173        if ( $ssl && is_wp_error( $request ) ) {
     
    169180                headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE
    170181            );
    171             $request = wp_remote_post( $http_url, $http_args );
     182            $request = wp_remote_get( $http_url, $http_args );
    172183        }
    173184
     
    183194            );
    184195        } else {
    185             $res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
    186             if ( ! is_object( $res ) && ! is_array( $res ) ) {
     196            $res = json_decode( wp_remote_retrieve_body( $request ), true );
     197            if ( is_array( $res ) ) {
     198                // Object casting is required in order to match the info/1.0 format.
     199                $res = (object) $res;
     200            } elseif ( null === $res ) {
    187201                $res = new WP_Error(
    188202                    'plugins_api_failed',
     
    194208                    wp_remote_retrieve_body( $request )
    195209                );
     210            }
     211
     212            if ( isset( $res->error ) ) {
     213                $res = new WP_Error( 'plugins_api_failed', $res->error );
    196214            }
    197215        }
     
    486504        'plugin_information', array(
    487505            'slug'   => wp_unslash( $_REQUEST['plugin'] ),
    488             'is_ssl' => is_ssl(),
    489             'fields' => array(
    490                 'banners'         => true,
    491                 'reviews'         => true,
    492                 'downloaded'      => false,
    493                 'active_installs' => true,
    494             ),
    495506        )
    496507    );
     
    708719            <ul class="contributors">
    709720                <?php
    710                 foreach ( (array) $api->contributors as $contrib_username => $contrib_profile ) {
    711                     if ( empty( $contrib_username ) && empty( $contrib_profile ) ) {
    712                         continue;
     721                foreach ( (array) $api->contributors as $contrib_username => $contrib_details ) {
     722                    $contrib_name = $contrib_details['display_name'];
     723                    if ( ! $contrib_name ) {
     724                        $contrin_name = $contrib_username;
    713725                    }
    714                     if ( empty( $contrib_username ) ) {
    715                         $contrib_username = preg_replace( '/^.+\/(.+)\/?$/', '\1', $contrib_profile );
    716                     }
    717                     $contrib_username = sanitize_user( $contrib_username );
    718                     if ( empty( $contrib_profile ) ) {
    719                         echo "<li><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' alt='' />{$contrib_username}</li>";
    720                     } else {
    721                         echo "<li><a href='{$contrib_profile}' target='_blank'><img src='https://wordpress.org/grav-redirect.php?user={$contrib_username}&amp;s=36' width='18' height='18' alt='' />{$contrib_username}</a></li>";
    722                     }
     726                    $contrib_name = esc_html( $contrib_name );
     727
     728                    $contrib_profile = esc_url( $contrib_details['profile'] );
     729                    $contrib_avatar = esc_url( add_query_arg( 's', '36', $contrib_details['avatar'] ) );
     730
     731                    echo "<li><a href='{$contrib_profile}' target='_blank'><img src='{$contrib_avatar}' width='18' height='18' alt='' />{$contrib_name}</a></li>";
    723732                }
    724733                ?>
Note: See TracChangeset for help on using the changeset viewer.