Making WordPress.org


Ignore:
Timestamp:
06/22/2016 01:33:53 PM (8 years ago)
Author:
dd32
Message:

Plugin Directory: Add plugin favoriting to the user interface.
Someone will need to style this properly.

Fixes #1577

File:
1 copied

Legend:

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

    r3523 r3545  
    66
    77/**
    8  * An API endpoint for subscribing to commits for a particular plugin.
     8 * An API endpoint for favoriting a particular plugin.
    99 *
    1010 * @package WordPressdotorg_Plugin_Directory
    1111 */
    12 class Commit_Subscriptions extends Base {
     12class Plugin_Favorites extends Base {
    1313
    1414    public function __construct() {
    15         register_rest_route( 'plugins/v1', '/plugin/(?P<plugin_slug>[^/]+)/commit-subscription', array(
    16             'methods'  => \WP_REST_Server::READABLE,
    17             'callback' => array( $this, 'subscribe' ),
     15        register_rest_route( 'plugins/v1', '/plugin/(?P<plugin_slug>[^/]+)/favorite', array(
     16            'methods'  => array( \WP_REST_Server::READABLE, \WP_REST_Server::CREATABLE ),
     17            'callback' => array( $this, 'favorite' ),
    1818            'args' => array(
    1919                'plugin_slug' => array(
    2020                    'validate_callback' => array( $this, 'validate_plugin_slug_callback' ),
    2121                ),
    22                 'subscribe' => array(
     22                'favorite' => array(
    2323                    'validate_callback' => function( $bool ) { return is_numeric( $bool ); },
    2424                ),
    25                 'unsubscribe' => array(
     25                'unfavorite' => array(
    2626                    'validate_callback' => function( $bool ) { return is_numeric( $bool ); },
    2727                ),
     
    3232
    3333    /**
    34      * Endpoint to subscribe to a plugin's commits.
     34     * Endpoint to favorite a plugin.
    3535     *
    3636     * @param \WP_REST_Request $request The Rest API Request.
    37      * @return bool True if the subscription was successful.
     37     * @return bool True if the favoriting was successful.
    3838     */
    39     public function subscribe( $request ) {
    40         $location = get_permalink( Plugin_Directory::get_plugin_post( $request['plugin_slug'] ) ) . '#developers';
     39    public function favorite( $request ) {
     40        $location = get_permalink( Plugin_Directory::get_plugin_post( $request['plugin_slug'] ) );
    4141        header( "Location: $location" );
    4242
     
    4545        );
    4646
    47         if ( ! isset( $request['subscribe'] ) && ! isset( $request['unsubscribe'] ) ) {
     47        if ( ! isset( $request['favorite'] ) && ! isset( $request['unfavorite'] ) ) {
    4848            $result['error'] = 'Unknown Action';
    4949        }
    5050
    51         $result['subscribed'] = Tools::subscribe_to_plugin_commits( $request['plugin_slug'], get_current_user_id(), isset( $request['subscribe'] ) );
     51        $result['favorite'] = Tools::favorite_plugin( $request['plugin_slug'], get_current_user_id(), isset( $request['favorite'] ) );
    5252
    5353        return (object) $result;
Note: See TracChangeset for help on using the changeset viewer.