Generating a Registration link

When someone pays with clickbank, it generates them a registration link that is valid.
when someone pays with Stripe it does it too.

How can I generate an approved link with PHP in WP upon a webhook hitting the site?
is there a code I can run to generate a link?

Hi Richard.

Look here: s2member/src/includes/classes/register-access.inc.php

:slight_smile:

I see it.

I see in there, this:

"
* Generates Registration Access Links.
*
* @package s2Member\Registrations
* @since 3.5
*
* @param string $subscr_gateway Payment Gateway associated with a Customer.
* @param string $subscr_id Unique Subscr. ID associated with Payment Gateway; associated with a Customer.
* @param string $custom Custom String value (as supplied in Shortcode); must start with installation domain name.
* @param int|string $item_number An s2Member-generated item_number ( i.e., 1 for Level 1, or level|ccaps|fixed-term, or sp|ids|expiration ).
* @param bool $shrink Optional. Defaults to true. If false, the raw registration link will NOT be reduced in size through the tinyURL API.
*
* @return string|bool A Registration Access Link on success, else false on failure.
*/"

so how do I call it from php?
to @return string|bool A Registration Access Link on success, else false on failure.?

if I have this data:$subscr_gateway = “thrivecart”;
$subscr_id = order id from thrivecart.
$custom = hmm… I have to figure out how to get this one… I’ll look into it, assume I have it…
$item_number = the level
$shrink = false

so if I have those strings, how would I call this to return that link?

is this how to do it:

$linkGenerated = c_ws_plugin__s2member_register_access::register_link_gen ("thrivecart", $_UniqueOrderId, $_SERVER["HTTP_HOST"], "???", false);

Like that, but with the ??? being the level…

If a Multi-site wp… what would the “level” be? I don’t know how the level would be, if they are signing up to a site in a multi site… they get registered to the main site, then get access to the website they mainly signed up at too right? so the first one setup, PLUS the one they purchased?
or just the one they purchased, and that puts them in the main one plus the one?
I’m Not sure. been many years since I’ve used a multi-site… so I cannot remember how they worked.

I tested that line of code and it works… but the link it generates says his instantly:
Your Link Expired:
Please contact Support if you need assistance.

I am in an incognito window…
why does it not work?

not only that but look how long the key is for the link:

https://mydomain.com/?s2member_register=ZGVmNTAyMDAyOWMwNjY3Njc2MmIyMTM0ZjNhNmYyZjFjMjc0NjFlNWE4NzU2MWU3NWFmMTU2ZjQxMGFhM2NlZjUxNGQxODFlNGZmMGZkMTM5NzU5OTdmZWE3MjQ4MWU3NDNjZDg1YmUwOThlZWFkYzg1M2RkNjllZThkMzM4MzQ2OTQ3YmE4MWNiZTFmNTllZjMxMTM2N2JiZWFiMTY0ZGY3ZTZkMTk3NjQ4NzUzNGYzOGQ3M2JkZDM5Mzc0NjRkYzc3YTZkZWNhMDUwMzljNjBkYTVkZjA5NzhmOTUzNTUyMTM4NWM0ZjdkYjZiOWY5ODYzOWE4ZTQwY2E2MzUwMGI0YzRhMzcyNmZlMTFhZDkxYzIxYzEwODM3OTY3MWNhZjM0NDJjMzhmZGJhZjJmODFmZmVlYWEzYzUyNWMxY2M5ZGU0NDIzYjJjNjVhYTVkNTJlZWRhY2RkNDIyMGNkNWFjNmQ0NmEzZDgzZDcyYjhiNjhhMzQwZDYwYjc4MmY2ZWU2MThjNGU4OWViNjY4OWU0ZWNlZTdmOWQ4MDljZDIyMWFhNmEyODM0NDNiYTE4MmFhNzBjMjRiZTU4MDhmYTQ3Y2NiOGIwMGFhMTUwY2FmNTM4MDhiNg

That is a HUGE registration link… is it doing it right?

Yep, that’s why it gets shortened. WP Admin > s2Member > General > URL Shortening :slight_smile:

@clavaque So why does it say the link is expired the moment it creates it? How do I get it where it is not expired?

Does it have something to do with what is in here:

$linkGenerated = c_ws_plugin__s2member_register_access::register_link_gen ("thrivecart", $_UniqueOrderId, $_SERVER["HTTP_HOST"], "???", false);

that code? if ??? has “subscriber” in it…

and if on a multi-site does this: $_SERVER[“HTTP_HOST”] - put the domain where the website is on for sure? or do I need to hardcode it to each website?

That 4th argument is the item number:

public static function register_link_gen($subscr_gateway = '', $subscr_id = '', $custom = '', $item_number = '', $shrink = TRUE)

If you search for that, you’ll find this line in s2member/src/includes/menu-pages/menu-pages-s.js

var levelCcapsPer = (fixedTerm && !fixedTerm.match(/L$/)) ? level+':'+cCaps+':'+fixedTerm : level+':'+cCaps;

So if you’re selling level 1 subscription, with ccap “video”, it’d be: 1:video

:slight_smile:

Nice. Okay @clavaque, so if the site is a multi-site wordpress, and has, say 5 sites…

if someone buys the account for website1, then registers, then buys website2… does the registration link, still work since they already have an account on one of the websites in the multisite?

or is there a special link I need to create?
Since I already have their info from the transaction, including their email address, is it best to look for their account via:

get_user_by(“email”, $emailpassed) ???
then if it finds an account, do something different to add the site they purchased an account for to their membership access?

I haven’t tried it, but am pretty sure that the user creation would include the blog he’s at. Jason was aware of multisite and, although this link is created by s2Member, the registration itself is done through WordPress routines.

I guess my best advice would be that you do tests to confirm the actual behavior. Create a user on one site and then another with the same email address, with the signup link and with normal registration, and then look them up in the database.