Changeset 2753 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-committers.php
- Timestamp:
- 03/15/2016 09:11:27 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-committers.php
r2752 r2753 22 22 } 23 23 24 /** 25 * Displays a list of committers for the current plugin. 26 */ 24 27 public static function display() { 25 28 $list = new Committers_List_Table(); … … 28 31 } 29 32 33 /** 34 * Ajax handler for adding a new committer. 35 */ 30 36 public static function add_committer() { 31 37 check_ajax_referer( 'add-committer' ); 32 38 33 $login = isset( $_POST['add_committer'] ) ? sanitize_user( $_POST['add_committer'] ) : ''; 34 $post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0; 39 $login = isset( $_POST['add_committer'] ) ? sanitize_user( $_POST['add_committer'] ) : ''; 40 $post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0; 41 $response = new \WP_Ajax_Response(); 35 42 36 43 if ( ! $committer = get_user_by( 'login', $login ) ) { 37 wp_die( time() ); 44 $response->add( array( 45 'what' => 'committer', 46 'data' => new \WP_Error( 'error', sprintf( __( 'The user %s does not exist.', 'wporg-plugins' ), '<code>' . $login . '</code>' ) ), 47 ) ); 48 $response->send(); 38 49 } 39 50 40 if ( ! current_user_can( 'manage_committers', $post_id ) ) { 41 // wp_die( -1 ); 51 // @todo: Capabilities. 52 if ( ! current_user_can( 'add_committers', $post_id ) ) { 53 // wp_die( -1 ); 42 54 } 43 55 global $post, $wpdb; 44 56 45 $response = new \WP_Ajax_Response(); 46 $post = get_post( $post_id ); 47 57 $post = get_post( $post_id ); 48 58 $result = $wpdb->insert( PLUGINS_TABLE_PREFIX . 'svn_access', array( 49 59 'path' => "/{$post->post_name}", … … 51 61 'access' => 'rw', 52 62 ) ); 53 54 63 if ( ! $result ) { 55 $message = __( 'An error has occurred. Please reload the page and try again.' ); 56 if ( is_wp_error( $result ) && $result->get_error_message() ) { 57 $message = $result->get_error_message(); 64 if ( 'Duplicate entry' === substr( $wpdb->last_error, 0, 15 ) ) { 65 $message = __( 'Duplicate committer detected.', 'wporg-plugins' ); 66 } else { 67 $message = __( 'An error has occurred. Please reload the page and try again.', 'wporg-plugins' ); 58 68 } 59 69 … … 76 86 } 77 87 88 /** 89 * Ajax handler for removing a committer. 90 */ 78 91 public static function remove_committer() { 79 92 $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; … … 82 95 check_ajax_referer( "remove-committer-$id" ); 83 96 97 $response = new \WP_Ajax_Response(); 98 84 99 if ( ! $committer = get_user_by( 'id', $id ) ) { 85 wp_die( time() ); 100 $response->add( array( 101 'what' => 'committer', 102 'data' => new \WP_Error( 'error', sprintf( __( 'The user %s does not exist.', 'wporg-plugins' ), '<code>' . $login . '</code>' ) ), 103 ) ); 104 $response->send(); 86 105 } 87 106 88 if ( ! current_user_can( 'manage_committers', $post_id ) ) { 89 // wp_die( -1 ); 107 // @todo: Capabilities. 108 if ( ! current_user_can( 'remove_committers', $post_id ) ) { 109 // wp_die( -1 ); 90 110 } 91 111 … … 93 113 94 114 $result = $GLOBALS['wpdb']->delete( PLUGINS_TABLE_PREFIX . 'svn_access', array( 95 'path' 96 'user' 115 'path' => "/{$plugin_slug}", 116 'user' => $committer->user_login, 97 117 ) ); 98 118
Note: See TracChangeset
for help on using the changeset viewer.