Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
coding-topic
Newbie editing: sp_email_notifications
Avatar
Roy Costa
Member
sp_UserOfflineSmall Offline
May 11, 2013 - 7:18 pm

I imagine it is sp_email_notifications that sends the email to admins for notification of new posts/replies?  I surmized this from sp_api_class_post.  How can I edit that sp_email function - I want to lay out the elements of the email a little differently.

Thanks!

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
May 11, 2013 - 7:52 pm

dont edit the core code function... use the hooks on it to adjust as you want...

if you look at the code, you will see some apply_filters() calls...  you can hook into those to change stuff without editing...  are you familiar with how wp api works?  if not, see:  http://codex.wordpress.org/Plugin_API

those are filters... so you can change the data... so for example, to change the subject, do something like:

add_filter('sph_email_subject', 'my_email_subject', 10, 2);
function my_email_subject($subject, $newpost) {
    # do what you want to $subject
    return $subject;
}

same for content, but use the sph_admin_email filter...  the $newpost array passed in contains all the new post info that was just created.. ie topic name, forum, etc...

Avatar
Roy Costa
Member
sp_UserOfflineSmall Offline
May 12, 2013 - 1:41 am

Thanks - I think I'm slightly more novice than you might be hoping... is there a way to take the standard email "template" (from, to, subject, post, link, etc.) and copy it to version 2 and edit that, and then refer to the new layout?

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
May 12, 2013 - 2:26 am

there are no 'templates' for emails... its a format defined in the code... but we offer filters to customize...

perhaps if you tell us what you want to do, we can offer more concrete suggestions...

Avatar
Roy Costa
Member
sp_UserOfflineSmall Offline
May 12, 2013 - 2:21 pm

Thanks - I'm hoping for an email notification that would go to the admin (and I'm using autoforward to send to other select people) in the following format:

[Full Name, in bold if possible] has posted the following in [Forum, in bold]:

[maybe a horizontal line if possible]

[Subject, in bold]

[Message]

[maybe a horizontal line if possible]

[Link to post or reply]

Thanks!!!

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
May 12, 2013 - 6:54 pm

Well Steve gave you the basic code in post 2 above - only for the email body you would need to swap the subject filter for the content filter (sph_admin_email).

where he has out the 'do what you want...' comment is where you can change the text. In your case you would want to construct your whole email message. And the data you need is available in the $newpost array. if you take a look at the original code you want to replace you should easily see how it can be done.

There is one problem though. You want to use horizontal lines and bold text. Yet by default, WordPress only send emails in plain text which excludes the use of html tags. There is more needed to be done within WordPress to get it to send HTML emails which I believe is covered in the WP codex. I will try and find the references...

Here they are: http://codex.wordpress.org/Fun.....ce/wp_mail - this explains how to switch to using html emails.

andy-signature.png
YELLOW
SWORDFISH
Avatar
Roy Costa
Member
sp_UserOfflineSmall Offline
May 12, 2013 - 9:03 pm

This might be beyond my skills - I have generally been able to read code that's "already" there and modify it as needed.  Where do I find the apply_filters()?  In which file?

Avatar
Roy Costa
Member
sp_UserOfflineSmall Offline
May 12, 2013 - 11:54 pm

Let me even suggest a simpler request:

I'm okay with the current layout, except as follows:

1) Would like to remove "New forum post on your site: [NAME of SITE]"

2) The "FROM" line is fine, but can I remove Poster IP?

3) Can I move the url link to below the Post?

4) Can we remove the word "Post:"

i.e., it would be cool if it could feel more like a regular email.

If it means modifying core files (and let's say that's easy to do) - I can just make the same modifications when I upgrade in the future.

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
May 13, 2013 - 7:32 am

It would be a total waste to change the core when you can use the filter, achieve the same thing and keep it safe from updates. and you do not need to knpw about the apply_filter() function as Steve already outlined what you need to do above. But here it is again with the proper filter name:

add_filter('sph_admin_email', 'my_admin_email', 10, 2);
function my_admin_email($content, $newpost) {
    # do what you want to $content
    # change it or even replace it
    return $content;
}

if you paste that into your spFuntions.php file in your SP theme (templates folder) then replace those two commented out lines in the middle with your preferred layout and text. Take the original from core, change it and add it here. Use the $content variable to build up your replacement and then return it as shown at the end.

This is virtually the same as editing the core only safe from updates.

As always we recommend that you create your own SP theme so that any customisation is not lost during a future update. (http://codex.simple-press.com/.....g-a-theme/)

andy-signature.png
YELLOW
SWORDFISH
Avatar
Roy Costa
Member
sp_UserOfflineSmall Offline
May 19, 2013 - 7:23 am

Thanks - finally had time to look into this and will try it out.

Can I ask how to change the breadcrumbs (e.g., the stacked theme which I've copied into my own theme) so that they go across like in this forum, instead of being stacked up and down with indentation?  Thanks.

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 620
Members: 17365
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10128
Posts: 79626