ID, 'meh_meh_color_pick', true );
// Set default values.
if( empty( $meh_meh_color_pick ) ) $meh_meh_color_pick = '#FFFFFF';
// Form fields.
echo '
';
}
public function save_metabox( $post_id, $post ) {
// Add nonce for security and authentication.
$nonce_name = isset( $_POST['meh_nonce'] ) ? $_POST['meh_nonce'] : '';
$nonce_action = 'meh_nonce_action';
// Check if a nonce is set.
if ( ! isset( $nonce_name ) )
return;
// Check if a nonce is valid.
if ( ! wp_verify_nonce( $nonce_name, $nonce_action ) )
return;
// Check if the user has permissions to save data.
if ( ! current_user_can( 'edit_post', $post_id ) )
return;
// Sanitize user input.
$meh_new_meh_color_pick = isset( $_POST[ 'meh_meh_color_pick' ] ) ? sanitize_text_field( $_POST[ 'meh_meh_color_pick' ] ) : '';
// Update the meta field in the database.
update_post_meta( $post_id, 'meh_meh_color_pick', $meh_new_meh_color_pick );
}
}
new Meh_Meta_Box;