Login wordpress external script

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.

    define( 'WP_USE_THEMES', false );
    define( 'COOKIE_DOMAIN', false );
    define( 'DISABLE_WP_CRON', true );


$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);
        echo $user->get_error_message();

 add_action( 'after_setup_theme', 'custom_login' );


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

Read more here: Login wordpress external script

Leave a Reply

Your email address will not be published. Required fields are marked *