Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the broken user-approved-filter (WP 4.4+) #44

Merged
merged 1 commit into from
Oct 4, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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} wp_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