Does WordPress have a built in message function for presenting notifications to users?

Does WordPress have something similar to Drupal’s drupal_set_message function? I want to notify the user of something and was hoping there was a built in API call to do this.

Solutions Collecting From Web of "Does WordPress have a built in message function for presenting notifications to users?"

Here’s an idea: use the save_post hook to set a session containing the message you want to show the user and then redirect to the home page. In the home page template, check for the presence of that session and show the message to the user.

Something like this:

functions.php:

add_action( 'save_post', 'wpse60249_save_post' );

function wpse60249_save_post( $post_id ) {
    session_start();
    $_SESSION[ 'message' ] = __( 'Your text here...' );
}

index.php (or appropriate template):

if ( isset( $_SESSION[ 'message' ] ) :
    echo $_SESSION[ 'message' ];
    unset( $_SESSION[ 'message' ] );
endif;

Edit 10/21/2012

When I wrote this answer, I did not know that WordPress resets the $_SESSION variable but I learned that a couple of weeks ago while working on a project for a client. Thanks for the reminder about this question, @kaiser! Here is updated code using transients instead:

functions.php:

add_action( 'save_post', 'wpse60249_save_post' );

function wpse60249_save_post( $post_id ) {
    session_start();
    set_transient( 'temporary_message', __( 'Your text here...' ), 60*60*12 );
}

index.php (or appropriate template):

if ( false !== ( $temp_message = get_transient( 'temporary_message' ) ) :
    echo $temp_message;
    delete_transient( 'temporary_message' );
endif;

There’s an update and an error message, that you can use on the admin_notices hook.

Test Plugin

/* Plugin Name: Admin Notice w test message */
function wpse60244_custom_admin_notice()
{
    return print '<div id="message" class="updated fade"><p><strong>Hi!</strong> Look at me! In theory I should even fade out after a short time span!</p></div>';
}
add_action( 'admin_notices', 'wpse60244_custom_admin_notice' );

You can throw this in your plugins folder and give it a test.

Sidenotes

You could – in theory also use the admin_head hook to trigger the adding of the action. If you only need it on specific admin UI screens/pages, then check for global $taxnow, $pagenow; or use the admin_head-{$hook_suffix} hook.