Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

Updated:

First, you will need to return a bool value on your notifications method so we can reliably set a marker for the message method. Then, you will need to set a $_POST array element to pass on to the redirection filter.

public function save_post($post_id){
    //Add a $_POST key if you syndicated successfully
    if($this->send_group_notifications()) //return true from your notification method
        $_POST['syndicated'] = true;
}

The following filter works from your functions.php file. I couldn't get it to work properly from a plugin file. Basically, what's happening here is we sniff out the $_POST array element you set in the save_post action and see if we add a query string variable to the redirect.

add_filter('redirect_post_location', 'update_post_redirect');
function update_post_redirect($location){
    $syndicated = isset($_POST['syndicated']) ? $_POST['syndicated'] : 0;
    if($syndicated == true)
        $location .= '&syndicated=1';
    return $location;
}

Then finally, we sniff out the $_GET variable so we can determine if a message needs to be displayed.

public function message($messages){
    $syndicated = isset($_GET['syndicated']);
    if($syndicated)
         //Do something with the messages array here.
    return $messages;
}

Check out this post for a nice example of how to use this filter: Set custom messages for post update/saveSet custom messages for post update/save

Hope this helps you out!

Updated:

First, you will need to return a bool value on your notifications method so we can reliably set a marker for the message method. Then, you will need to set a $_POST array element to pass on to the redirection filter.

public function save_post($post_id){
    //Add a $_POST key if you syndicated successfully
    if($this->send_group_notifications()) //return true from your notification method
        $_POST['syndicated'] = true;
}

The following filter works from your functions.php file. I couldn't get it to work properly from a plugin file. Basically, what's happening here is we sniff out the $_POST array element you set in the save_post action and see if we add a query string variable to the redirect.

add_filter('redirect_post_location', 'update_post_redirect');
function update_post_redirect($location){
    $syndicated = isset($_POST['syndicated']) ? $_POST['syndicated'] : 0;
    if($syndicated == true)
        $location .= '&syndicated=1';
    return $location;
}

Then finally, we sniff out the $_GET variable so we can determine if a message needs to be displayed.

public function message($messages){
    $syndicated = isset($_GET['syndicated']);
    if($syndicated)
         //Do something with the messages array here.
    return $messages;
}

Check out this post for a nice example of how to use this filter: Set custom messages for post update/save

Hope this helps you out!

Updated:

First, you will need to return a bool value on your notifications method so we can reliably set a marker for the message method. Then, you will need to set a $_POST array element to pass on to the redirection filter.

public function save_post($post_id){
    //Add a $_POST key if you syndicated successfully
    if($this->send_group_notifications()) //return true from your notification method
        $_POST['syndicated'] = true;
}

The following filter works from your functions.php file. I couldn't get it to work properly from a plugin file. Basically, what's happening here is we sniff out the $_POST array element you set in the save_post action and see if we add a query string variable to the redirect.

add_filter('redirect_post_location', 'update_post_redirect');
function update_post_redirect($location){
    $syndicated = isset($_POST['syndicated']) ? $_POST['syndicated'] : 0;
    if($syndicated == true)
        $location .= '&syndicated=1';
    return $location;
}

Then finally, we sniff out the $_GET variable so we can determine if a message needs to be displayed.

public function message($messages){
    $syndicated = isset($_GET['syndicated']);
    if($syndicated)
         //Do something with the messages array here.
    return $messages;
}

Check out this post for a nice example of how to use this filter: Set custom messages for post update/save

Hope this helps you out!

added 2 characters in body
Source Link
Brian Fegter
  • 10k
  • 1
  • 41
  • 60

Updated:

First, you will need to return a bool value on your notifications method so we can reliably set a marker for the message method. Then, you will need to set a $_POST array element to pass on to the redirection filter.

public function save_post($post_id){
    //Add a $_POST key if you syndicated successfully
    if($this->send_group_notifications()) //return true from your notification method
        $_POST['syndicated'] = true;
}

The following filter works from your functions.php file. I couldn't get it to work properly from a plugin file. Basically, what's happening here is we sniff out the $_POST array element you set in the save_post action and see if we add a query string variable to the redirect.

add_filter('redirect_post_location', 'update_post_redirect');
function update_post_redirect($location){
    $syndicated = isset($_POST['syndicated']) ? $_POST['syndicated'] : 0;
    if($syndicated == true)
        $location .= '&syndicated=1';
    return $location;
}

Then finally, we sniff out the $_GET variable so we can determine if a message needs to be displayed.

public function message($messages){
    $synicated$syndicated = isset($_GET['syndicated]$_GET['syndicated']);
    if($syndicated)
         //Do something with the messages array here.
    return $messages;
}

Check out this post for a nice example of how to use this filter: Set custom messages for post update/save

Hope this helps you out!

Updated:

First, you will need to return a bool value on your notifications method so we can reliably set a marker for the message method. Then, you will need to set a $_POST array element to pass on to the redirection filter.

public function save_post($post_id){
    //Add a $_POST key if you syndicated successfully
    if($this->send_group_notifications()) //return true from your notification method
        $_POST['syndicated'] = true;
}

The following filter works from your functions.php file. I couldn't get it to work properly from a plugin file. Basically, what's happening here is we sniff out the $_POST array element you set in the save_post action and see if we add a query string variable to the redirect.

add_filter('redirect_post_location', 'update_post_redirect');
function update_post_redirect($location){
    $syndicated = isset($_POST['syndicated']) ? $_POST['syndicated'] : 0;
    if($syndicated == true)
        $location .= '&syndicated=1';
    return $location;
}

Then finally, we sniff out the $_GET variable so we can determine if a message needs to be displayed.

public function message($messages){
    $synicated = isset($_GET['syndicated]);
    if($syndicated)
         //Do something with the messages array here.
    return $messages;
}

Check out this post for a nice example of how to use this filter: Set custom messages for post update/save

Hope this helps you out!

Updated:

First, you will need to return a bool value on your notifications method so we can reliably set a marker for the message method. Then, you will need to set a $_POST array element to pass on to the redirection filter.

public function save_post($post_id){
    //Add a $_POST key if you syndicated successfully
    if($this->send_group_notifications()) //return true from your notification method
        $_POST['syndicated'] = true;
}

The following filter works from your functions.php file. I couldn't get it to work properly from a plugin file. Basically, what's happening here is we sniff out the $_POST array element you set in the save_post action and see if we add a query string variable to the redirect.

add_filter('redirect_post_location', 'update_post_redirect');
function update_post_redirect($location){
    $syndicated = isset($_POST['syndicated']) ? $_POST['syndicated'] : 0;
    if($syndicated == true)
        $location .= '&syndicated=1';
    return $location;
}

Then finally, we sniff out the $_GET variable so we can determine if a message needs to be displayed.

public function message($messages){
    $syndicated = isset($_GET['syndicated']);
    if($syndicated)
         //Do something with the messages array here.
    return $messages;
}

Check out this post for a nice example of how to use this filter: Set custom messages for post update/save

Hope this helps you out!

Bounty Ended with 50 reputation awarded by Michael Ecklund
Updated to a better approach
Source Link
Brian Fegter
  • 10k
  • 1
  • 41
  • 60

You can't add a filter within the save_post action because when the action is completed, a redirect is fired to clear $_POST data. After the redirect, the post edit page will be completely ignorant of the filter you're trying to set.

This is how I would approach what you're trying to accomplish using the Transients API.Updated:

First, you will need to return a bool value on your notifications method so we can reliably set a marker for the message method. Depending on your server setup (whether you use object cache)Then, a transient is either stored as an option or asyou will need to set a memcache object. You can think of transients as expiring options$_POST array element to pass on to the redirection filter.

public function save_post($post_id){  //make sure to include the $post_id param
    global $flag;
//Add a $_POST key if($flag == 0)
  you syndicated successfully
    if($this->send_group_notifications()) //return true from your notification method
        $_POST['syndicated'] = true;
}

The following filter works from your functions.php file. I couldn't get it to work properly from a plugin file. Basically, what's happening here is we sniff out the $_POST array element you set in the save_post action and see if we add a query string variable to the redirect.

add_filter('redirect_post_location', 'update_post_redirect');
function set_transientupdate_post_redirect("group_notification_$post_id",$location){
 true, 15  $syndicated = isset($_POST['syndicated']); //Expires? after$_POST['syndicated'] 15: seconds0;
    $flagif($syndicated == true)
        $location .= 1;'&syndicated=1';
    return $location;
}

You might need to play with the expiration time depending on how frequently you update your posts and how much processing time it takes to save a post

Within the message methodThen finally, you will then pullwe sniff out the transient that was just set and decide whether or not to display your admin$_GET variable so we can determine if a message needs to be displayed.

public function message($messages){
    global $post;
    #Check for group notifications on this post
    $updated$synicated = get_transientisset("group_notification_{$post->ID}"$_GET['syndicated]);
    if($updated$syndicated)
         //Do something with the messages array here.
    return $messages;
}

Note: You will still need to place your 'post_updated_message' filter with all of your other class hooks. Check out this post for a nice example of how to use this filter: Set custom messages for post update/save

Hope this helps you out!

You can't add a filter within the save_post action because when the action is completed, a redirect is fired to clear $_POST data. After the redirect, the post edit page will be completely ignorant of the filter you're trying to set.

This is how I would approach what you're trying to accomplish using the Transients API.

First, you will need to return a bool value on your notifications method so we can reliably set a marker for the message method. Depending on your server setup (whether you use object cache), a transient is either stored as an option or as a memcache object. You can think of transients as expiring options.

public function save_post($post_id){  //make sure to include the $post_id param
    global $flag;
    if($flag == 0)
        if($this->send_group_notifications()) //return true from your notification method
            set_transient("group_notification_$post_id", true, 15); //Expires after 15 seconds
    $flag = 1;
}

You might need to play with the expiration time depending on how frequently you update your posts and how much processing time it takes to save a post

Within the message method, you will then pull the transient that was just set and decide whether or not to display your admin message.

public function message($messages){
    global $post;
    #Check for group notifications on this post
    $updated = get_transient("group_notification_{$post->ID}");
    if($updated)
         //Do something with the messages array here.
    return $messages;
}

Note: You will still need to place your 'post_updated_message' filter with all of your other class hooks. Check out this post for a nice example of how to use this filter: Set custom messages for post update/save

Hope this helps you out!

Updated:

First, you will need to return a bool value on your notifications method so we can reliably set a marker for the message method. Then, you will need to set a $_POST array element to pass on to the redirection filter.

public function save_post($post_id){
    //Add a $_POST key if you syndicated successfully
    if($this->send_group_notifications()) //return true from your notification method
        $_POST['syndicated'] = true;
}

The following filter works from your functions.php file. I couldn't get it to work properly from a plugin file. Basically, what's happening here is we sniff out the $_POST array element you set in the save_post action and see if we add a query string variable to the redirect.

add_filter('redirect_post_location', 'update_post_redirect');
function update_post_redirect($location){
    $syndicated = isset($_POST['syndicated']) ? $_POST['syndicated'] : 0;
    if($syndicated == true)
        $location .= '&syndicated=1';
    return $location;
}

Then finally, we sniff out the $_GET variable so we can determine if a message needs to be displayed.

public function message($messages){
    $synicated = isset($_GET['syndicated]);
    if($syndicated)
         //Do something with the messages array here.
    return $messages;
}

Check out this post for a nice example of how to use this filter: Set custom messages for post update/save

Hope this helps you out!

deleted 20 characters in body; added 158 characters in body
Source Link
Brian Fegter
  • 10k
  • 1
  • 41
  • 60
Loading
Source Link
Brian Fegter
  • 10k
  • 1
  • 41
  • 60
Loading