How to correctly do the data transfer in wp_signon( ) without any error on the admin side?

You need to authenticate the user. In the code example:
function custom_login() {
 $creds = array();
 $creds['user_login'] = 'example';
 $creds['user_password'] = 'plaintextpw';
 $creds['remember'] = true;
 $user = wp_signon( $creds, false );
 if ( is_wp_error($user) )
 echo $user->get_error_message();
}
// run it before the headers and cookies are sent
add_action( 'after_setup_theme', 'custom_login' );


If I give in wp_signon( ) with POST data:
function custom_login() {
 $creds = array();
 $creds['user_login'] = $_POST['log'];
 $creds['user_password'] = $_POST['pwd'];
 $creds['remember'] = true;
 $user = wp_signon( );
 if ( is_wp_error($user) )
 echo $user->get_error_message();
}
// run it before the headers and cookies are sent
add_action( 'after_setup_theme', 'custom_login' );


Yes, authentication works, but when you try to save/delete in the admin post or change the theme I get the error "are you sure You want to do this?
Please try again."

Such situation:
- when any approved subject (testile),
- the direct indication in the code of the login and password error in the admin does not occur only when sending a POST (also already checked),
- other plugins are not affected (deployed on a clean engine - same behavior)

engine version 5.4.2
How to make correctly the transfer of data in wp_signon( )? I understand that most likely my fault some stupid PTS, but nothing substantial on this issue naguglit failed.
July 12th 19 at 13:22

Find more questions by tags WordPress