So it looks like there is some page redirecting going on in the post updating process, hence why I can’t even access a $GLOBALS
variable. The only alternative I found to use was to use a session variable. Something like:
add_filter( 'pre_insert_term', 'pre_insert_term_action', 10, 2 );
add_action( 'admin_notices', 'show_example_error' );
function pre_insert_term_action( $term, $taxonomy ) {
if ( MY CONDITION THAT WARRANTS A WARNING NOTICE IS TRUE ) {
if ( session_id() === '' || ! isset($_SESSION) ) {
session_start();
}
$_SESSION['show_my_error_message'] = true;
return new WP_Error( 'code', 'message' );
}
return $term;
}
function show_example_error() {
if ( session_id() === '' || ! isset($_SESSION) ) {
session_start();
}
if ( isset($_SESSION['show_my_error_message']) ) {
?>
<div class="error">
<p>My example warning message.</p>
</div>
<?php
unset($_SESSION['show_my_error_message']);
}
}