Ticket #1202: functions.bb-admin.php.diff

File functions.bb-admin.php.diff, 4.0 KB (added by Gautam Gupta, 2 years ago)

Part 3 - Adds bulk editing and single user delete link

  • functions.bb-admin.php

     
    411411        return $ids; 
    412412} 
    413413 
    414 function bb_user_row( $user, $role = '', $email = false ) { 
     414function bb_user_row( $user, $role = '', $email = false, $delete = false ) { 
    415415        $actions = "<a href='" . esc_attr( get_user_profile_link( $user->ID ) ) . "'>" . __('View') . "</a>"; 
    416416        $title = ''; 
    417417        if ( bb_current_user_can( 'edit_user', $user_id ) ) { 
    418                 $actions .= " | <a href='" . esc_attr( get_profile_tab_link( $user->ID, 'edit' ) ) . "'>" . __('Edit') . "</a>"; 
     418                $actions .= " | <a href='" . esc_attr( get_profile_tab_link( $user->ID, 'edit' ) ) . "'>" . __( 'Edit' ) . "</a>"; 
     419                $actions .= bb_get_user_delete_link( array( 'id' => $user->ID, 'before' => ' | ', 'after' => '', 'delete_text' => __( 'Delete' ) ) ); 
    419420                $title = " title='" . esc_attr( sprintf( __( 'User ID: %d' ), $user->ID ) ) . "'"; 
    420421        } 
    421422        $r  = "\t<tr id='user-$user->ID'" . get_alt_class("user-$role") . ">\n"; 
     423        if ( $delete ) { 
     424                $r .= "\t\t<td class=\"check-column\"><input type=\"checkbox\" name=\"user[]\" value=\"" . $user->ID . "\" /></td> \n"; 
     425        } 
    422426        $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>&nbsp;</div></td>\n"; 
    423427        $r .= "\t\t<td><a href='" . get_user_profile_link( $user->ID ) . "'>" . get_user_display_name( $user->ID ) . "</a></td>\n"; 
    424428        if ( $email ) { 
     
    563567                return false; 
    564568        } 
    565569 
    566         function display( $show_search = true, $show_email = false ) { 
     570        function display( $show_search = true, $show_email = false, $show_delete = false ) { 
    567571                global $wp_roles; 
    568572 
    569573                $r = ''; 
     
    627631                        $r .= "</fieldset>\n"; 
    628632                        $r .= "</form>\n\n"; 
    629633                } 
     634                 
     635                if( $show_delete ) { 
     636                        $bulk_actions = array( 
     637                                'delete' => __( 'Delete' ), 
     638                        ); 
     639                }else{ 
     640                        $bulk_actions = array(); //for plugins 
     641                } 
     642                 
     643                do_action_ref_array( 'bulk_user_actions', array( &$bulk_actions, &$bb_user_search ) ); 
     644                 
     645                $r .= "<div class='clear'></div>\n\n"; 
     646                $r .= "<form class='table-form bulk-form' method='post' action=''>\n"; 
     647                $r .= "\t<fieldset>\n"; 
     648                $r .= "\t\t<select name='action'>\n"; 
     649                $r .= "\t\t\t<option>" . __( 'Bulk Actions' ) . "</option>\n"; 
     650                 
     651                foreach ( $bulk_actions as $value => $label ) : 
     652                        $r .= "\t\t\t<option value='" . esc_attr( $value ) . "'>" . esc_html( $label ) . "</option>\n"; 
     653                endforeach; 
     654                 
     655                $r .= "\t\t</select>\n"; 
     656                $r .= "\t\t<input type='submit' value='" . esc_attr__( 'Apply' ) . "' class='button submit-input' />\n"; 
     657                $r .= "\t\t" . bb_nonce_field( 'user-bulk', '_wpnonce', true, false ) . "\n"; 
     658                $r .= "\t</fieldset>\n"; 
    630659 
    631660                if ( $this->get_results() ) { 
    632661                        if ( $this->results_are_paged() ) 
     
    641670                                $r .= "<table class='widefat'>\n"; 
    642671                                $r .= "<thead>\n"; 
    643672                                $r .= "\t<tr>\n"; 
     673                                if ( $show_delete ) { 
     674                                        $r .= "\t\t<th scope='col' class='check-column'><input type='checkbox' /></th>\n"; 
     675                                } 
    644676                                if ( $show_email ) { 
    645677                                        $r .= "\t\t<th style='width:30%;'>" . __('Username') . "</th>\n"; 
    646678                                        $r .= "\t\t<th style='width:20%;'>" . __('Name') . "</th>\n"; 
     
    655687                                $r .= "</thead>\n\n"; 
    656688                                $r .= "<tfoot>\n"; 
    657689                                $r .= "\t<tr>\n"; 
     690                                if ( $show_delete ) { 
     691                                        $r .= "\t\t<th scope='col' class='check-column'><input type='checkbox' /></th>\n"; 
     692                                } 
    658693                                if ( $show_email ) { 
    659694                                        $r .= "\t\t<th style='width:30%;'>" . __('Username') . "</th>\n"; 
    660695                                        $r .= "\t\t<th style='width:20%;'>" . __('Name') . "</th>\n"; 
     
    670705 
    671706                                $r .= "<tbody id='role-$role'>\n"; 
    672707                                foreach ( (array) $this->get_results() as $user_object ) 
    673                                         $r .= bb_user_row($user_object, $role, $show_email); 
     708                                        $r .= bb_user_row($user_object, $role, $show_email, $show_delete); 
    674709                                $r .= "</tbody>\n"; 
    675710                                $r .= "</table>\n\n"; 
     711                                $r .= "</form>\n\n"; 
    676712                        //} 
    677713 
    678714                        if ( $this->results_are_paged() )