Making WordPress.org


Ignore:
Timestamp:
02/10/2022 12:41:19 AM (5 years ago)
Author:
dd32
Message:

Plugin Directory: API: Allow clients to disable the versions and download_link fields.

Full changes:

  • Can disable the versions response key.
  • Can disable the download_link response key.
  • Incorrectly documented downloadlink key will affect the download_link key.
  • Requesting reviews without sections will now result in sections.reviews being returned still
  • Typos in documentation & code cleanup.

See #6032.

File:
1 edited

Legend:

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

    r11219 r11535  
    155155         * @param string $method   The requested method, used to determine the default fields to include.
    156156         *
    157          * @return array The $resonse with the extra fields removed.
    158          */
    159         protected function remove_unexpected_fields( $response, $request, $method = '' ) {
    160                 $fields = $request->get_expected_fields( $method );
     157         * @return array The $response with the extra fields removed.
     158         */
     159        protected function remove_unexpected_fields( $full_response, $request, $method = '' ) {
     160                $response = $full_response;
     161                $fields   = $request->get_expected_fields( $method );
    161162                foreach ( $fields as $field => $include ) {
    162163                        if ( ! $include ) {
     
    168169                }
    169170
     171                // Support requesting reviews without sections.
     172                if ( ! empty( $fields['reviews'] ) && empty( $fields['sections'] ) ) {
     173                        $response['sections'] = array(
     174                                'reviews' => $full_response['sections']['reviews']
     175                        );
     176                }
     177
    170178                // Back-compatible routines.
    171179                // WordPress 4.9 and older need a "bare" contributor map [ user => profile ]
    172180                if ( ! empty( $fields['bare_contributors'] ) ) {
    173                         $contribs                 = $response['contributors'] ?? [];
     181                        $contributors             = $response['contributors'] ?? [];
    174182                        $response['contributors'] = array();
    175                         if ( $contribs ) {
    176                                 foreach ( $contribs as $user => $data ) {
    177                                         $response['contributors'][ $user ] = $data['profile'];
    178                                 }
     183                        foreach ( $contributors as $user => $data ) {
     184                                $response['contributors'][ $user ] = $data['profile'];
    179185                        }
    180186                }
     
    182188                // Only include block translation data for the selected locale.
    183189                if ( ! empty( $response['block_translations'] ) ) {
    184                         $response['block_translations'] = !empty( $response['block_translations'][ $request->locale ] ) ? $response['block_translations'][ $request->locale ] : [];
     190                        $response['block_translations'] = $response['block_translations'][ $request->locale ] ?? [];
    185191                }
    186192
Note: See TracChangeset for help on using the changeset viewer.