I am asking user few questions at the time of registration with checkboxes like
In Registration form
[] I am blah blah
[] I am blan blah
[] I am blah blah
Now user will come for approval in admin panel, in pending state.
I want to add above (Checkbox) in the listing user table. So Admin can change the data if he wants inline and as soon as click on approve data get saved in the database for that user.
This is what i have tried.
function X_member_user_table( $columns ) {
$columns['dbem_X_member_f'] = 'Member';
$columns['dbem_X_delegate_f'] = 'Delegate';
$columns['dbem_X_sponsor_f'] = 'Sponsor';
return $columns;
}
add_filter( 'manage_users_columns', 'X_member_user_table' );
function X_modify_user_table_row( $val, $column_name, $user_id ) {
$column_value = get_the_author_meta($column_name,$user_id );
//return "<input type='checkbox' name='".$column_name_.$user_id."' value='".$column_value."' id='".$column_name_.$user_id."'/>";
//return "<input onclick='$(form).serialize();' type='checkbox' name='{$column_name}[]' id='{$column_name}_{$user_id}' class='$role' value='{$user_id}' />";
$checkbox = '<label class="screen-reader-text" for="cb-select-'.$column_name."_" . $user_id . '">' . '</label>'
. "<input type='checkbox' name='{$column_name}[]' id='user_{$column_name}_{$user_id}' class='$role' value='{$column_value}' />";
return $checkbox;
}
add_filter( 'manage_users_custom_column', 'X_modify_user_table_row', 10, 3 );
I am able to get checkbox in the user table. Now the question is how to get the in $GET
or $POST
when user clicks on Approve link. This link is just redirecting the page and not submitting the page so i do not think it will come in post.
I have created below method to get data in GET
attributes. Do I need to use jQuery to build data in it?
function X_user_row_actions($actions, $user_object){
$current_user = wp_get_current_user();
$u = $user_object->ID;
if ( $current_user->ID != $user_object->ID ) {
/*if ( in_array( 'pending', (array) $user_object->roles ) ) {
switch ( get_option( 'type' ) ) {
case 'admin' :*/
// Add "Approve" link
$actions['approve-X-user'] = sprintf( '<a href="%1$s">%2$s</a>',
add_query_arg( 'wp_http_referer',
urlencode( esc_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ),
wp_nonce_url( "users.php?action=approve&user=$user_object->ID&dbem_X_member_f=1", 'approve-X-user' )
),
__( 'Approve with changes', 'theme-my-login' )
);
//break;
//}
//}
}
return $actions;
echo "<pre>";
print "X row";
print_r($actions);
print_r($user_object);
echo "</pre>";
return $actions;
//exit;
}
add_filter( 'user_row_actions', 'X_user_row_actions' , 10, 2 );
However it is not working. Is there any hook to use when Approve is clicked, or change its status?
Yes, we need jQuery for that. The first thing is to give proper classes and ID’s to the elements.
In
manage_users_custom_column
, add a class and a data selector to the checkbox:And in
user_row_actions
, an ID to the<a>
tag:id='approval-$user_id'
.Now, we have all the elements properties and can manipulate the URL of the Approve with changes links.
Hint: use
sprintf
to build$checkbox
.