Changeset 2752 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-committers.php
- Timestamp:
- 03/15/2016 08:02:51 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
r2655 r2752 1 1 <?php 2 2 namespace WordPressdotorg\Plugin_Directory\Admin\Metabox; 3 use WordPressdotorg\Plugin_Directory\ Tools;3 use WordPressdotorg\Plugin_Directory\Admin\Committers_List_Table; 4 4 5 5 /** … … 9 9 */ 10 10 class Committers { 11 static function display() {12 $plugin_slug = get_post()->post_name;13 $existing_committers = Tools::get_plugin_committers( $plugin_slug );14 $existing_committers = array_map( function ( $user ) {15 return new \WP_User( $user );16 }, $existing_committers );17 11 18 $output = ''; 19 foreach ( $existing_committers as $committer ) { 20 $output .= sprintf( 21 '<li title="%s"><span class="avatar">%s</span> %s</li>', 22 esc_attr( $committer->user_login ), 23 get_avatar( $committer, '24' ), 24 esc_html( $committer->display_name ) 25 ); 12 /** 13 * Filters the postbox classes for custom comment meta boxes. 14 * 15 * @param array $classes An array of postbox classes. 16 * @return array 17 */ 18 public static function postbox_classes( $classes ) { 19 $classes[] = 'committers-meta-box'; 20 21 return array_filter( $classes ); 22 } 23 24 public static function display() { 25 $list = new Committers_List_Table(); 26 $list->prepare_items(); 27 $list->display(); 28 } 29 30 public static function add_committer() { 31 check_ajax_referer( 'add-committer' ); 32 33 $login = isset( $_POST['add_committer'] ) ? sanitize_user( $_POST['add_committer'] ) : ''; 34 $post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0; 35 36 if ( ! $committer = get_user_by( 'login', $login ) ) { 37 wp_die( time() ); 26 38 } 27 echo '<ul class="committers">' . $output . '</ul>'; 39 40 if ( ! current_user_can( 'manage_committers', $post_id ) ) { 41 // wp_die( -1 ); 42 } 43 global $post, $wpdb; 44 45 $response = new \WP_Ajax_Response(); 46 $post = get_post( $post_id ); 47 48 $result = $wpdb->insert( PLUGINS_TABLE_PREFIX . 'svn_access', array( 49 'path' => "/{$post->post_name}", 50 'user' => $login, 51 'access' => 'rw', 52 ) ); 53 54 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(); 58 } 59 60 $response->add( array( 61 'what' => 'committer', 62 'data' => new \WP_Error( 'error', $message ), 63 ) ); 64 $response->send(); 65 } 66 67 $wp_list_table = new Committers_List_Table(); 68 69 $response->add( array( 70 'what' => 'committer', 71 'id' => $committer->ID, 72 'data' => $wp_list_table->single_row( $committer ), 73 'position' => -1, 74 ) ); 75 $response->send(); 76 } 77 78 public static function remove_committer() { 79 $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0; 80 $post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0; 81 82 check_ajax_referer( "remove-committer-$id" ); 83 84 if ( ! $committer = get_user_by( 'id', $id ) ) { 85 wp_die( time() ); 86 } 87 88 if ( ! current_user_can( 'manage_committers', $post_id ) ) { 89 // wp_die( -1 ); 90 } 91 92 $plugin_slug = get_post( $post_id )->post_name; 93 94 $result = $GLOBALS['wpdb']->delete( PLUGINS_TABLE_PREFIX . 'svn_access', array( 95 'path' => "/{$plugin_slug}", 96 'user' => $committer->user_login, 97 ) ); 98 99 wp_die( $result ); 28 100 } 29 101 }
Note: See TracChangeset
for help on using the changeset viewer.