wp_login not working but wp_enqueue_scripts working

This currently works:

function identify_user() {
if( is_user_logged_in()):
$current_user = wp_get_current_user();
$_id = $current_user->ID;
$_email = $current_user->user_email;
$user = json_encode(array(“user_id”=>$_id,”user_email”=>$_email));
$curl = curl_init(“myWebsite.com/endpoint”);
curl_setopt( $curl, CURLOPT_POST, true );
curl_setopt( $curl, CURLOPT_POSTFIELDS,$user);
curl_setopt($ch, CURLOPT_HTTPHEADER,array(‘Content-Type:application/json’));
curl_exec( $curl );
curl_close( $curl );
endif;
}

add_action( ‘wp_enqueue_scripts’, ‘identify_user’);

But if I switch wp_enqueue_scripts with wp_login, nothing happens when I log in and out. How do I enqueue a script that only fires on an action?

function identify_user() {
function identify(){
if( is_user_logged_in()):
$current_user = wp_get_current_user();
$_id = $current_user->ID;
$_email = $current_user->user_email;
$user = json_encode(array(“user_id”=>$_id,”user_email”=>$_email));
$curl = curl_init(“www.mywebsite.com/endpoint”);
curl_setopt( $curl, CURLOPT_POST, true );
curl_setopt( $curl, CURLOPT_POSTFIELDS,$user);
curl_setopt($ch, CURLOPT_HTTPHEADER,array(‘Content-Type:application/json’));
curl_exec( $curl );
curl_close( $curl );
endif;
}
add_action( ‘wp_login’, ‘identify’);
}

add_action( ‘wp_enqueue_scripts’, ‘identify_user’);

I don’t think this will work, but I’m not sure how to go about this.

Read more here:: wp_login not working but wp_enqueue_scripts working

Leave a Reply

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