Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
[WordPress] Display a native WordPress error message using add_settings_error.
add_action( 'save_post', 'acme_save_post' );
function acme_save_post() {
// Verify the user has permission to save. Code consolidated for readability.
if ( acme_user_can_save( $post_id, 'acme_save_meta_data_nonce' ) ) {
// Make sure the meta box data isn't empty
if ( isset( $_POST['acme-input-field'] ) && 0 === strlen( trim( $_POST['acme-input-field'] ) ) ) {
// Define the settings error to display
'You must define a value in the meta box.',
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment