I am hooking into the profile_update event in order to perform an action to member profiles when they are saved from the backend. After the event and my code is triggered Wordpress redirects the page back to itself.

I think this is why my notices are not showing up in the backend. Is there a way to tell it to show up only on the new page view?

An abbreviated version of my code:

function SITE_profile_update_notice() {
    echo '<div class="error notice"><p>Good Job!</p></div>';

function SITE_profile_update( $user_id, $old_user_data ) {
    // ... 
    add_action( 'admin_notices', 'SITE_profile_update_notice' );

add_action( 'profile_update', 'SITE_profile_update', 10, 2 );
  • Does your code modify profile data and/or cause the redirect itself? – bosco Mar 23 '17 at 22:46

You should use set_transient this is stored and will show up after the page reloads as it is like cookies on the server side.

function SITE_profile_update_notice() {
// Add this to your code where you want to the transient to fire  after function
set_transient( 'fx-admin-notice-panel', true, 5 );

/* Add admin notice */
add_action( 'admin_notices', 'fx_admin_notice_example_notice' );

/** Admin Notice on Activation. @since 0.1.0 */
function fx_admin_notice_example_notice(){

    /* Check transient, if available display notice */
    if( get_transient( 'fx-admin-notice-panel' ) ){
        <div class="updated notice is-dismissible">
            <div class="notice"><p>Good Job!</p></div>
        /* Delete transient, only display this notice once. */
        delete_transient( 'fx-admin-notice-panel' );

This page might be perfect for your needs http://revelationconcept.com/wordpress-send-admin-notification-user-updates-profile/

  • 1
    If this is a transient, then could there be possible collision if there are more then one admin logged into the backend? – Louis W Mar 24 '17 at 5:28
  • 2
    A race/collision is absolutely likely. To prevent that, you can include the current user_id in the name of the transient. Something like this: 'fx-admin-notice-panel-' . get_current_user_id() You could also set it as a meta value in the users profile that you write, read, and delete as you set and display the error. – Michael Khalili May 16 '18 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.