Changeset 5867 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-support-reps.php
- Timestamp:
- 09/03/2017 09:43:53 PM (7 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-plugin-support-reps.php
r5864 r5867 11 11 12 12 /** 13 * An API Endpoint to manage plugin committers.13 * An API Endpoint to manage plugin support reps. 14 14 * 15 15 * @package WordPressdotorg_Plugin_Directory 16 16 */ 17 class Plugin_ Committers extends Base {17 class Plugin_Support_Reps extends Base { 18 18 19 19 function __construct() { 20 register_rest_route( 'plugins/v1', '/plugin/(?P<plugin_slug>[^/]+)/ committers/?', array(20 register_rest_route( 'plugins/v1', '/plugin/(?P<plugin_slug>[^/]+)/support-reps/?', array( 21 21 array( 22 22 'methods' => WP_REST_Server::READABLE, 23 'callback' => array( $this, 'list_ committers' ),23 'callback' => array( $this, 'list_support_reps' ), 24 24 'permission_callback' => function( $request ) { 25 25 return current_user_can( … … 37 37 array( 38 38 'methods' => WP_REST_Server::CREATABLE, 39 'callback' => array( $this, 'add_ committer' ),39 'callback' => array( $this, 'add_support_rep' ), 40 40 'permission_callback' => function( $request ) { 41 41 return current_user_can( 42 'plugin_add_ committer',42 'plugin_add_support_rep', 43 43 Plugin_Directory::get_plugin_post( $request['plugin_slug'] ) 44 44 ); … … 53 53 ) ); 54 54 55 register_rest_route( 'plugins/v1', '/plugin/(?P<plugin_slug>[^/]+)/ committers/(?P<committer>[^/]+)/?', array(55 register_rest_route( 'plugins/v1', '/plugin/(?P<plugin_slug>[^/]+)/support-reps/(?P<support_rep>[^/]+)/?', array( 56 56 'methods' => WP_REST_Server::DELETABLE, 57 'callback' => array( $this, 're voke_committer' ),57 'callback' => array( $this, 'remove_support_rep' ), 58 58 'permission_callback' => function( $request ) { 59 59 return current_user_can( 60 'plugin_remove_ committer',60 'plugin_remove_support_rep', 61 61 Plugin_Directory::get_plugin_post( $request['plugin_slug'] ) 62 62 ); … … 67 67 'required' => true, 68 68 ), 69 ' committer' => array(69 'support_rep' => array( 70 70 'validate_callback' => array( $this, 'validate_user_slug_callback' ), 71 71 'required' => true, … … 78 78 * 79 79 */ 80 function list_ committers( $request ) {80 function list_support_reps( $request ) { 81 81 $plugin_slug = $request['plugin_slug']; 82 82 83 $ committers = array();84 foreach ( (array) Tools::get_plugin_ committers( $plugin_slug ) as $user_login) {85 $user = get_user_by( ' login', $user_login);86 $ committers[] = $this->user_committer_details( $user );83 $support_reps = array(); 84 foreach ( (array) Tools::get_plugin_support_reps( $plugin_slug ) as $user_nicename ) { 85 $user = get_user_by( 'slug', $user_nicename ); 86 $support_reps[] = $this->user_support_rep_details( $user ); 87 87 } 88 88 89 return $ committers;89 return $support_reps; 90 90 } 91 91 92 function add_ committer( $request ) {93 $user = new WP_User( $request[' committer'] );92 function add_support_rep( $request ) { 93 $user = new WP_User( $request['support_rep'] ); 94 94 if ( ! $user->exists() ) { 95 95 return new WP_Error( 'plugin_user_not_found', __( 'The provided user could not be found.', 'wporg-plugins' ) ); … … 98 98 $plugin_slug = $request['plugin_slug']; 99 99 100 if ( ! Tools:: grant_plugin_committer( $plugin_slug, $user ) ) {100 if ( ! Tools::add_plugin_support_rep( $plugin_slug, $user ) ) { 101 101 return new WP_Error( 'failed', __( 'The operation failed. Please try again.', 'wporg-plugins' ) ); 102 102 } 103 103 104 return $this->user_ committer_details( $user );104 return $this->user_support_rep_details( $user ); 105 105 } 106 106 107 function re voke_committer( $request ) {108 $user = new WP_User( $request[' committer'] );107 function remove_support_rep( $request ) { 108 $user = new WP_User( $request['support_rep'] ); 109 109 if ( ! $user->exists() ) { 110 110 return new WP_Error( 'plugin_user_not_found', __( 'The provided user could not be found.', 'wporg-plugins' ) ); … … 113 113 $plugin_slug = $request['plugin_slug']; 114 114 115 $result = Tools::re voke_plugin_committer( $plugin_slug, $user );115 $result = Tools::remove_plugin_support_rep( $plugin_slug, $user ); 116 116 if ( ! $result ) { 117 117 return new WP_Error( 'failed', __( 'The operation failed. Please try again.', 'wporg-plugins' ) ); … … 129 129 130 130 /** 131 * Helper function to return a committerobject131 * Helper function to return a support rep object 132 132 */ 133 function user_ committer_details( $user ) {133 function user_support_rep_details( $user ) { 134 134 $data = array( 135 135 'nicename' => $user->user_nicename,
Note: See TracChangeset
for help on using the changeset viewer.