/** * Output gateway options form. */ public function admin_options_form() { if (!$this->is_editable()) { return; } $form = new Edr_Form(); $form->add_field_class('ib-edu-field'); $form->set_decorator('label_before', '<div class="ib-edu-label">'); $form->set_decorator('label_after', '</div>'); $form->set_decorator('control_before', '<div class="ib-edu-control">'); $form->set_decorator('control_after', '</div>'); foreach ($this->options as $name => $data) { $data['name'] = 'ibedu_' . $this->id . '_' . $name; $form->set_value($data['name'], $this->get_option($name)); $form->add($data); } $form->display(); }
$form = new Edr_Form(); $form->default_decorators(); // Price. $form->set_value('_ib_educator_price', $meta['price']); $form->add(array('type' => 'text', 'name' => '_ib_educator_price', 'id' => 'ib-educator-price', 'label' => __('Price', 'ibeducator'), 'before' => esc_html(ib_edu_get_currency_symbol(ib_edu_get_currency())) . ' ')); // Tax Class. $edu_tax = Edr_TaxManager::get_instance(); $form->set_value('_ib_educator_tax_class', $edu_tax->get_tax_class_for($post->ID)); $form->add(array('type' => 'select', 'name' => '_ib_educator_tax_class', 'label' => __('Tax Class', 'ibeducator'), 'options' => $edu_tax->get_tax_classes(), 'default' => 'default')); // Duration. $period = '<select name="_ib_educator_period">'; foreach ($membership_periods as $mp_value => $mp_name) { $period .= '<option value="' . esc_attr($mp_value) . '"' . selected($meta['period'], $mp_value, false) . '>' . esc_html($mp_name) . '</option>'; } $period .= '</select>'; $form->set_value('_ib_educator_duration', $meta['duration']); $form->add(array('type' => 'text', 'name' => '_ib_educator_duration', 'id' => 'ib-educator-duration', 'class' => 'small-text', 'label' => __('Duration', 'ibeducator'), 'after' => " {$period}")); // Categories. $categories = array('' => __('Select Categories', 'ibeducator')); $terms = get_terms('ib_educator_category'); if ($terms && !is_wp_error($terms)) { foreach ($terms as $term) { $categories[$term->term_id] = $term->name; } } $form->set_value('_ib_educator_categories', $meta['categories']); $form->add(array('type' => 'select', 'name' => '_ib_educator_categories', 'label' => __('Categories', 'ibeducator'), 'multiple' => true, 'size' => 5, 'options' => $categories)); // Display the form. wp_nonce_field('ib_edu_membership', 'ib_edu_membership_nonce'); $form->display();
/** * 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(); }