T
T
Thes2020-07-08 00:51:55
WordPress
Thes, 2020-07-08 00:51:55

How to properly process field data with a nonce?

Hello!
How to do wp_create_nonce for forms and process data through a one-time check is understandable, but how to check for such cases when there is no form, and the data is updated like this:

function user_rules( $user_id ) {
  if ( ! empty( $_POST['user_rules'] ) ) {
    update_user_meta( $user_id, 'user_rules', esc_attr( $_POST['user_rules'] ) );
  }
}
add_action( 'user_register', 'user_rules' );

That is, when registering, a checkbox is created, if it is not empty, then when creating a new user, it is written: user_rules with a value of true .
Do I need to check the $_POST['user_rules'] request through wp_verify_nonce, if so, tell me how.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question