Good morning, I’m trying to login to WordPress users via external scripts, recording is ok, but I have a problem with login. This is my script that works only if I write the values ​​in the arrays, if I put the variable does not work.

<?php
    define( 'WP_USE_THEMES', false );
    define( 'COOKIE_DOMAIN', false );
    define( 'DISABLE_WP_CRON', true );

require("/home/MYDOMAIN/public_html/wp-load.php");


$u = $_POST['u'];
$p = $_POST['p'];


function custom_login(){
    $cred = array();
    $cred ['user_login'] = 'username';  --> if i put $u NOT WORK
    $cred ['user_password'] = 'password'; --> if i put $p NOT WORK
    $cred ['remember'] = true;
    $user = wp_signon($cred, false);
    if(is_wp_error($user))
        echo $user->get_error_message();

}
 add_action( 'after_setup_theme', 'custom_login' );

?>
<html>
<h1>Ciao</h1>

<form action="<?php custom_login() ?>" >
<input type="submit" value="Login">
</form>     
</html>

Read more here: Login wordpress external script


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: