Use new code style
This commit is contained in:
@ -9,8 +9,8 @@
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
use \WP_Ultimo\Checkout\Checkout;
|
||||
use \WP_Ultimo\Models\Checkout_Form;
|
||||
use WP_Ultimo\Checkout\Checkout;
|
||||
use WP_Ultimo\Models\Checkout_Form;
|
||||
|
||||
/**
|
||||
* Returns a checkout_form.
|
||||
@ -23,8 +23,7 @@ use \WP_Ultimo\Models\Checkout_Form;
|
||||
function wu_get_checkout_form($checkout_form_id) {
|
||||
|
||||
return \WP_Ultimo\Models\Checkout_Form::get_by_id($checkout_form_id);
|
||||
|
||||
} // end wu_get_checkout_form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries checkout_forms.
|
||||
@ -37,8 +36,7 @@ function wu_get_checkout_form($checkout_form_id) {
|
||||
function wu_get_checkout_forms($query = array()) {
|
||||
|
||||
return \WP_Ultimo\Models\Checkout_Form::query($query);
|
||||
|
||||
} // end wu_get_checkout_forms;
|
||||
}
|
||||
/**
|
||||
* Returns a checkout_form based on slug.
|
||||
*
|
||||
@ -59,40 +57,33 @@ function wu_get_checkout_form_by_slug($checkout_form_slug) {
|
||||
* @see wu_checkout_form_membership_change_form_fields filter.
|
||||
*/
|
||||
if ($checkout_form_slug === 'wu-checkout') {
|
||||
|
||||
$checkout_form = new \WP_Ultimo\Models\Checkout_Form;
|
||||
$checkout_form = new \WP_Ultimo\Models\Checkout_Form();
|
||||
|
||||
$checkout_fields = Checkout_Form::membership_change_form_fields();
|
||||
|
||||
$checkout_form->set_settings($checkout_fields);
|
||||
|
||||
return $checkout_form;
|
||||
|
||||
} elseif ($checkout_form_slug === 'wu-add-new-site') {
|
||||
|
||||
$checkout_form = new \WP_Ultimo\Models\Checkout_Form;
|
||||
$checkout_form = new \WP_Ultimo\Models\Checkout_Form();
|
||||
|
||||
$checkout_fields = Checkout_Form::add_new_site_form_fields();
|
||||
|
||||
$checkout_form->set_settings($checkout_fields);
|
||||
|
||||
return $checkout_form;
|
||||
|
||||
} elseif ($checkout_form_slug === 'wu-finish-checkout') {
|
||||
|
||||
$checkout_form = new \WP_Ultimo\Models\Checkout_Form;
|
||||
$checkout_form = new \WP_Ultimo\Models\Checkout_Form();
|
||||
|
||||
$checkout_fields = Checkout_Form::finish_checkout_form_fields();
|
||||
|
||||
$checkout_form->set_settings($checkout_fields);
|
||||
|
||||
return $checkout_form;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return \WP_Ultimo\Models\Checkout_Form::get_by('slug', $checkout_form_slug);
|
||||
|
||||
} // end wu_get_checkout_form_by_slug;
|
||||
}
|
||||
/**
|
||||
* Creates a new checkout form.
|
||||
*
|
||||
@ -103,22 +94,24 @@ function wu_get_checkout_form_by_slug($checkout_form_slug) {
|
||||
*/
|
||||
function wu_create_checkout_form($checkout_form_data) {
|
||||
|
||||
$checkout_form_data = wp_parse_args($checkout_form_data, array(
|
||||
'name' => false,
|
||||
'slug' => false,
|
||||
'settings' => array(),
|
||||
'allowed_countries' => array(),
|
||||
'date_created' => wu_get_current_time('mysql', true),
|
||||
'date_modified' => wu_get_current_time('mysql', true),
|
||||
));
|
||||
$checkout_form_data = wp_parse_args(
|
||||
$checkout_form_data,
|
||||
array(
|
||||
'name' => false,
|
||||
'slug' => false,
|
||||
'settings' => array(),
|
||||
'allowed_countries' => array(),
|
||||
'date_created' => wu_get_current_time('mysql', true),
|
||||
'date_modified' => wu_get_current_time('mysql', true),
|
||||
)
|
||||
);
|
||||
|
||||
$checkout_form = new Checkout_Form($checkout_form_data);
|
||||
|
||||
$saved = $checkout_form->save();
|
||||
|
||||
return is_wp_error($saved) ? $saved : $checkout_form;
|
||||
|
||||
} // end wu_create_checkout_form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all the available domain options in all registered forms.
|
||||
@ -133,46 +126,35 @@ function wu_get_available_domain_options() {
|
||||
$main_form = wu_get_checkout_form_by_slug('main-form');
|
||||
|
||||
if ($main_form) {
|
||||
|
||||
$fields = $main_form->get_all_fields_by_type('site_url');
|
||||
|
||||
} else {
|
||||
|
||||
$forms = wu_get_checkout_forms(array(
|
||||
'number' => 1,
|
||||
));
|
||||
$forms = wu_get_checkout_forms(
|
||||
array(
|
||||
'number' => 1,
|
||||
)
|
||||
);
|
||||
|
||||
if ($forms) {
|
||||
|
||||
$fields = $forms[0]->get_all_fields_by_type('site_url');
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
}
|
||||
|
||||
$domain_options = array();
|
||||
|
||||
if ($fields) {
|
||||
|
||||
foreach ($fields as $field) {
|
||||
|
||||
$available_domains = isset($field['available_domains']) ? $field['available_domains'] : '';
|
||||
|
||||
$field_domain_options = explode(PHP_EOL, (string) $available_domains);
|
||||
|
||||
if (isset($field['enable_domain_selection']) && $field['enable_domain_selection'] && $field_domain_options) {
|
||||
|
||||
$domain_options = array_merge($domain_options, $field_domain_options);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $domain_options;
|
||||
|
||||
} // end wu_get_available_domain_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the field is preselected in request.
|
||||
@ -187,11 +169,10 @@ function wu_is_form_field_pre_selected($field_slug) {
|
||||
|
||||
$pre_selected = $checkout->request_or_session('pre_selected', array());
|
||||
|
||||
$from_request = stripslashes_deep(wu_get_isset($_GET, $field_slug)) || isset($pre_selected[$field_slug]);
|
||||
$from_request = stripslashes_deep(wu_get_isset($_GET, $field_slug)) || isset($pre_selected[ $field_slug ]);
|
||||
|
||||
return wu_request('wu_preselected') === $field_slug || $from_request;
|
||||
|
||||
} // end wu_is_form_field_pre_selected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the request arg slug from a field.
|
||||
@ -203,20 +184,15 @@ function wu_is_form_field_pre_selected($field_slug) {
|
||||
function wu_form_field_request_arg($field) {
|
||||
|
||||
if ($field['type'] === 'template_selection') {
|
||||
|
||||
return 'template_id';
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
if ($field['type'] === 'pricing_table') {
|
||||
|
||||
return 'products';
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return $field['id'];
|
||||
|
||||
} // end wu_form_field_request_arg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the field should be hidden in form
|
||||
@ -230,5 +206,4 @@ function wu_should_hide_form_field($field) {
|
||||
$hide_preselect = (bool) (int) wu_get_isset($field, "hide_{$field['type']}_when_pre_selected");
|
||||
|
||||
return $hide_preselect && wu_is_form_field_pre_selected(wu_form_field_request_arg($field));
|
||||
|
||||
} // end wu_should_hide_form_field;
|
||||
}
|
||||
|
Reference in New Issue
Block a user