I would like to use a link to the sign up that contains a code. (This code is generated when a new user has been referred by an existing user and we use it to take a specific action upon account creation.)
I need a way so that after the new user has registered via social login, the code can still be retrieved. In other words, a way of preserving the code that is in the link to the signup page so that it isn't lost when the user connects with their social network and can then be associated afterwards with their account.
Thank you.
Answers
You could add your signup code as an extra parameter to the plugin's callback_uri.
This callback is usually set in the javascript on your page.
Regards
I looked here and found the following code to change oneall's callback:
https://docs.oneall.com/services/implementation-guide/social-login/
_oneall.push([\'social_login\', \'set_callback_uri\', your_callback_script]);
I am trying the following code but it's not changing the callback.
In the page:
[oa_social_login]
[social_login_callback_add_code]//
Shortcode php echoing javascript (tested the php -> javascript echoing and that method is working):
<?php
//SOCIAL LOGIN CHANGE callback to include code from link to process after login/registration
function social_login_callback_add_code() {
if ( !empty( htmlspecialchars( $_GET["code"] ) ) ) {//there is a code
$friend_code = htmlspecialchars( $_GET["code"] );
$new_callback = 'http://employwe.com/bonus/?code=' . $friend_code;
echo '<script type="text/javascript">
/* Replace #your_callback_uri# with the url to your own callback script */
var your_callback_script = ' . $new_callback . ';
/* Embeds the buttons into the container oa_social_login_container */
var _oneall = _oneall || [];
_oneall.push([\'social_login\', \'set_callback_uri\', your_callback_script]);
';
}
}
add_shortcode( 'social_login_callback_add_friend_code', 'social_login_callback_add_code' );
?>
If you use your shortcode, you need to add the code parameter in the shortcode [... code="xxxx"]. (which you are probably doing but did not include in your post)
Also, adding oa_social_login will display the regular icons, without your callback.
So, you could use only your shortcode, but include the line
return oa_social_login_render_login_form ('shortcode');
to display icons.Then add an argument with the callback, such as:
oa_social_login_render_login_form ('shortcode', array ('callback_uri => 'your callback with code'));
Not tested, just ideas from your description that we probable misunderstood!
Now we have:
In the page calling shortcode:
[social_login_callback_add_code]
For the new shortcode, I replaced this line "_oneall.push([\'social_login\', \'set_callback_uri\', your_callback_script]);" with your suggested "oa_social_login_render_login_form ('shortcode', array ('callback_uri => 'your callback with code'));"
After that we are outputting with "return oa_social_login_render_login_form ('shortcode');". By the way, the return is working because the OneAll login icon is showing up fine and works. (It's just that the callback URL isn't changed.)
So new shortcode is:
//SOCIAL LOGIN CHANGE callback to include code from link to process after login/registration
function social_login_callback_add_code() {
if ( !empty( htmlspecialchars( $_GET["code"] ) ) ) {//there is a code
$code = htmlspecialchars( $_GET["code"] );
/* Javascript to put Code extracted using php into OneAll icon */
echo '
oa_social_login_render_login_form (\'shortcode\', array (\'callback_uri\' => \'http://example.com/?code=' . $code . '\'));
';
}
return oa_social_login_render_login_form ('shortcode');
}
add_shortcode( 'social_login_callback_add_code', 'social_login_callback_add_code' );
After a quick glance, 2 calls to oa_social_login_render_login_form seems odd, especially the second one which is without the custom callback.
But, we will test it out and let you know.
The following code works, however, it is a rough solution.
To use the existing shortcode, with your signup code option, like this:
[oa_social_login code="1234"]
then, in user_interface.php, modify lines ~430 into: where code is the signup code. You can change those accordingly. Also, this modifies the existing shortcode handler, you could add your own.
If you need to add JS code inside the callback uri, then you will have further modify user_interface.php, line 951 (because of single quotes required for login window).
Hope this helps.
Entered the new solution.
[oa_social_login code="1234"] doesn't render the login icon...
Widget & Shortcode Settings
Redirect users to this page after they have logged in with Social Login embedded by Widget/Shortcode:
Redirect users back to the current page (Default)
Redirect users to the homepage of my blog
Redirect users to their account dashboard
Redirect users to the following url:
I see this on 951 but I don't understand what you mean by single quotes and where that is:
"//Build Callback URI
if (array_key_exists ('callback_uri', $args) AND !empty ($args ['callback_uri']))
{
$callback_uri = "'" . $args ['callback_uri'] . "'";
}
else
{
$callback_uri = "(window.location.href + ((window.location.href.split('?')[1] ? '&': '?') + \"oa_social_login_source=" . $source . "\"))";
}
//No providers selected
if (count ($providers) == 0)
{
$output = '
}"
In the page call to shortcode:
[social_login_callback_add_code]
Shortcode in php file echoing HTML and using "do_shortcode":
//SOCIAL LOGIN CHANGE callback to include code from link to process after login/registration
function social_login_callback_add_code() {
if ( !empty( htmlspecialchars( $_GET["code"] ) ) ) {//there is a code
$code = htmlspecialchars( $_GET["code"] );
/* HTML to put Code extracted using php into OneAll icon */
echo do_shortcode( '[oa_social_login code="'. $code . '"]' );
echo $code;
} else {
return oa_social_login_render_login_form ( 'shortcode' );
}
}
add_shortcode( 'social_login_callback_add_code', 'social_login_callback_add_code' );
Thank you Frederic for making the code to put in line 430!
How do you set that general redirect (for users not using OneAll)?
You can always look into the filter for registration redirect, to inspect and preserve the signup code.