Skip to content

Instantly share code, notes, and snippets.

@alessandrotesoro
Created December 10, 2014 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alessandrotesoro/3e80fc28da4d02f4e6ce to your computer and use it in GitHub Desktop.
Save alessandrotesoro/3e80fc28da4d02f4e6ce to your computer and use it in GitHub Desktop.
WPRM Move last custom field up at the top of the booking form
class WPRM_Move_last_custom_field_up extends WPRM_Custom_Fields {
/**
* Add new fields to the metaboxes in the admin panel
*
* @since 1.0.0
* @return void
*/
public function add_new_fields_to_booking_form( $booking_fields ) {
$prefix = '_wprm_';
$get_field_options = null;
$is_required = null;
$new_fields = array_reverse(WPRM_Custom_Fields::get_custom_fields());
if(!empty($new_fields)):
foreach ($new_fields as $new_field) {
// Check if the field is a select type
// if so - retrieve the options.
if($new_field['type'] == 'select') {
$get_field_options = explode(',', $new_field['options']);
}
// Check if the field is required or not
if($new_field['required'] == 'on') {
$is_required = true;
} else {
$is_required = false;
}
// Add the new field to the booking form
$booking_fields[] = array(
'type' => $new_field['type'],
'label' => $new_field['title'],
'name' => $prefix . $new_field['slug'],
'desc' => $new_field['description'],
'options' => $get_field_options,
'placeholder' => $new_field['placeholder'],
'value' => isset($_POST[$prefix.$new_field['slug']]) ? sanitize_text_field($_POST[$prefix.$new_field['slug']]) : '',
'selected' => isset($_POST[$prefix.$new_field['slug']]) ? sanitize_text_field($_POST[$prefix.$new_field['slug']]) : '',
'required' => $is_required
);
}
endif;
return array_merge(array_splice($booking_fields, -1), $booking_fields);
}
}
new WPRM_Move_last_custom_field_up;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment