Skip to content

Commit

Permalink
Fixed the broken user-approved-filter by extending it to use two sepe…
Browse files Browse the repository at this point in the history
…rate inputs for top and bottom bar. (#44)
  • Loading branch information
Julian authored and picklewagon committed Oct 4, 2016
1 parent a9813f8 commit 3aea225
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions includes/user-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function instance() {
private function __construct() {
// Actions
add_action( 'load-users.php', array( $this, 'update_action' ) );
add_action( 'restrict_manage_users', array( $this, 'status_filter' ) );
add_action( 'restrict_manage_users', array( $this, 'status_filter' ), 10, 1 );
add_action( 'pre_user_query', array( $this, 'filter_by_status' ) );
add_action( 'admin_footer-users.php', array( $this, 'admin_footer' ) );
add_action( 'load-users.php', array( $this, 'bulk_action' ) );
Expand Down Expand Up @@ -161,14 +161,16 @@ public function status_column( $val, $column_name, $user_id ) {
*
* @uses restrict_manage_users
*/
public function status_filter() {
public function status_filter( $which ) {
$id = 'bottom' === $which ? 'new_user_approve_filter2' : 'new_user_approve_filter';

$filter_button = submit_button( __( 'Filter', 'new-user-approve' ), 'button', 'pw-status-query-submit', false, array( 'id' => 'pw-status-query-submit' ) );
$filtered_status = ( isset( $_GET['new_user_approve_filter'] ) ) ? esc_attr( $_GET['new_user_approve_filter'] ) : '';
$filtered_status = $this->selected_status();

?>
<label class="screen-reader-text"
for="new_user_approve_filter"><?php _e( 'View all users', 'new-user-approve' ); ?></label>
<select id="new_user_approve_filter" name="new_user_approve_filter" style="float: none; margin: 0 0 0 15px;">
for="<?php echo $id ?>"><?php _e( 'View all users', 'new-user-approve' ); ?></label>
<select id="<?php echo $id ?>" name="<?php echo $id ?>" style="float: none; margin: 0 0 0 15px;">
<option value=""><?php _e( 'View all users', 'new-user-approve' ); ?></option>
<?php foreach ( pw_new_user_approve()->get_valid_statuses() as $status ) : ?>
<option
Expand Down Expand Up @@ -203,8 +205,8 @@ public function filter_by_status( $query ) {
return;
}

if ( isset( $_GET['new_user_approve_filter'] ) && $_GET['new_user_approve_filter'] != '' ) {
$filter = esc_attr( $_GET['new_user_approve_filter'] );
if ( $this->selected_status() != null ) {
$filter = $this->selected_status();

$query->query_from .= " INNER JOIN {$wpdb->usermeta} ON ( {$wpdb->users}.ID = wp_usermeta.user_id )";

Expand All @@ -218,6 +220,14 @@ public function filter_by_status( $query ) {
}
}

private function selected_status() {
if ( ! empty( $_REQUEST['new_user_approve_filter'] ) || ! empty( $_REQUEST['new_user_approve_filter2'] ) ) {
return esc_attr( ( ! empty( $_REQUEST['new_user_approve_filter'] ) ) ? $_REQUEST['new_user_approve_filter'] : $_REQUEST['new_user_approve_filter2'] );
}

return null;
}

/**
* Use javascript to add the ability to bulk modify the status of users.
*
Expand Down Expand Up @@ -270,7 +280,7 @@ public function bulk_action() {
return;
}

$sendback = remove_query_arg( array( 'approved', 'denied', 'deleted', 'ids', 'new_user_approve_filter', 'pw-status-query-submit', 'new_role' ), wp_get_referer() );
$sendback = remove_query_arg( array( 'approved', 'denied', 'deleted', 'ids', 'new_user_approve_filter', 'new_user_approve_filter2', 'pw-status-query-submit', 'new_role' ), wp_get_referer() );
if ( !$sendback ) {
$sendback = admin_url( 'users.php' );
}
Expand Down

0 comments on commit 3aea225

Please sign in to comment.