Making WordPress.org


Ignore:
Timestamp:
12/04/2016 10:45:34 PM (8 years ago)
Author:
obenland
Message:

Plugin Directory: First pass at adding post meta to REST API.

We'll need to register our own rest api fields for more complex data
structures, namely objects and arrays of objects.

See #1576.

File:
1 edited

Legend:

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

    r4457 r4484  
    22namespace WordPressdotorg\Plugin_Directory;
    33use WordPressdotorg\Plugin_Directory\Admin\Customizations;
    4 use WordPressdotorg\Plugin_Directory\CLI\Tag_To_Category;
    54
    65/**
     
    109108            ),
    110109            'description'     => __( 'A Repo Plugin', 'wporg-plugins' ),
    111             'supports'        => array( 'comments', 'author' ),
     110            'supports'        => array( 'comments', 'author', 'custom-fields' ),
    112111            'public'          => true,
    113112            'show_ui'         => true,
     113            'show_in_rest'    => true,
    114114            'has_archive'     => true,
    115115            'rewrite'         => false,
     
    288288            'show_in_admin_status_list' => current_user_can( 'plugin_reject' ),
    289289            'label_count'               => _n_noop( 'Rejected <span class="count">(%s)</span>', 'Rejected <span class="count">(%s)</span>', 'wporg-plugins' ),
     290        ) );
     291
     292        /**
     293         * TODO
     294         * Use register_rest_field() to add array and object meta data to the API:
     295         * ratings, upgrade_notice, contributors, screenshots, sections, assets_screenshots,
     296         * assets_icons, assets_banners,
     297         */
     298
     299        register_meta( 'post', 'rating', array(
     300            'type'              => 'number',
     301            'description'       => __( 'Overall rating of the plugin.', 'wporg-plugins' ),
     302            'single'            => true,
     303            // todo 'sanitize_callback' => 'absint',
     304            'show_in_rest'      => true,
     305        ) );
     306
     307        register_meta( 'post', 'active_installs', array(
     308            'type'              => 'integer',
     309            'description'       => __( 'Number of installations.', 'wporg-plugins' ),
     310            'single'            => true,
     311            'sanitize_callback' => 'absint',
     312            'show_in_rest'      => true,
     313        ) );
     314
     315        register_meta( 'post', 'downloads', array(
     316            'type'              => 'integer',
     317            'description'       => __( 'Number of downloads', 'wporg-plugins' ),
     318            'single'            => true,
     319            'sanitize_callback' => 'absint',
     320            'show_in_rest'      => true,
     321        ) );
     322
     323        register_meta( 'post', 'tested', array(
     324            'description'       => __( 'The version of WordPress the plugin was tested with.', 'wporg-plugins' ),
     325            'single'            => true,
     326            // TODO 'sanitize_callback' => 'absint',
     327            'show_in_rest'      => true,
     328        ) );
     329
     330        register_meta( 'post', 'requires', array(
     331            'description'       => __( 'The minimum version of WordPress the plugin needs to run.', 'wporg-plugins' ),
     332            'single'            => true,
     333            // TODO 'sanitize_callback' => 'absint',
     334            'show_in_rest'      => true,
     335        ) );
     336
     337        register_meta( 'post', 'stable_tag', array(
     338            'description'       => __( 'Stable version of the plugin', 'wporg-plugins' ),
     339            'single'            => true,
     340            // TODO 'sanitize_callback' => 'absint',
     341            'show_in_rest'      => true,
     342        ) );
     343
     344        register_meta( 'post', 'donate_link', array(
     345            'description'       => __( 'Link to donate to the plugin.', 'wporg-plugins' ),
     346            'single'            => true,
     347            'sanitize_callback' => 'esc_url_raw',
     348            'show_in_rest'      => true,
     349        ) );
     350
     351        register_meta( 'post', 'version', array(
     352            'description'       => __( 'Current stable version.', 'wporg-plugins' ),
     353            'single'            => true,
     354            // TODO 'sanitize_callback' => 'esc_url_raw',
     355            'show_in_rest'      => true,
     356        ) );
     357
     358        register_meta( 'post', 'header_name', array(
     359            'description'       => __( 'Name of the plugin.', 'wporg-plugins' ),
     360            'single'            => true,
     361            // TODO 'sanitize_callback' => 'esc_url_raw',
     362            'show_in_rest'      => true,
     363        ) );
     364
     365        register_meta( 'post', 'header_plugin_uri', array(
     366            'description'       => __( 'URL to the homepage of the plugin.', 'wporg-plugins' ),
     367            'single'            => true,
     368            'sanitize_callback' => 'esc_url_raw',
     369            'show_in_rest'      => true,
     370        ) );
     371
     372        register_meta( 'post', 'header_name', array(
     373            'description'       => __( 'Name of the plugin.', 'wporg-plugins' ),
     374            'single'            => true,
     375            // TODO 'sanitize_callback' => 'esc_url_raw',
     376            'show_in_rest'      => true,
     377        ) );
     378
     379        register_meta( 'post', 'header_author', array(
     380            'description'       => __( 'Name of the plugin author.', 'wporg-plugins' ),
     381            'single'            => true,
     382            // TODO 'sanitize_callback' => 'esc_url_raw',
     383            'show_in_rest'      => true,
     384        ) );
     385
     386        register_meta( 'post', 'header_author_uri', array(
     387            'description'       => __( 'URL to the homepage of the author.', 'wporg-plugins' ),
     388            'single'            => true,
     389            'sanitize_callback' => 'esc_url_raw',
     390            'show_in_rest'      => true,
     391        ) );
     392
     393        register_meta( 'post', 'header_description', array(
     394            'description'       => __( 'Description of the plugin.', 'wporg-plugins' ),
     395            'single'            => true,
     396            // TODO 'sanitize_callback' => 'esc_url_raw',
     397            'show_in_rest'      => true,
     398        ) );
     399
     400        register_meta( 'post', 'assets_icons', array(
     401            'type'              => 'array',
     402            'description'       => __( 'Icon images of the plugin.', 'wporg-plugins' ),
     403            'single'            => true,
     404            // TODO 'sanitize_callback' => 'esc_url_raw',
     405            'show_in_rest'      => true,
     406        ) );
     407
     408        register_meta( 'post', 'assets_banners_color', array(
     409            'description'       => __( 'Fallback color for the plugin.', 'wporg-plugins' ),
     410            'single'            => true,
     411            // TODO 'sanitize_callback' => 'esc_url_raw',
     412            'show_in_rest'      => true,
     413        ) );
     414
     415        register_meta( 'post', 'support_threads', array(
     416            'type'              => 'integer',
     417            'description'       => __( 'Amount of support threads for the plugin.', 'wporg-plugins' ),
     418            'single'            => true,
     419            'sanitize_callback' => 'absint',
     420            'show_in_rest'      => true,
     421        ) );
     422
     423        register_meta( 'post', 'support_threads_resolved', array(
     424            'type'              => 'integer',
     425            'description'       => __( 'Amount of resolved support threads for the plugin.', 'wporg-plugins' ),
     426            'single'            => true,
     427            'sanitize_callback' => 'absint',
     428            'show_in_rest'      => true,
    290429        ) );
    291430
Note: See TracChangeset for help on using the changeset viewer.