-
-
Save tommcfarlin/ab83b2bc517f9a555e52 to your computer and use it in GitHub Desktop.
[WordPress] Display a native WordPress error message using add_settings_error.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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