post_updated_messages
Allows you to change messages displayed when a post is updated or added.
Messages such as "Post added" or "Post updated" are displayed at the top of the screen while editing a post. This hook can supplement or completely replace them.
The hook fires whenever a post creation or editing page is opened, even when nothing is updated. If message processing is expensive, attach it through current_screen after checking whether a post is being updated or added and whether it is the required post.
Usage
add_filter( 'post_updated_messages', 'wp_kama_post_updated_messages_filter' );
/**
* Function for `post_updated_messages` filter-hook.
*
* @param array[] $messages Post updated messages. For defaults see `$messages` declarations above.
*
* @return array[]
*/
function wp_kama_post_updated_messages_filter( $messages ){
// filter...
return $messages;
}
Parameters
- $messages(array)
Array of all possible messages, divided into
post,page, andattachmentsubarrays. In the English locale it looks like this:Array ( [post] => Array ( [0] => [1] => Post updated. <a href="http://example.com/foo/">View post</a> [2] => Custom field updated. [3] => Custom field deleted. [4] => Post updated. [5] => [6] => Post published. <a href="http://example.com/foo/">View post</a> [7] => Post saved. [8] => Post submitted. <a target="_blank" href="http://example.com/foo/?preview=true">Preview post</a> [9] => Post scheduled for: <strong>May 28, 2016 @ 03:20</strong>. <a target="_blank" href="http://example.com/foo/">Preview post</a> [10] => Post draft updated. <a target="_blank" href="http://example.com/foo/?preview=true">Preview post</a> ) [page] => Array ( [0] => [1] => Page updated. <a href="http://example.com/foo/">View page</a> [2] => Custom field updated. [3] => Custom field deleted. [4] => Page updated. [5] => [6] => Page published. <a href="http://example.com/foo/">View page</a> [7] => Page saved. [8] => Page submitted. <a target="_blank" href="http://example.com/foo/?preview=true">Preview page</a> [9] => Page scheduled for: <strong>May 28, 2016 @ 03:20</strong>. <a target="_blank" href="http://example.com/foo/">Preview page</a> [10] => Page draft updated. <a target="_blank" href="http://example.com/foo/?preview=true">Preview page</a> ) [attachment] => Array ( [1] => Media file updated. [2] => Media file updated. [3] => Media file updated. [4] => Media file updated. [5] => Media file updated. [6] => Media file updated. [7] => Media file updated. [8] => Media file updated. [9] => Media file updated. [10] => Media file updated. ) )
Examples
#1 Supplement the message displayed when a post is created
Publishing a post displays Post published followed by a link to the post. This example appends text to that message:
add_filter('post_updated_messages', function($messages){
$messages['post'][6] .= ' Additional message.';
return $messages;
});Changelog
| Since 3.0.0 | Introduced. |
Where the hook is called
In file: /wp-admin/edit-form-advanced.php
post_updated_messages
wp-admin/edit-form-advanced.php 212
$messages = apply_filters( 'post_updated_messages', $messages );