Ticket #1202: 1202-better-and-combined.diff
| File 1202-better-and-combined.diff, 9.3 KB (added by Gautam Gupta, 2 years ago) |
|---|
-
bb-admin/delete-user.php
1 <?php 2 require('admin-action.php'); 3 4 $user_id = (int) $_GET['id']; 5 6 bb_check_admin_referer( 'delete-user_' . $user_id ); 7 8 if ( !bb_current_user_can( 'edit_user', $user_id ) ) 9 bb_die( __( 'You can\'t do that!' ) ); 10 11 $bb_current_id = bb_get_current_user_info( 'id' ); 12 $bb_user = bb_get_user( $user_id ); 13 14 if ( !$bb_user ) 15 bb_die( __( 'There is a problem with that user.' ) ); 16 17 if ( $bb_current_id == $user_id ) 18 bb_die( __( 'You can\'t delete yourself!' ) ); 19 20 if( bb_delete_user( $user_id ) ) 21 $message = 'deleted'; 22 else 23 bb_die( __( 'There was an error deleting that user.' ) ); 24 25 if ( $sendto = wp_get_referer() ) { 26 $sendto = remove_query_arg( 'message', $sendto ); 27 $sendto = add_query_arg( 'message', $message, $sendto ); 28 } else { 29 $sendto = bb_get_uri(); 30 } 31 32 bb_safe_redirect( $sendto ); 33 exit; -
bb-admin/includes/functions.bb-admin.php
411 411 return $ids; 412 412 } 413 413 414 function bb_user_row( $user, $role = '', $e mail= false ) {414 function bb_user_row( $user, $role = '', $ed = false ) { 415 415 $actions = "<a href='" . esc_attr( get_user_profile_link( $user->ID ) ) . "'>" . __('View') . "</a>"; 416 416 $title = ''; 417 if ( bb_current_user_can( 'edit_user', $user_id ) ) { 418 $actions .= " | <a href='" . esc_attr( get_profile_tab_link( $user->ID, 'edit' ) ) . "'>" . __('Edit') . "</a>"; 417 $r = "\t<tr id='user-$user->ID'" . get_alt_class("user-$role") . ">\n"; 418 if ( bb_current_user_can( 'edit_user', $user_id ) && $ed ) { 419 $actions .= " | <a href='" . esc_attr( get_profile_tab_link( $user->ID, 'edit' ) ) . "'>" . __( 'Edit' ) . "</a>"; 420 $actions .= bb_get_user_delete_link( array( 'id' => $user->ID, 'before' => ' | ', 'after' => '', 'delete_text' => __( 'Delete' ) ) ); 419 421 $title = " title='" . esc_attr( sprintf( __( 'User ID: %d' ), $user->ID ) ) . "'"; 422 $r .= "\t\t<td class=\"check-column\"><input type=\"checkbox\" name=\"user[]\" value=\"" . $user->ID . "\" /></td> \n"; 420 423 } 421 $r = "\t<tr id='user-$user->ID'" . get_alt_class("user-$role") . ">\n";422 424 $r .= "\t\t<td class=\"user\">" . bb_get_avatar( $user->ID, 32 ) . "<span class=\"row-title\"><a href='" . get_user_profile_link( $user->ID ) . "'" . $title . ">" . get_user_name( $user->ID ) . "</a></span><div><span class=\"row-actions\">$actions</span> </div></td>\n"; 423 425 $r .= "\t\t<td><a href='" . get_user_profile_link( $user->ID ) . "'>" . get_user_display_name( $user->ID ) . "</a></td>\n"; 424 if ( $e mail) {426 if ( $ed ) { 425 427 $email = bb_get_user_email( $user->ID ); 426 428 $r .= "\t\t<td><a href='mailto:$email'>$email</a></td>\n"; 427 429 } … … 446 448 $_roles = $wp_roles->get_names(); 447 449 $role = array(); 448 450 foreach ( $user->capabilities as $cap => $cap_set ) { 449 if ( !$cap_set) {451 if ( !$cap_set || !$_roles[$cap] ) { 450 452 continue; 451 453 } 452 454 $role[] = $_roles[$cap]; … … 563 565 return false; 564 566 } 565 567 566 function display( $show_search = true, $show_email = false ) { 568 /** 569 * Displays the controls for users 570 * 571 * @param bool $show_search Show Search or not. Default true 572 * @param bool $show_ed Show Email of the user and delete options or not. Default false. Probable input could be `bb_current_user_can('edit_users') 573 */ 574 function display( $show_search = true, $show_ed = false ) { 567 575 global $wp_roles; 568 576 569 577 $r = ''; … … 627 635 $r .= "</fieldset>\n"; 628 636 $r .= "</form>\n\n"; 629 637 } 630 638 639 if( $show_ed ) { 640 $bulk_actions = array( 641 'delete' => __( 'Delete' ), 642 ); 643 }else{ 644 $bulk_actions = array(); //for plugins 645 } 646 647 do_action_ref_array( 'bulk_user_actions', array( &$bulk_actions, &$bb_user_search ) ); 648 649 $show_bulk = ( is_array( $bulk_actions ) && count( $bulk_actions ) > 0 ) ? true : false; 650 651 if( $show_bulk ){ 652 $r .= "<div class='clear'></div>\n\n"; 653 $r .= "<form class='table-form bulk-form' method='post' action=''>\n"; 654 $r .= "\t<fieldset>\n"; 655 $r .= "\t\t<select name='action'>\n"; 656 $r .= "\t\t\t<option>" . __( 'Bulk Actions' ) . "</option>\n"; 657 658 foreach ( $bulk_actions as $value => $label ) { 659 $r .= "\t\t\t<option value='" . esc_attr( $value ) . "'>" . esc_html( $label ) . "</option>\n"; 660 } 661 662 $r .= "\t\t</select>\n"; 663 $r .= "\t\t<input type='submit' value='" . esc_attr__( 'Apply' ) . "' class='button submit-input' />\n"; 664 $r .= "\t\t" . bb_nonce_field( 'user-bulk', '_wpnonce', true, false ) . "\n"; 665 $r .= "\t</fieldset>\n"; 666 } 667 631 668 if ( $this->get_results() ) { 632 669 if ( $this->results_are_paged() ) 633 670 $r .= "<div class='tablenav'>\n" . $this->paging_text . "</div><div class=\"clear\"></div>\n\n"; … … 641 678 $r .= "<table class='widefat'>\n"; 642 679 $r .= "<thead>\n"; 643 680 $r .= "\t<tr>\n"; 644 if ( $show_email ) { 681 if ( $show_bulk ) { 682 $r .= "\t\t<th scope='col' class='check-column'><input type='checkbox' /></th>\n"; 683 } 684 if ( $show_ed ) { 645 685 $r .= "\t\t<th style='width:30%;'>" . __('Username') . "</th>\n"; 646 686 $r .= "\t\t<th style='width:20%;'>" . __('Name') . "</th>\n"; 647 687 $r .= "\t\t<th style='width:20%;'>" . __('E-mail') . "</th>\n"; … … 655 695 $r .= "</thead>\n\n"; 656 696 $r .= "<tfoot>\n"; 657 697 $r .= "\t<tr>\n"; 658 if ( $show_email ) { 698 if ( $show_bulk ) { 699 $r .= "\t\t<th scope='col' class='check-column'><input type='checkbox' /></th>\n"; 700 } 701 if ( $show_ed ) { 659 702 $r .= "\t\t<th style='width:30%;'>" . __('Username') . "</th>\n"; 660 703 $r .= "\t\t<th style='width:20%;'>" . __('Name') . "</th>\n"; 661 704 $r .= "\t\t<th style='width:20%;'>" . __('E-mail') . "</th>\n"; … … 670 713 671 714 $r .= "<tbody id='role-$role'>\n"; 672 715 foreach ( (array) $this->get_results() as $user_object ) 673 $r .= bb_user_row( $user_object, $role, $show_email);716 $r .= bb_user_row( $user_object, $role, $show_ed ); 674 717 $r .= "</tbody>\n"; 675 718 $r .= "</table>\n\n"; 719 $r .= "</form>\n\n"; 676 720 //} 677 721 678 722 if ( $this->results_are_paged() ) -
bb-admin/users.php
1 1 <?php 2 2 require_once('admin.php'); 3 3 4 if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) ) { 5 6 bb_check_admin_referer( 'user-bulk' ); 7 $user_ids = array_map( 'absint', $_POST['user'] ); 8 $count = 0; 9 $bb_current_id = bb_get_current_user_info( 'id' ); 10 11 $action = trim( $_POST['action'] ); 12 13 switch ( $action ) { 14 case 'delete' : 15 foreach ( $user_ids as $user_id ) { 16 if ( $bb_current_id != $user_id ) 17 $count += (int) (bool) bb_delete_user( $user_id ); 18 } 19 $query_vars = array( 'message' => 'deleted', 'count' => $count ); 20 break; 21 default : 22 if ( $action ) 23 $query_vars = apply_filters( "bulk_user__$action", array(), $user_ids, $action ); 24 break; 25 } 26 27 bb_safe_redirect( add_query_arg( $query_vars ) ); 28 exit; 29 } 30 31 if ( !empty( $_GET['message'] ) ) { 32 $message_count = isset( $_GET['count'] ) ? (int) $_GET['count'] : 1; 33 34 switch ( (string) $_GET['message'] ) { 35 case 'deleted': 36 bb_admin_notice( sprintf( _n( '<strong>User deleted.</strong>', '<strong>%s users deleted.</strong>', $message_count ), bb_number_format_i18n( $message_count ) ) ); 37 break; 38 } 39 } 40 4 41 // Query the users 5 42 $bb_user_search = new BB_User_Search(@$_GET['usersearch'], @$_GET['page'], @$_GET['userrole']); 6 43 -
bb-includes/functions.bb-template.php
2247 2247 return apply_filters( 'get_user_delete_button', $r); 2248 2248 } 2249 2249 2250 function bb_user_delete_link( $args = '' ) { 2251 echo bb_get_user_delete_link( $args ); 2252 } 2253 2254 function bb_get_user_delete_link( $args = '' ) { 2255 $defaults = array( 'id' => 0, 'before' => '[', 'after' => ']', 'delete_text' => false, 'redirect' => true ); 2256 extract(wp_parse_args( $args, $defaults ), EXTR_SKIP); 2257 $id = (int) $id; 2258 2259 $user = bb_get_user( bb_get_user_id( $id ) ); 2260 2261 if ( !$user || !bb_current_user_can( 'edit_user', $user->ID ) ) 2262 return; 2263 2264 $bb_current_id = bb_get_current_user_info( 'id' ); 2265 if ( $bb_current_id == $user->ID ) 2266 return; 2267 2268 if ( true === $redirect ) 2269 $redirect = add_query_arg( bb_is_admin() ? array() : array( 'view' => 'all' ) ); 2270 2271 $query = array( 'id' => $user->ID, '_wp_http_referer' => $redirect ? rawurlencode( $redirect ) : false ); 2272 $confirm = __( 'Are you sure you wanna delete that user?' ); 2273 $display = esc_html( $delete_text ? $delete_text : __( 'Delete user' ) ); 2274 $uri = bb_get_uri('bb-admin/delete-user.php', $query, BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN); 2275 $uri = esc_url( bb_nonce_url( $uri, 'delete-user_' . $user->ID ) ); 2276 2277 return $before . '<a href="' . $uri . '" onclick="return confirm(\'' . esc_js( $confirm ) . '\');">' . $display . '</a>' . $after; 2278 } 2279 2250 2280 function profile_tab_link( $id = 0, $tab, $page = 1 ) { 2251 2281 echo apply_filters( 'profile_tab_link', get_profile_tab_link( $id, $tab ) ); 2252 2282 }