I am trying to send out e-mail, SMS and IM notifications to group members of this WordPress website, whenever a WordPress page in their user group has been published/updated.
I figured using the action hook 'save_post'
would be the best solution. However, I ran into some annoying factors along the way, and believe I have found a fix for them.
One of the annoying factors was every time the page was updated, it would perform the action twice. So I used the fix proposed here and it seems to have corrected the double saving issue. If you have a better solution to the double saving issue, I would be glad to read about it.
Now, the issue I am facing is I don't know exactly how to properly use the filter hook 'post_updated_messages'
in coherence with action hook 'save_post'
. When I place the reference to add_filter('post_updated_messages', array(&$this, 'message'));
in the class constructor, it displays the updated message when I have only just arrived on the edit screen and haven't even clicked the update button yet.
After talking to @rarst in chat, he informed me that the 'post_updated_messages'
filter was referenced as 'place' and not as 'event' which gave me the idea of moving the reference to add_filter('post_updated_messages', array(&$this, 'message'));
to $this->save_post();
.
After moving the filter to $this->save_post();
, now I don't see the custom updated message displayed at all. I just see the typical post updated message. However, the group notification method still fires.
Where is the best place to make the filter reference. Or if this situation does not require this particular hook, what hook should be used, and where should it be placed?
I tagged this as related to plugin development, even though it's just a class file included by the functions.php file of this particular active WordPress theme.
Here is a rough idea of what I have:
<?php
if(!class_exists('tester_class')){
class tester_class{
/**
* Initiate!
*
* @return void
**/
public function __construct() {
add_action('save_post', array(&$this, 'save_post'));
}
/**
* Display update message
*
* Outputs a message using post_updated_messages, after the WP save_post action
*
* @return void
**/
public function message(){
_e('<div class="updated"><p><strong>Post updated & Notified all group members!</strong></p></div>');
}
/**
* Hooks the WP save_post action
*
* Perform class call after post is saved.
*
* @return void
**/
public function save_post(){
global $flag;
if($flag == 0){
$this->send_group_notifications();
add_filter('post_updated_messages', array(&$this, 'message'));
}
$flag = 1;
}
/**
* Notifies group members
*
* Sends email, SMS, and IM notifications to all group members.
*
* @return void
**/
public function send_group_notifications(){
// example...
}
}// EoF tester_class class
// Initiate tester_class class
$tester_class = new tester_class();
}// EoF tester_class class_exists
?>