public static function get_instance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
/** * Get states. */ public static function ajax_get_states() { if (empty($_GET['country']) || !isset($_GET['_wpnonce']) || !wp_verify_nonce($_GET['_wpnonce'], 'ib_edu_get_states')) { exit; } $country = preg_replace('/[^a-z]+/i', '', $_GET['country']); $edu_countries = Edr_Countries::get_instance(); $states = $edu_countries->get_states($country); $json = '['; $i = 0; foreach ($states as $scode => $sname) { if ($i > 0) { $json .= ','; } $json .= '{"code": ' . json_encode(esc_html($scode)) . ',"name":' . json_encode(esc_html($sname)) . '}'; ++$i; } $json .= ']'; echo $json; exit; }
} ?> </div> </div> <!-- Country --> <div class="ib-edu-field"> <div class="ib-edu-label"><label for="ib-edu-country"><?php _e('Country', 'ibeducator'); ?> </label></div> <div class="ib-edu-control"> <select id="ib-edu-country" class="regular-text" name="country"> <option value=""></option> <?php $countries = Edr_Countries::get_instance()->get_countries(); foreach ($countries as $code => $country) { echo '<option value="' . esc_attr($code) . '"' . selected($payment->country, $code, false) . '>' . esc_html($country) . '</option>'; } ?> </select> </div> </div> </div> </div> <?php if (!empty($lines)) { ?> <div class="postbox"> <div class="handlediv"><br></div>
/** * 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(); }
/** * Render tax rates app. */ public function render_tax_classes() { $countries = Edr_Countries::get_instance()->get_countries(); ?> <div id="edu-tax-classes-container"></div> <!-- TEMPLATE: TaxClassView --> <script id="edu-tax-class" type="text/html"> <td><%= description %></td> <td> <button class="button edit-tax-class"><?php _e('Edit', 'ibeducator'); ?> </button> <button class="button edit-rates"><?php _e('Rates', 'ibeducator'); ?> </button> <button class="button delete-tax-class"><?php _e('Delete', 'ibeducator'); ?> </button> </td> </script> <!-- TEMPLATE: TaxClassesView --> <script id="edu-tax-classes" type="text/html"> <table class="edu-tax-classes-table edu-table"> <thead> <tr> <th><?php _e('Tax Class', 'ibeducator'); ?> </th> <th><?php _e('Options', 'ibeducator'); ?> </th> </tr> </thead> <tbody></tbody> </table> <p class="actions"> <button class="button add-new-class"><?php _e('Add New', 'ibeducator'); ?> </button> </p> </script> <!-- TEMPLATE: EditTaxClassView --> <script id="edu-edit-tax-class" type="text/html"> <h4 class="title-add-new"><?php _e('Add New Tax Rate', 'ibeducator'); ?> </h4> <h4 class="title-edit"><?php _e('Edit Tax Rate', 'ibeducator'); ?> </h4> <p> <label><?php _e('Short Name', 'ibeducator'); ?> </label> <input type="text" class="short-name" value="<%= name %>"> </p> <p> <label><?php _e('Description', 'ibeducator'); ?> </label> <input type="text" class="description" value="<%= description %>"> </p> <p> <button class="button button-primary save-tax-class"><?php _e('Save', 'ibeducator'); ?> </button> <button class="button cancel"><?php _e('Cancel', 'ibeducator'); ?> </button> </p> </script> <!-- TEMPLATE: view tax rate --> <script id="edu-tax-rate" type="text/html"> <td class="handle"><div class="ib-edu-sort-y dashicons dashicons-sort"></div></td> <td class="country"><%= country_name %></td> <td class="state"><%= state_name %></td> <td class="name"><%= name %></td> <td class="rate"><%= rate %></td> <td class="priority"><%= priority %></td> <td class="options"> <a class="edit-rate ib-edu-action" href="#"><?php _e('Edit', 'ibeducator'); ?> </a> <span>|</span> <a class="delete-rate ib-edu-action" href="#"><?php _e('Delete', 'ibeducator'); ?> </a> </td> </script> <!-- TEMPLATE: edit tax rate --> <script id="edu-tax-rate-edit" type="text/html"> <td class="handle"><div class="ib-edu-sort-y dashicons dashicons-sort"></div></td> <td class="country"> <select class="country"> <option value=""></option> <?php foreach ($countries as $code => $country) { echo '<option value="' . esc_attr($code) . '">' . esc_html($country) . '</option>'; } ?> </select> </td> <td class="state"></td> <td class="name"><input type="text" value="<%= name %>"></td> <td class="rate"><input type="number" value="<%= rate %>"></td> <td class="priority"><input type="number" value="<%= priority %>"></td> <td class="options"> <a class="save-rate ib-edu-action" href="#"><?php _e('Save', 'ibeducator'); ?> </a> <span>|</span> <a class="delete-rate ib-edu-action" href="#"><?php _e('Delete', 'ibeducator'); ?> </a> </td> </script> <!-- TEMPLATE: TaxRatesView --> <script id="edu-tax-rates" type="text/html"> <table class="edu-tax-rates-table edu-table"> <thead> <tr> <th></th> <th><?php _e('Country', 'ibeducator'); ?> </th> <th><?php _e('State', 'ibeducator'); ?> </th> <th><?php _e('Name', 'ibeducator'); ?> </th> <th><?php _e('Rate (%)', 'ibeducator'); ?> </th> <th><?php _e('Priority', 'ibeducator'); ?> </th> <th><?php _e('Options', 'ibeducator'); ?> </th> </tr> </thead> <tbody> <tr class="loading"> <td colspan="7"> <?php _e('Loading', 'ibeducator'); ?> </td> </tr> </tbody> <tfoot> <tr> <td colspan="7"> <button class="button button-primary add-new-rate"><?php _e('Add New', 'ibeducator'); ?> </button> <button class="button save-order" disabled="disabled"><?php _e('Save Order', 'ibeducator'); ?> </button> <button class="button cancel"><?php _e('Close', 'ibeducator'); ?> </button> </td> </tr> </tfoot> </table> </script> <script> var eduTaxAppNonce = <?php echo json_encode(wp_create_nonce('ib_educator_tax_rates')); ?> ; var eduGetStatesNonce = <?php echo json_encode(wp_create_nonce('ib_edu_get_states')); ?> ; var eduTaxClasses = <?php $json = '['; $classes = Edr_TaxManager::get_instance()->get_tax_classes(); $i = 0; foreach ($classes as $name => $description) { if ($i > 0) { $json .= ','; } $json .= '{name:' . json_encode(esc_html($name)) . ',description:' . json_encode(esc_html($description)) . '}'; ++$i; } $json .= ']'; echo $json; ?> ; var eduTaxAppErrors = { name: <?php echo json_encode(__('The name is invalid.', 'ibeducator')); ?> , nameNotUnique: <?php echo json_encode(__('Tax class with this name exists.', 'ibeducator')); ?> , description: <?php echo json_encode(__('Description cannot be empty.', 'ibeducator')); ?> , ratesNotSaved: <?php echo json_encode(__('Rates could not be saved.', 'ibeducator')); ?> }; </script> <?php }