How to hook admin notices into the save_post action hook?
-
I have the following problem. I have a method checking some input for a new or updated post. Based on that check i wanted to hook into the settings errors functionality to show different messages on update and on error.
The add_action i use is placed in function__construct():
add_action('admin_notices', array( $this, 'xyz_check_notices' ) );
the according method:
public function xyz_check_notices() { if ( $this->check_fail_constraint ) { add_settings_error( 'xyz-notices' , 'xyz-check-fail', __( 'Failed', 'xyzrequest'), 'error' ); } else { add_settings_error( 'xyz-notices', 'xyz-success', __('Worky Work', 'xyzrequest'), 'updated' ); } settings_errors( 'xyz-notices' ); }
But somehow those messages are shown on every admin page and not only post save (and not alone but alongside the standard wp update message). i also tried to place the add_action into the method called by the save_post action hook. Nothing helped. So is there a way to properly hook into the save function that only the custom message according to the check_fail_constraint is shown? Thanks r.
- The topic ‘How to hook admin notices into the save_post action hook?’ is closed to new replies.