Question

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 );
Was it helpful?

Solution

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>
        </div>
        <?php
        /* 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/

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top