A A A
Forum Scope


Match



Forum Options



Min search length: 3 characters / Max search length: 84 characters
Forum Login
Lost password?
coding-topic
sph_post_create versus sph_after_post action
RSS
Avatar
Mike Grace-Martin

6 Posts
(Offline)
1
Mar 1, 2018 - 4:00 pm
Print

I want to trigger my own custom function (that includes sending an email message) after someone posts in the forum. When I use the “sph_post_create” action as a trigger, I get one email message (like I want to), but the $spVars variable doesn’t contain the data about the post that I want. If I use the sph_after_post action, $spVars contains the data I want about the post, but then my function triggers multiple times for some reason, which I don’t want. Any idea how I can get the $spVars data I want but only have it triggered once? Thanks.

Avatar
Mike Grace-Martin

6 Posts
(Offline)
2
Mar 1, 2018 - 4:15 pm
Print

I also tried the sph_new_forum_post action, and $spVars again didn’t contain the post’s data.

Avatar
Yellow Swordfish
Glinton, England

16436 Posts
(Offline)
3
Mar 1, 2018 - 4:18 pm
Print

I would recommend the ‘sph_new_post’ action which has one argument which is the $newpost array which should have everything you need defined. And this is triggered at the post creation time after success of saving has been accomplished,

andy-signature.png
YELLOW
SWORDFISH
Avatar
Mike Grace-Martin

6 Posts
(Offline)
4
Mar 1, 2018 - 7:36 pm
Print

It took me a while to figure out how to be able to use $newpost. It turns out I had to add two more arguments (the 10 & 1) in my add_action declaration: add_action( ‘sph_new_post’, ‘my_function’, 10, 1 ) …where the 1 refers to the one argument being passed to my_function via my_function($newpost). Thanks.

Avatar
Mr Papa
Simi Valley, CA

19448 Posts
(Offline)
5
Mar 1, 2018 - 8:39 pm
Print

yes, standard wp hook format…  glad we could help…

Forum Timezone: America/New_York
All RSS Show Stats
Administrators: Blues Dancer, Simple Press, SP Community Support
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 628
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Newest Members:
Matthew Russell
Darlene Bos
Jana Jakob
Kristi Krauss
Forum Stats:
Groups: 7
Forums: 17
Topics: 10043
Posts: 79319

 

Member Stats:
Guest Posters: 606
Members: 16868
Moderators: 0
Admins: 3

Most Users Ever Online
499
Currently Online
Guest(s)
17
Currently Browsing this Page

1 Guest(s)