Пример #1
0
 /**
  * Output default user register form.
  *
  * @param WP_Error $errors
  * @param WP_Post $object
  */
 public static function register_form($errors, $object)
 {
     // Get current user.
     $user = wp_get_current_user();
     $error_codes = is_wp_error($errors) ? $errors->get_error_codes() : array();
     // Determine fields that can have multiple errors.
     $has_error = self::parse_register_errors($error_codes);
     // Setup form.
     $form = new Edr_Form();
     $form->default_decorators();
     if (!$user->ID) {
         // Add account details group.
         $form->add_group(array('name' => 'account', 'label' => __('Create an Account', 'ibeducator')));
         // Set values.
         $form->set_value('account_username', isset($_POST['account_username']) ? $_POST['account_username'] : '');
         $form->set_value('account_email', isset($_POST['account_email']) ? $_POST['account_email'] : '');
         // Username.
         $form->add(array('type' => 'text', 'name' => 'account_username', 'container_id' => 'account-username-field', 'label' => __('Username', 'ibeducator'), 'id' => 'account-username', 'class' => isset($has_error['account_username']) ? 'error' : '', 'required' => true), 'account');
         // Email.
         $form->add(array('type' => 'text', 'name' => 'account_email', 'container_id' => 'account-email-field', 'label' => __('Email', 'ibeducator'), 'id' => 'account-email', 'class' => isset($has_error['account_email']) ? 'error' : '', 'required' => true), 'account');
     }
     if (ib_edu_collect_billing_data($object)) {
         // Add billing details group.
         $form->add_group(array('name' => 'billing', 'label' => __('Billing Details', 'ibeducator')));
         // Set values.
         $values = IB_Educator::get_instance()->get_billing_data($user->ID);
         if (empty($values['country'])) {
             $values['country'] = ib_edu_get_location('country');
         }
         if (empty($values['state'])) {
             $values['state'] = ib_edu_get_location('state');
         }
         $values['first_name'] = $user->ID ? $user->first_name : '';
         $values['last_name'] = $user->ID ? $user->last_name : '';
         foreach ($values as $key => $value) {
             $post_key = 'billing_' . $key;
             if (isset($_POST[$post_key])) {
                 $form->set_value($post_key, $_POST[$post_key]);
             } else {
                 $form->set_value($post_key, $value);
             }
         }
         // First Name.
         $form->add(array('type' => 'text', 'name' => 'billing_first_name', 'container_id' => 'billing-first-name-field', 'label' => __('First Name', 'ibeducator'), 'id' => 'billing-first-name', 'class' => in_array('billing_first_name_empty', $error_codes) ? 'error' : '', 'required' => true), 'billing');
         // Last Name.
         $form->add(array('type' => 'text', 'name' => 'billing_last_name', 'container_id' => 'billing-last-name-field', 'label' => __('Last Name', 'ibeducator'), 'id' => 'billing-last-name', 'class' => in_array('billing_last_name_empty', $error_codes) ? 'error' : '', 'required' => true), 'billing');
         // Address.
         $form->add(array('type' => 'text', 'name' => 'billing_address', 'container_id' => 'billing-address-field', 'label' => __('Address', 'ibeducator'), 'id' => 'billing-address', 'class' => in_array('billing_address_empty', $error_codes) ? 'error' : '', 'required' => true), 'billing');
         // Address Line 2.
         $form->add(array('type' => 'text', 'name' => 'billing_address_2', 'container_id' => 'billing-address-2-field', 'label' => __('Address Line 2', 'ibeducator'), 'id' => 'billing-address-2'), 'billing');
         // City.
         $form->add(array('type' => 'text', 'name' => 'billing_city', 'container_id' => 'billing-city-field', 'label' => __('City', 'ibeducator'), 'id' => 'billing-city', 'class' => in_array('billing_city_empty', $error_codes) ? 'error' : '', 'required' => true), 'billing');
         $edu_countries = Edr_Countries::get_instance();
         // State.
         $state_field = array('name' => 'billing_state', 'container_id' => 'billing-state-field', 'label' => __('State / Province', 'ibeducator'), 'id' => 'billing-state', 'class' => in_array('billing_state_empty', $error_codes) ? 'error' : '', 'required' => true);
         $country = $form->get_value('billing_country');
         $states = $country ? $edu_countries->get_states($country) : null;
         if ($states) {
             $state_field['type'] = 'select';
             $state_field['options'] = array_merge(array('' => ' '), $states);
             unset($states);
         } else {
             $state_field['type'] = 'text';
         }
         $form->add($state_field, 'billing');
         // Postcode.
         $form->add(array('type' => 'text', 'name' => 'billing_postcode', 'container_id' => 'billing-postcode-field', 'label' => __('Postcode / Zip', 'ibeducator'), 'id' => 'billing-postcode', 'class' => in_array('billing_postcode_empty', $error_codes) ? 'error' : '', 'required' => true), 'billing');
         // Country.
         $form->add(array('type' => 'select', 'name' => 'billing_country', 'container_id' => 'billing-country-field', 'label' => __('Country', 'ibeducator'), 'id' => 'billing-country', 'class' => in_array('billing_country_empty', $error_codes) ? 'error' : '', 'required' => true, 'options' => array_merge(array('' => ' '), $edu_countries->get_countries())), 'billing');
     }
     $form->display();
 }