The reason this doesn’t work is because there is a redirection happening after the save_post action. One way you can acheive want you want is by implementing a quick work around using query vars.
Here is a sample class to demonstrate:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | class My_Awesome_Plugin { public function __construct(){ add_action( 'save_post', array( $this, 'save_post' ) ); add_action( 'admin_notices', array( $this, 'admin_notices' ) ); } public function save_post( $post_id, $post, $update ) { // Do you stuff here // ... // Add your query var if the coordinates are not retreive correctly. add_filter( 'redirect_post_location', array( $this, 'add_notice_query_var' ), 99 ); } public function add_notice_query_var( $location ) { remove_filter( 'redirect_post_location', array( $this, 'add_notice_query_var' ), 99 ); return add_query_arg( array( 'YOUR_QUERY_VAR' => 'ID' ), $location ); } public function admin_notices() { if ( ! isset( $_GET['YOUR_QUERY_VAR'] ) ) { return; } ?> <div class="updated"> <p><?php esc_html_e( 'YOUR MESSAGE', 'text-domain' ); ?></p> </div> <?php } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.