Ihave the code from here and used it to create a checkbox in the user backend. This should show which members have paid. I can also change this checkbox directly in the user’s profile. But is there a way to change and apply this via the checkbox directly in the table. i.e. select a checkbox and that’s it? or also with an Apply button?
add_filter(
'manage_users_columns',
function( $columns ) {
$columns['paid'] = 'Beitrag gezahlt';
return $columns;
}
);
add_filter( 'manage_users_custom_column', 'manage_users_custom_column_callback', 10, 3 );
function manage_users_custom_column_callback( $val, $column_name, $user_id ) {
$checked = get_user_meta( $user_id, 'payment_status', true ) ? 'checked' : '';
switch ( $column_name ) {
case 'paid':
return '<input type="checkbox" id="your_id" name="your_id" value="your_value" ' . $checked . '>';
default:
}
return $val;
}
add_action( 'show_user_profile', 'add_custom_payment_checkbox_callback' );
add_action( 'personal_options_update', 'save_custom_payment_checkbox_callback' );
add_action( 'edit_user_profile', 'add_custom_payment_checkbox_callback' );
add_action( 'edit_user_profile_update', 'save_custom_payment_checkbox_callback' );
function add_custom_payment_checkbox_callback( $user ) {
$user_id = $user->data->ID;
$checked = get_user_meta( $user_id, 'payment_status', true ) ? 'checked' : '';
printf(
'
<h3>%1$s</h3>
<table class="form-table">
<tr>
<th><label for="Payment">%2$s</label></th>
<td>
<input type="checkbox" id="your_id" name="payment_status" value="your_value" ' . $checked . '>
<br /><span class="description">%4$s</span>
</td>
</tr>
</table>
',
__( 'Extra Profile Information', 'locale' ),
__( 'Beitrag gezahlt?', 'locale' ),
esc_attr( get_user_meta( $user->ID, 'payment_status', true ) ),
__( '', 'locale' )
);
}
function save_custom_payment_checkbox_callback( $user_id ) {
if ( ! current_user_can( 'edit_user', $user_id ) ) {
return false;
}
$payment_status = ( isset( $_POST['payment_status'] ) ) ? 'paid' : '';
update_user_meta( $user_id, 'payment_status', $payment_status);
}
Add this code to functions.php and test it.