I have an AJAX function that sends information in userpro_ajax_urlafter a successful login through Facebook.
I am trying to get a success block to run a function do_actionusing
<?php
ob_start();
do_action('userpro_social_login', <email needs to go here>);
ob_clean();
?>
Right now, if I pass the email address manually, it works fine, however the only way to get the email dynamically is through the current response, which is in JavaScript.
Full function:
FB.api('/me?fields=name,email,first_name,last_name,gender', function(response) {
jQuery.ajax({
url: userpro_ajax_url,
data: "action=userpro_fbconnect&id="+response.id+"&username="+response.username+"&first_name="+response.first_name+"&last_name="+response.last_name+"&gender="+response.gender+"&email="+response.email+"&name="+response.name+"&link="+response.link+"&profilepicture="+encodeURIComponent(profilepicture)+"&redirect="+redirect,
dataType: 'JSON',
type: 'POST',
success:function(data){
userpro_end_load( form );
<?php
ob_start();
do_action('userpro_social_login', );
ob_clean();
?>
if (data.custom_message){
form.parents('.userpro').find('.userpro-body').prepend( data.custom_message );
}
if (data.redirect_uri){
if (data.redirect_uri =='refresh') {
} else {
}
}
},
error: function(){
alert('Something wrong happened.');
}
});
});
I tried to run the php action using:
jQuery(document).trigger('userpro_social_login', response.email);
None of these works ... what am I doing wrong?
source
share