<?php // Setup form object. require_once IBEDUCATOR_PLUGIN_DIR . 'includes/ib-educator-form.php'; $form = new IB_Educator_Form(); $form->default_decorators(); // Registration. $form->set_value('_ib_educator_register', get_post_meta($post->ID, '_ib_educator_register', true)); $form->add(array('type' => 'select', 'name' => '_ib_educator_register', 'label' => __('Registration', 'ibeducator'), 'options' => array('open' => __('Open', 'ibeducator'), 'closed' => __('Closed', 'ibeducator')), 'default' => 'open')); // Price. $form->set_value('_ibedu_price', ib_edu_get_course_price($post->ID)); $form->add(array('type' => 'text', 'name' => '_ibedu_price', 'class' => '', 'id' => 'ib-educator-price', 'label' => __('Price', 'ibeducator'), 'before' => esc_html(ib_edu_get_currency_symbol(ib_edu_get_currency())) . ' ')); // Tax Class. $edu_tax = IB_Educator_Tax::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')); // Difficulty. $form->set_value('_ib_educator_difficulty', get_post_meta($post->ID, '_ib_educator_difficulty', true)); $form->add(array('type' => 'select', 'name' => '_ib_educator_difficulty', 'id' => 'ib-educator-difficulty', 'label' => __('Difficulty', 'ibeducator'), 'options' => array_merge(array('' => __('None', 'ibeducator')), ib_edu_get_difficulty_levels()))); // Prerequisite. $courses = array('' => __('None', 'ibeducator')); $tmp = get_posts(array('post_type' => 'ib_educator_course', 'post_status' => 'publish', 'posts_per_page' => -1)); foreach ($tmp as $course) { $courses[$course->ID] = $course->post_title; } $prerequisites = IB_Educator::get_instance()->get_prerequisites($post->ID); $form->set_value('_ib_educator_prerequisite', array_pop($prerequisites)); $form->add(array('type' => 'select', 'name' => '_ib_educator_prerequisite', 'id' => 'ib-educator-prerequisite', 'label' => __('Prerequisite', 'ibeducator'), 'options' => $courses)); wp_nonce_field('ib_educator_course_meta_box', 'ib_educator_course_meta_box_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. require_once IBEDUCATOR_PLUGIN_DIR . 'includes/ib-educator-form.php'; $form = new IB_Educator_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 = IB_Educator_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(); }
/** * Output gateway options form. */ public function admin_options_form() { if (!$this->is_editable()) { return; } require_once IBEDUCATOR_PLUGIN_DIR . 'includes/ib-educator-form.php'; $form = new IB_Educator_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(); }