I’m trying to fire an admin notice from within a pre_insert_term
filter (have also tried it as an action). Example:
add_filter( 'pre_insert_term', 'pre_insert_term_action', 10, 2 );
function pre_insert_term_action( $term, $taxonomy ) {
add_action( 'admin_notices', 'show_example_error' );
return $term;
}
function show_example_error() { ?>
<div class="error">
<p>My example warning message.</p>
</div>
<?php }
So I add a tag in my post and hit the Update button, but it does not show me the admin notice as expected. If I put die()
calls within both functions, it is showing me that the functions are firing as expected, first pre_insert_term_action()
above, then show_example_error()
.
When I add my admin_notices
action outside of the pre_insert_term_action()
function scope, the admin notice does display. So if the functions are firing in the expected order, why is my admin notice not displaying if the action is added in the first firing function?
There’s an accepted answer in this related question suggesting to use add_settings_error()
but that didn’t do anything that I can visibly see.
I also find it weird that if I define a $GLOBALS
variable in my pre_insert_term_action()
function, it doesn’t return a value when I call it in show_example_error()
.