-
-
Save RafaelFunchal/2e3c34f51934bc985830 to your computer and use it in GitHub Desktop.
<?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' ); |
Works well - thanks
Where do I paste this code?
I figured it out and thank you so much this was a life saver!!
@myrafletcher, you can paste it in your file functions.php
.
Sorry about the delayed answer, but Gist doesn't send any notification when someone adds a new comment.
Thank you, this is so useful. Don't know why this is not official function in MP? Your code is working great :)
Thats what i need, but i did not now where i have to paste this code? On functions.php i got a error!
All the best,
Pascal
@someco, I haven't tested that code with the current version of MailPoet yet, but I think you can reach their support and ask for any customization.
Is there any reason why this would not work in Wordpress 4.6? I have an odd error using s2Member Pro, if I add the link (<a href="<?php echo wysija_get_subscriptions_edit_link(); ?>">Manage your subscription or the text you wish.</a>
) to their login widget it works perfectly in 4.53 and I've had no problems but in 4.6 it screws up the page. It works fine if I place it on a page and I can use other php echo links in the widget and they seem to work fine...just this one that doesn't. s2Member Pro are telling the link should never have worked and it's not an error in the widget?
Is there a way to get this shortcode to render the actual form, rather than link to a new page with the form?
@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.
Can I say that I love you???? <3 😵 This saved my ass... :) Thanks so much. 😄