Making WordPress.org


Ignore:
Timestamp:
04/27/2016 08:08:11 AM (10 years ago)
Author:
dd32
Message:

Plugin Directory: Add a REST API endpoint which represents the full plugin data currently exposed through api.wordpress.org.
Although it's unlikely api.wordpress.org will run the API directly, this is a test to verify that all data we have on file is available.

See #1576

File:
1 edited

Legend:

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

    r3009 r3020  
    6767     * @return array
    6868     */
    69     static function get_plugin_sections() {
    70         $plugin      = get_post();
     69    static function get_plugin_sections( $post = null ) {
     70        $plugin      = get_post( $post );
    7171        $plugin_slug = $plugin->post_name;
    7272
     
    173173        $raw_icons = get_post_meta( $plugin->ID, 'assets_icons', true );
    174174
    175         $icon = $icon_2x = $vector = $generated = false;
     175        $icon = $icon_2x = $svg = $generated = false;
    176176        foreach ( $raw_icons as $file => $info ) {
    177177            switch ( $info['resolution'] ) {
     
    184184                    break;
    185185
     186                /* false = the resolution of the icon, this is NOT disabled */
    186187                case false && 'icon.svg' == $file:
    187                     $icon   = self::get_asset_url( $plugin_slug, $info );
    188                     $vector = true;
    189                     break;
    190             }
     188                    $svg   = self::get_asset_url( $plugin_slug, $info );
     189                    break;
     190            }
     191        }
     192
     193        if ( ! $icon && $svg ) {
     194            $icon = $svg;
    191195        }
    192196
     
    223227            case 'raw':
    224228            default:
    225                 return compact( 'icon', 'icon_2x', 'vector', 'generated' );
     229                return compact( 'svg', 'icon', 'icon_2x', 'generated' );
    226230        }
    227231    }
     
    333337        return $output;
    334338    }
    335    
     339
     340    /**
     341     * Generate a Download link for a given plugin & version.
     342     *
     343     * @param \WP_Post $post    The Plugin Post.
     344     * @param string   $version The version to link to. Optional. Default: latest.
     345     * @return string The Download URL.
     346     */
     347    static function download_link( $post = null, $version = 'latest' ) {
     348        $post = get_post( $post );
     349
     350        if ( 'latest' == $version || 'latest-stable' == $version ) {
     351            $version = get_post_meta( $post->ID, 'stable_tag', true );
     352        }
     353
     354        if ( 'trunk' != $version ) {
     355            return sprintf( "https://downloads.wordpress.org/plugin/%s.%s.zip", $post->post_name, $version );
     356        } else {
     357            return sprintf( "https://downloads.wordpress.org/plugin/%s.zip", $post->post_name );
     358        }
     359    }
    336360}
Note: See TracChangeset for help on using the changeset viewer.