Support Forum

Changing Unsubscribe url in Topic Notification Email

DE Derek Ellerman
Derek Ellerman
Member

Hi –

I’d like to change the unsubscribe url given by default at the bottom of notification emails.  The current default one isn’t working for me as it doesn’t properly insert their username into the url, triggering a redirect to another page.  Is there a filter I can add to my functions.php file to modify this url?  

The current line says: ‘To unsubscribe, please visit your profile: http://everydayfeminism.com/forum/profile/?ptab=subscriptions&pmenu=topic-subscriptions

Thanks!

Derek

11 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

It should work OK if they are still logged in to your site or still have an active cookie. If not then that login step is still going to be necessary. The normal SP profile URLs do not, in normal use, actually pass the user name or ID.

The nearest filter available would be ‘sph_subscriptions_notification_email’ which passes in 3 parameters. First is the email message text, next the post details array as a second parameter. The third parameter is the users ID.

DE Derek Ellerman
Derek Ellerman
Member

Great – I’ll give it a shot – thanks so much!

Derek

DH Dave Hughes
Dave Hughes
Member

The unsubscribe URL currently links to “…profile/?ptab=subscriptions&pmenu=topic-subscriptions”. I would like to change this to “profile/?ptab=subscriptions&pmenu=forum-subscriptions” to make it easier for my members to unsubscribe from a forum since we are primarily using forum subscriptions not topic subscriptions. Is this possible?

 

MP Mr Papa
Mr Papa
Member

you would need to hook into the message prior to it being sent and do a php str_replace on the url with the updated on…

the filter to use would be:  sph_subscriptions_notification

do you know how wp filters work?

DH Dave Hughes
Dave Hughes
Member

No, I am not familiar with wp filters. Can you provide more specific instructions or refer to a tutorial on how to do this.

 

MP Mr Papa
Mr Papa
Member

here is wp codex entry:  http://codex.wordpress.org/Plugin_API

so something like:

add_filter(‘sph_subscriptions_notification’, ‘my_url_changer’, 10, 2);
function my_url_changer($msg, $newpost) {
    $msg = str_replace(‘old_url’, ‘new_url’, $msg);
    return $msg;
}

of course, untested and you have to put in the original url and new url…

DH Dave Hughes
Dave Hughes
Member

I have studied the WP codex page you referenced. I think I understand the filter concept now and the code you suggested. The only thing I am not sure of is where exactly I should insert this code. Does it go into one of the existing php files, or do I need to create a child theme and put this into a new functions.php file?

I have been reading about child themes recently and I understand this is the best way to make modifications of WP code so changes are not lost during updates. This will be my first attempt at doing code modification so I really appreciate any extra assistance you can provide.

 

BR Brandon
Brandon
Member

If you are running a custom Simple:Press theme you can put it in the spFunctions.php file that is in the theme’s /template folder.

 

DH Dave Hughes
Dave Hughes
Member

I wasn’t able to get to this for a while, but I finally got chance to try it. I was originally using the default theme, but after reading how to create a theme in the SP codex, I copied it to a new custom theme and added the code suggested by Mr. Papa in the spFunctions.php file as suggested by Brandon. It worked perfectly. The unsubscribe link in the emails now takes the user to the Forum Subscriptions pane of their profile instead of the Topic Subscriptions pane.

Thanks again for all the help you guys provide. I have really enjoyed working with Simple:Press and I have learned a lot about the inner workings of WordPress in the process.