Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fundcode_association_save_meta_box( $post_id ) {
- $err = false;
- $message = '';
- // Check if our nonce is set.
- if ( ! isset( $_POST['fundcode_post_class_nonce'] ) ) {
- return;
- }
- // Verify that the nonce is valid.
- if ( ! wp_verify_nonce( $_POST['fundcode_post_class_nonce'], basename( __FILE__ ) ) ) {
- return;
- }
- // If this is an autosave, our form has not been submitted, so we don't want to do anything.
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
- return;
- }
- // Save occasion
- if( isset( $_POST['fundcode-occasion'] ) )
- {
- if(!empty($_POST['fundcode-occasion']))
- {
- $my_data = sanitize_text_field( $_POST['fundcode-occasion'] );
- update_post_meta( $post_id, 'fundcode_occasion', $my_data );
- }
- else
- {
- $err = true;
- $message .= "Occasion can't be empty.<br />";
- update_post_meta( $post_id, 'fundcode_occasion', null );
- }
- }
- // Save association
- if( isset( $_POST['fundcode-association'] ) )
- {
- if(!empty($_POST['fundcode-association']))
- {
- $my_data = sanitize_text_field( $_POST['fundcode-association'] );
- update_post_meta( $post_id, 'fundcode_association', $my_data );
- }
- else
- {
- $err = true;
- $message .= "Association can't be empty.<br />";
- update_post_meta( $post_id, 'fundcode_association', null );
- }
- }
- if($err)
- {
- update_option('fundcode_admin_errors', $message);
- }
- else
- {
- update_option('fundcode_admin_errors', false);
- }
- }
- add_action( 'save_post', 'fundcode_association_save_meta_box', 1 );
- function fundcode_admin_notice_handler() {
- $errors = get_option('fundcode_admin_errors');
- if($errors)
- {
- echo '<div class="error"><p>' . $errors . '</p></div>';
- }
- }
- add_action( 'admin_notices', 'fundcode_admin_notice_handler' );
- // Clear any errors
- function fundcode_clear_errors() {
- update_option('fundcode_admin_errors', false);
- }
- add_action( 'admin_footer', 'fundcode_clear_errors' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement