'', '_breadcrumb' => '' ) ); $this->save_custom_field( $data, 'baltic_save_metabox', 'baltic_metabox_nonce', $post ); } } public function save_custom_field( array $data, $nonce_action, $nonce_name, $post ) { // Verify the nonce. if ( isset( $_POST[ $nonce_name ] ) && wp_verify_nonce( sanitize_key( $_POST[ $nonce_name ] ), $nonce_action ) ) { // Don't try to save the data under autosave, ajax, or future post. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { return; } if ( defined( 'DOING_CRON' ) && DOING_CRON ) { return; } // Grab the post object. if ( null !== $deprecated ) { $post = get_post( $deprecated ); } else { $post = get_post( $post ); } // Don't save if WP is creating a revision (same as DOING_AUTOSAVE?). if ( 'revision' === get_post_type( $post ) ) { return; } // Check that the user is allowed to edit the post. if ( ! current_user_can( 'edit_post', $post->ID ) ) { return; } // Cycle through $data, insert value or delete field. foreach ( (array) $data as $field => $value ) { // Save $value, or delete if the $value is empty. if ( $value ) { update_post_meta( $post->ID, $field, $value ); } else { delete_post_meta( $post->ID, $field ); } } } } }