Make WordPress Core

Changeset 42631


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

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

See #43192.
Fixes #29274.

Location:
trunk/src/wp-admin
Files:
4 edited

Legend:

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

    r42343 r42631  
    146146                        'page'              => $paged,
    147147                        'per_page'          => $per_page,
    148                         'fields'            => array(
    149                                 'last_updated'    => true,
    150                                 'icons'           => true,
    151                                 'active_installs' => true,
    152                         ),
    153                         // Send the locale and installed plugin slugs to the API so it can provide context-sensitive results.
     148                        // Send the locale to the API so it can provide context-sensitive results.
    154149                        'locale'            => get_user_locale(),
    155                         'installed_plugins' => array_keys( $installed_plugins ),
    156150                );
    157151
     
    176170
    177171                        case 'featured':
    178                                 $args['fields']['group'] = true;
    179                                 $this->orderby           = 'group';
    180                                 // No break!
    181172                        case 'popular':
    182173                        case 'new':
    183174                        case 'beta':
     175                                $args['browse'] = $tab;
     176                                break;
    184177                        case 'recommended':
    185178                                $args['browse'] = $tab;
     179                                // Include the list of installed plugins so we can get relevant results.
     180                                $args['installed_plugins'] = array_keys( $installed_plugins );
    186181                                break;
    187182
  • 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                                ?>
  • trunk/src/wp-admin/update-core.php

    r42343 r42631  
    278278        if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $cur_wp_version, '>=' ) ) {
    279279                $compat = '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: 100%% (according to its author)' ), $cur_wp_version );
    280         } elseif ( isset( $plugin_data->update->compatibility->{$cur_wp_version} ) ) {
    281                 $compat = $plugin_data->update->compatibility->{$cur_wp_version};
    282                 $compat = '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)' ), $cur_wp_version, $compat->percent, $compat->votes, $compat->total_votes );
    283280        } else {
    284281                $compat = '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: Unknown' ), $cur_wp_version );
     
    288285                if ( isset( $plugin_data->update->tested ) && version_compare( $plugin_data->update->tested, $core_update_version, '>=' ) ) {
    289286                        $compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: 100%% (according to its author)' ), $core_update_version );
    290                 } elseif ( isset( $plugin_data->update->compatibility->{$core_update_version} ) ) {
    291                         $update_compat = $plugin_data->update->compatibility->{$core_update_version};
    292                         $compat       .= '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: %2$d%% (%3$d "works" votes out of %4$d total)' ), $core_update_version, $update_compat->percent, $update_compat->votes, $update_compat->total_votes );
    293287                } else {
    294288                        $compat .= '<br />' . sprintf( __( 'Compatibility with WordPress %1$s: Unknown' ), $core_update_version );
  • trunk/src/wp-admin/update.php

    r42343 r42631  
    110110                                'slug'   => $plugin,
    111111                                'fields' => array(
    112                                         'short_description' => false,
    113                                         'sections'          => false,
    114                                         'requires'          => false,
    115                                         'rating'            => false,
    116                                         'ratings'           => false,
    117                                         'downloaded'        => false,
    118                                         'last_updated'      => false,
    119                                         'added'             => false,
    120                                         'tags'              => false,
    121                                         'compatibility'     => false,
    122                                         'homepage'          => false,
    123                                         'donate_link'       => false,
     112                                        'sections' => false,
    124113                                ),
    125114                        )
Note: See TracChangeset for help on using the changeset viewer.