Using WordPress admin_notices in a OOP plugin
Admin Notices are not used for this and the hook don't work at the point where you're putting it. And to trigger it selectively, we use get_option
or get_user_meta
.
For this kind of notice, we use admin classes:
if( $success ) echo '<div class="updated"><p>class .updated with paragraph</p></div>';if( $error ) echo '<div class="error"><p>class .error with paragraph</p></div>';
Here's a helper plugin to style our admin screens: WordPress Admin Styles.
Or, use the whole Settings API, which has a function add_settings_error()
to display notices, despite the name, it is used to display update
and error
messages.