Changeset 3545 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-favorites.php
- Timestamp:
- 06/22/2016 01:33:53 PM (8 years ago)
- 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 6 6 7 7 /** 8 * An API endpoint for subscribing to commits fora particular plugin.8 * An API endpoint for favoriting a particular plugin. 9 9 * 10 10 * @package WordPressdotorg_Plugin_Directory 11 11 */ 12 class Commit_Subscriptions extends Base {12 class Plugin_Favorites extends Base { 13 13 14 14 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' ), 18 18 'args' => array( 19 19 'plugin_slug' => array( 20 20 'validate_callback' => array( $this, 'validate_plugin_slug_callback' ), 21 21 ), 22 ' subscribe' => array(22 'favorite' => array( 23 23 'validate_callback' => function( $bool ) { return is_numeric( $bool ); }, 24 24 ), 25 'un subscribe' => array(25 'unfavorite' => array( 26 26 'validate_callback' => function( $bool ) { return is_numeric( $bool ); }, 27 27 ), … … 32 32 33 33 /** 34 * Endpoint to subscribe to a plugin's commits.34 * Endpoint to favorite a plugin. 35 35 * 36 36 * @param \WP_REST_Request $request The Rest API Request. 37 * @return bool True if the subscriptionwas successful.37 * @return bool True if the favoriting was successful. 38 38 */ 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'] ) ); 41 41 header( "Location: $location" ); 42 42 … … 45 45 ); 46 46 47 if ( ! isset( $request[' subscribe'] ) && ! isset( $request['unsubscribe'] ) ) {47 if ( ! isset( $request['favorite'] ) && ! isset( $request['unfavorite'] ) ) { 48 48 $result['error'] = 'Unknown Action'; 49 49 } 50 50 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'] ) ); 52 52 53 53 return (object) $result;
Note: See TracChangeset
for help on using the changeset viewer.