Unable to add admin notice on plugin activation

As @MohammadLimon said I need to use the Transients API. The following code worked:

register_activation_hook( __FILE__, 'sp_subscriber_check_activation_hook' );
function sp_subscriber_check_activation_hook() {
    set_transient( 'mp-admin-notice-activation', true, 5 );
}

add_action( 'admin_notices', 'sp_subscriber_check_activation_notice' );
function sp_subscriber_check_activation_notice(){
     if( get_transient( 'mp-admin-notice-activation' ) ){
        ?>
        <div class="updated notice is-dismissible">
            <p>If you are using a caching plugin like W3TC or WP Super Cache make sure to make any pages you wish to protect an exception to the caching!</p>
        </div>
        <?php
        delete_transient( 'mp-admin-notice-activation' );
    }
}

Leave a Comment