Forked from benheu/wysija_get_subscription_link
Last active
September 19, 2018 21:18
-
-
Save RafaelFunchal/2e3c34f51934bc985830 to your computer and use it in GitHub Desktop.
Shows the link of the profile page for logged in users and let them edit their subscription
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is a sample function showing how to get a link toward the "Manage your subscriptions page" in Wysija (http://wordpress.org/plugins/wysija-newsletters/description/) | |
* You'll need to call that function at a moment where Wysija's classes are already loaded otherwise it won't work | |
* @return subscription link for the current logged in WordPress' user | |
*/ | |
function wysija_get_subscriptions_edit_link(){ | |
// wysija classes ar enot loaded so we can't use that function | |
if (!class_exists('WYSIJA')){ | |
return; | |
} | |
// let's get the current WordPress user ID | |
$model_user = WYSIJA::get('user','model',false,'wysija-newsletters',false); | |
$model_user ->getFormat=OBJECT; | |
$wpuser_id = WYSIJA::wp_get_userdata('ID'); | |
// there is no logged in WordPress user | |
if (empty($wpuser_id)){ | |
return; | |
} | |
// let's try to get the corresponding Wysija's subscriber to that WordPress' user ID | |
$user_object = $model_user ->getOne(false,array('wpuser_id'=>$wpuser_id)); | |
if (empty($user_object)){ | |
return; | |
} | |
// we return the subscription link for that user | |
return $model_user ->getConfirmLink($user_object,'subscriptions',false,true); | |
} | |
/** | |
* You have to insert the code below in your front end to display the link | |
*/ | |
<a href="<?php echo wysija_get_subscriptions_edit_link(); ?>">Manage your subscription or the text you wish.</a> | |
/** | |
* Or create a shortcode, this way you will be able to use the shortcode [mailpoet_subscription_link] | |
* in your pages and posts | |
*/ | |
add_shortcode( 'mailpoet_subscription_link', 'wysija_get_subscriptions_edit_link' ); |
@nigel7119 , probably because it is an old code which has not been tested with those WordPress versions. But you can always reach out to MailPoet support and ask them for help.
@davidzack , no. The purpose of this code is just to display a link, not the form.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a way to get this shortcode to render the actual form, rather than link to a new page with the form?