The problem is that when a post is saved, there’s a redirect back to the edit post page and the admin_notices action never runs. This means that any admin notice you put on any of the save post actions (save_post, transition_post_status, etc.) will be thrown away (since they’re not persistent) during that redirect.
The workaround is to save a state (user settings/user meta, post meta, transients, options) which would signal that an admin notice should be shown, and look for that state on the next request.
add_action( 'save_post', function( $post ) {
// some checks here
update_user_option( get_current_user_id(), '_my_show_notice', true );
});
add_action( 'admin_notices', function() {
if ( get_user_option( '_my_show_notice' ) ) {
delete_user_option( get_current_user_id(), '_my_show_notice' );
echo '<div class="notice notice-success"><p>Some notice</p></div>';
}
});
Hope that helps!
Related Posts:
- Objective Best Practices for Plugin Development? [closed]
- How do i best handle custom plugin page actions?
- How to create an API for my plugin?
- Is it ever okay to include inline CSS in plugins?
- Plugins in symlinked directories?
- How can I configure Docker for developing and deploying a custom theme?
- No Error Log File, no debug info
- Is the new WordPress 3.1 admin bar pluggable and how can I extend it?
- How to use PanelColorSettings in custom Gutenberg block?
- Getting a peer review for my new plugin?
- Using filters and actions for plugin API?
- Is There A Hook To Process The Content Of The Text Widget?
- How to Change the Entire WordPress Admin panel Look and Feel?
- Allowing for multiple template views on the Gallery Settings page when using the Visual Editor
- Using Primary Color in Plugin Block
- When is it appropriate to put functions on page template vs. functions.php?
- When to check if a function exists
- How to use wp_set_password in a plugin?
- How Can I setup WP CLI on Windows development machine running AMPPS?
- WP_LOCALIZE_SCRIPT doesn’t work
- Nuance in adding CPT and TAX to a submenu
- Can I differentiate between “Delete Post Permanently” and “Empty Trash” and do something for each accordingly?
- Delete a specific item menu when I deactivate my plugin
- Are we allowed to use the Allman (BSD) indent style when coding WordPress plugins and themes?
- Get the password key when using the wp_new_user_notification_email filter
- Order properties should not be accessed directly
- How to deal with equal & similar arguments for a function?
- Executing a function upon webhook calling wordpress
- Customizer: widget-synced triggers twice
- WordPress not working on localhost
- Adding functions to hooks from within a class
- how to use hook deleted_user into custom function to delete user from custom table
- Where to store the name of a custom table?
- Applying OO patterns and principles to plugin development
- WordPress is automatically linking plain text email addresses
- Is Using WordPress Supplied WYSIWYG Advisable?
- ServerSideRender and Media Object: attributes passing image data object to php renderer even though it’s not set
- Is it possible to change a term slug before being saved to the database?
- Clearing caches on plugin uninstall
- How to use a hook to override an update_post_meta call in a plugin?
- Add code inside specific wordpress standard function
- Create a free scripts and styles template within a plugin
- How can I turn a custom wordpress page into a product page?
- How can we display product price $104 on the cart while the credit card payment method is checked?
- Notice: Trying to get property ‘term_id’ of non-object
- How to Bind one post object Type with other postobject Type in Advanced Custom field [closed]
- Search: how to extend the existing search to include a custom table
- Is there documentation reference for forms in menu and setting pages?
- Show error message after exception handled
- Enqueue script globally
- How to modify files inside wp-includes directory in wordpress
- Plugin Options Array Set to Undefined
- Custom entity search and display
- How to set a cookie for logged in users to md5($user->ID . “my_secret”)?
- Plugin: database creation
- Loading Modernizr (or other JavaScript libraries) for use in a plugin
- Displaying “One Time” Notification in Plugins
- Why in this archive page that call query_posts() function show only the last 10 posts?
- Create Widget or Enable Shortcodes in Sidebar
- Logout after clicking URL link results in “headers already sent” error
- Problem with display data from get_option
- Converting core modification to a plugin
- How to use a WP_Customize_Control outside of the Customizer?
- How to replace settings in WordPress plugin from a theme
- Setting a post’s category
- Extract Information from post content (using regex?)
- Serial Number from custom table not appear in woocommerce_email_before_order_table action
- Customise Grouped Product display in Woocommerce with custom column
- Custom Endpoint – Does it possible to use PUT method with WP API Rest?
- Why won’t this submenu page show? – My First WordPress Plugin
- How to create a custom post-new.php page for plugin , no wp menu
- Want to know how to reveal a WordPress theme, considering the theme name is hidden?
- Save meta box data from selected dropdown list in bbpress reply form
- Metabox types list
- Where to save Gutenberg plugin data?
- WordPress how do I echo SUM from a column of a MySQL table by user id AND type_operation
- Rate limiting ajax requests in WordPress
- Does hooking into a plugin action / filter override the plugin’s function for that hook?
- How to prevent users from deleting their accounts?
- Hiding class namespace from plugin’s extensions
- Set widget icon in Customizer?
- Create Customization panel for Plugins not for theme
- Determine if the current page, is being edited
- WordPress delete mysql rows with string
- Add function to Dokan ajax class
- PHP includes with AJAX actions
- Custom Post Type and Functions
- Associating special meaning with user id 0
- Managing Custom Designed Content
- Theming Custom Plugin Page
- Best practice: What belongs in theme and what in plugin for large eCommerce website
- Adding class to the parent of current-post-ancestor / current-menu-parent / current-post-parent
- Dynamic banner for use on external sites
- Adding Meta box to thrid-party plugin
- How do I store a custom dataset in WordPress to best take advantage of API?
- Client Profiles
- Is Explicit Versioning a better alternative to Semantic Versioning for wordpress?
- Custom plugin not appearing
- Is there any other ways to replicating changes on live from staging without pushing from git
- Developing an IP lookup function using an API