Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[WordPress] Display a native WordPress error message using add_settings_error.
<?php
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
add_settings_error(
'invalid-email',
'',
'You must define a value in the meta box.',
'error'
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.