/** * Updates user * * @access public * @return void */ public static function updateUser() { $data = $_POST; if (isset($_POST['data'])) { parse_str($_POST['data'], $data); } if (isset($data['user_action'])) { $action = sanitize_title($data['user_action']); $ID = get_current_user_id(); $redirect = false; if (!empty($ID)) { switch ($action) { case 'update_avatar': self::updateAvatar($ID, themex_array('user_avatar', $_FILES)); $redirect = true; break; case 'update_profile': self::updateProfile($ID, $data); break; case 'update_settings': self::updateSettings($ID, $data); break; case 'add_relation': self::addRelation($ID, $data); break; case 'remove_relation': self::removeRelation($ID, $data); break; case 'submit_message': self::submitMessage($ID, $data); break; } } switch ($action) { case 'register_user': self::registerUser($data); break; case 'login_user': self::loginUser($data); break; case 'reset_user': self::resetUser($data); break; } if ($redirect || empty(ThemexInterface::$messages)) { wp_redirect(themex_url()); exit; } } }
/** * Renders module data * * @access public * @param string $slug * @param array $optionst * @param array $values * @return void */ public static function renderData($slug, $options = array(), $values = array()) { $options = wp_parse_args($options, array('edit' => true, 'placeholder' => true, 'before_title' => '', 'after_title' => '', 'before_content' => '', 'after_content' => '')); $out = ''; $counter = 0; if (self::isActive($slug)) { foreach (self::$data[$slug]['fields'] as $field) { if (!empty($field['name'])) { $ID = themex_sanitize_key($field['name']); $counter++; if ($options['edit']) { if (!empty($options['before_title']) || !empty($options['after_title'])) { $out .= $options['before_title'] . $field['name'] . $options['after_title']; } if (!empty($options['before_content'])) { $out .= $options['before_content']; } $args = array('id' => $ID, 'type' => $field['type'], 'value' => themex_array($ID, $values), 'wrap' => false); if ($field['type'] == 'select') { $args['options'] = array_merge(array('0' => '–'), explode(',', $field['options'])); $out .= '<div class="element-select"><span></span>'; } else { if ($options['placeholder']) { $args['attributes'] = array('placeholder' => $field['name']); } $out .= '<div class="field-wrap">'; } $out .= ThemexInterface::renderOption($args); $out .= '</div>'; if (!empty($options['after_content'])) { $out .= $options['after_content']; } } else { if (isset($values[$ID])) { $out .= $options['before_title'] . $field['name'] . $options['after_title'] . $options['before_content']; if ($field['type'] == 'select') { $items = array_merge(array('0' => '–'), explode(',', $field['options'])); if (isset($items[$values[$ID]])) { $values[$ID] = $items[$values[$ID]]; } } if (empty($values[$ID])) { $values[$ID] = '–'; } $out .= $values[$ID]; $out .= $options['after_content']; } } } } } echo $out; }
} } else { ?> <tr> <th><?php echo $field['label']; ?> </th> <td> <?php if (in_array($field['type'], array('select', 'select_country'))) { ?> <div class="element-select"> <span></span> <?php echo ThemexInterface::renderOption(array('id' => $field['name'], 'type' => $field['type'], 'options' => array_intersect_key(themex_array('options', $field), $methods), 'value' => themex_value($field['name'], $_POST), 'wrap' => false, 'attributes' => array('class' => 'element-trigger'))); ?> </div> <?php } else { ?> <div class="field-wrap"> <input type="text" name="<?php echo esc_attr($field['name']); ?> " value="<?php echo esc_attr(themex_value($field['name'], $_POST)); ?> " /> </div> <?php
<?php echo ThemexInterface::renderOption(array('id' => 'country', 'type' => 'select_country', 'attributes' => array('class' => 'countries-list'), 'value' => esc_attr(themex_array('country', $_GET)), 'wrap' => false)); ?> </div> </td> </tr> <tr> <th><?php _e('City', 'makery'); ?> </th> <td> <div class="element-select"> <span></span> <?php echo ThemexInterface::renderOption(array('id' => 'city', 'type' => 'select_city', 'attributes' => array('class' => 'element-filter', 'data-filter' => 'countries-list'), 'value' => esc_attr(themex_array('city', $_GET)), 'wrap' => false)); ?> </div> </td> </tr> <?php } ?> </tbody> </table> <a href="#" class="element-button element-submit primary"><?php _e('Search', 'makery'); ?> </a> <input type="hidden" name="post_type" value="shop" /> </form>
/** * Enqueues script * * @access public * @param array $args * @return void */ public static function enqueueScript($args) { if (isset($args['uri'])) { $args['deps'] = themex_array('deps', $args, array()); wp_enqueue_script($args['name'], $args['uri'], $args['deps'], null, true); } else { wp_enqueue_script($args['name']); } if (isset($args['options'])) { wp_localize_script($args['name'], 'options', $args['options']); } }
/** * Updates shipping settings * * @access public * @param int $ID * @param array $data * @return void */ public static function updateShipping($ID, $data) { $shipping = array(); $methods = ThemexWoo::getShippingMethods(); $defaults = array('free_shipping', 'flat_rate', 'international_delivery', 'local_delivery'); foreach ($defaults as $default) { if (isset($methods[$default])) { $shipping[$default]['enabled'] = sanitize_title(themex_value($default . '_enabled', $data)); $shipping[$default]['availability'] = sanitize_title(themex_value($default . '_availability', $data)); $countries = themex_array($default . '_countries', $data); if (is_array($countries)) { foreach ($countries as &$country) { if (is_array($country) && !empty($country)) { $country = reset($country); } } } $shipping[$default]['countries'] = $countries; if ($default == 'free_shipping') { $shipping[$default]['min_amount'] = ThemexWoo::formatPrice(themex_value($default . '_min_amount', $data), false); } else { if ($default == 'flat_rate') { $shipping[$default]['default_cost'] = ThemexWoo::formatPrice(themex_value($default . '_default_cost', $data), false); $costs = themex_array($default . '_cost', $data); if (is_array($costs)) { foreach ($costs as &$cost) { $cost = ThemexWoo::formatPrice($cost, false); } } $classes = themex_array($default . '_class', $data); $shipping[$default]['costs'] = array(); if (is_array($classes)) { $classes = array_map('sanitize_title', $classes); foreach ($classes as $index => $class) { if (isset($costs[$index]) && !empty($costs[$index])) { $shipping[$default]['costs'][$class] = $costs[$index]; } } } } else { if (in_array($default, array('international_delivery', 'local_delivery'))) { $shipping[$default]['cost'] = ThemexWoo::formatPrice(themex_value($default . '_cost', $data), false); } } } } } ThemexCore::updatePostMeta($ID, 'shipping', $shipping); ThemexInterface::$messages[] = __('Changes have been successfully saved', 'makery'); $_POST['success'] = true; }
/** * Updates shipping rates * * @access public * @param array $rates * @param array $package * @return array */ public static function updateShipping($rates, $package) { $products = $package['contents']; $product = reset($products); $total = $package['contents_cost']; $shipping = ThemexShop::getShipping(ThemexUser::getShop($product['data']->post->post_author)); $country = ''; if (isset($package['destination']) && isset($package['destination']['country'])) { $country = $package['destination']['country']; } if (!empty($rates)) { foreach ($rates as $key => $rate) { if (isset($shipping[$key])) { $method = $shipping[$key]; $enabled = themex_value('enabled', $method); $available = themex_value('availability', $method); $amount = themex_value('min_amount', $method); $countries = themex_array('countries', $method); if ($enabled == 'no' || !empty($amount) && $total < $amount || $available == 'specific' && !in_array($country, $countries)) { unset($rates[$key]); } else { if ($key == 'flat_rate') { $default = intval(themex_value('default_cost', $method)); $costs = themex_array('costs', $method); $cost = 0; foreach ($products as $product) { $classes = get_the_terms($product['product_id'], 'product_shipping_class'); if (is_array($classes) && !empty($classes)) { $class = reset($classes); $class = $class->slug; if (isset($costs[$class])) { $cost = $cost + intval($costs[$class]) * $product['quantity']; } else { $cost = $cost + $default * $product['quantity']; } } else { $cost = $cost + $default * $product['quantity']; } } $rates[$key]->cost = $cost; } } } } } return $rates; }
/** * Renders admin profile * * @access public * @param mixed $user * @return void */ public static function renderAdminProfile($user) { $profile = self::getProfile($user->ID); $out = '<table class="form-table themex-profile"><tbody>'; if (current_user_can('edit_users')) { $out .= '<tr><th><label for="avatar">' . __('Profile Photo', 'academy') . '</label></th>'; $out .= '<td><div class="themex-image-uploader">'; $out .= get_avatar($user->ID); $out .= ThemexInterface::renderOption(array('id' => 'avatar', 'type' => 'uploader', 'value' => '', 'wrap' => false)); $out .= '</div></td></tr>'; } ob_start(); ThemexForm::renderData('profile', array('edit' => true, 'placeholder' => false, 'before_title' => '<tr><th><label>', 'after_title' => '</label></th>', 'before_content' => '<td>', 'after_content' => '</td></tr>'), $profile); $out .= ob_get_contents(); ob_end_clean(); $out .= '<tr><th><label>' . __('Profile Text', 'academy') . '</label></th><td>'; ob_start(); ThemexInterface::renderEditor('description', themex_array('description', $profile)); $out .= ob_get_contents(); ob_end_clean(); $out .= '</td></tr>'; $out .= '</tbody></table>'; echo $out; }
/** * Renders option * * @access public * @param array $option * @return string */ public static function renderOption($option) { global $post, $wpdb, $wp_registered_sidebars, $wp_locale; $out = ''; //option wrapper if (!isset($option['wrap']) || $option['wrap']) { $parent = ''; if (isset($option['parent'])) { $parent = 'data-parent="' . THEMEX_PREFIX . $option['parent']['id'] . '" '; $parent .= 'data-value="' . $option['parent']['value'] . '"'; } $out .= '<div class="themex-option themex-' . str_replace('_', '-', $option['type']) . '" ' . $parent . '>'; if (isset($option['name']) && $option['type'] != 'checkbox') { $out .= '<h3 class="themex-option-title">' . $option['name'] . '</h3>'; } } //option before if (isset($option['before'])) { $out .= $option['before']; } //option description if (isset($option['description'])) { $out .= '<div class="themex-tooltip"><div class="themex-tooltip-icon"></div><div class="themex-tooltip-text">' . $option['description'] . '</div></div>'; } //option attributes $attributes = ''; if (isset($option['attributes'])) { foreach ($option['attributes'] as $name => $value) { $attributes .= $name . '="' . $value . '" '; } } //option value if (!isset($option['value'])) { $option['value'] = ''; if (isset($option['id'])) { $option['value'] = themex_stripslashes(get_option($option['id'])); if (($option['value'] === false || $option['value'] == '') && isset($option['default'])) { $option['value'] = themex_stripslashes($option['default']); } } else { if (isset($option['default'])) { $option['value'] = themex_stripslashes($option['default']); } } } switch ($option['type']) { //text field case 'text': $out .= '<input type="text" id="' . $option['id'] . '" name="' . $option['id'] . '" value="' . $option['value'] . '" ' . $attributes . ' />'; break; //number field //number field case 'number': $out .= '<input type="number" id="' . $option['id'] . '" name="' . $option['id'] . '" value="' . abs(intval($option['value'])) . '" ' . $attributes . ' />'; break; //date field //date field case 'date': $out .= '<input type="text" id="' . $option['id'] . '" name="' . $option['id'] . '" value="' . $option['value'] . '" class="date-field" ' . $attributes . ' />'; break; //hidden field //hidden field case 'hidden': $out .= '<input type="hidden" id="' . $option['id'] . '" name="' . $option['id'] . '" value="' . $option['value'] . '" ' . $attributes . ' />'; break; //message field //message field case 'textarea': $out .= '<textarea id="' . $option['id'] . '" name="' . $option['id'] . '" ' . $attributes . '>' . $option['value'] . '</textarea>'; break; //visual editor //visual editor case 'editor': ob_start(); self::renderEditor($option['id'], $option['value']); $out = ob_get_contents(); ob_end_clean(); break; //checkbox //checkbox case 'checkbox': $checked = ''; if ($option['value'] == 'true') { $checked = 'checked="checked"'; } $out .= '<input type="checkbox" id="' . $option['id'] . '" name="' . $option['id'] . '" value="true" ' . $checked . ' ' . $attributes . ' />'; if (isset($option['name'])) { $out .= '<label for="' . $option['id'] . '">' . $option['name'] . '</label>'; } break; //colorpicker //colorpicker case 'color': $out .= '<input name="' . $option['id'] . '" id="' . $option['id'] . '" type="text" value="' . $option['value'] . '" class="themex-colorpicker" />'; break; //uploader //uploader case 'uploader': $out .= '<input name="' . $option['id'] . '" id="' . $option['id'] . '" type="text" value="' . $option['value'] . '" ' . $attributes . ' />'; $out .= '<a class="button themex-upload-button">' . __('Browse', 'makery') . '</a>'; break; //images selector //images selector case 'select_image': foreach ($option['options'] as $name => $src) { $out .= '<image src="' . $src . '" '; if ($name == $option['value']) { $out .= 'class="current"'; } $out .= ' data-value="' . $name . '" />'; } $out .= '<input type="hidden" name="' . $option['id'] . '" id="' . $option['id'] . '" value="' . $option['value'] . '" ' . $attributes . ' />'; break; //custom dropdown //custom dropdown case 'select': if (isset($option['attributes']['multiple'])) { $option['id'] .= '[]'; } $out .= '<select id="' . $option['id'] . '" name="' . $option['id'] . '" ' . $attributes . '>'; if (isset($option['options'])) { foreach ($option['options'] as $name => $title) { $selected = ''; if ($option['value'] != '' && ($name == $option['value'] || is_array($option['value']) && in_array($name, $option['value']))) { $selected = 'selected="selected"'; } $out .= '<option value="' . $name . '" ' . $selected . '>' . $title . '</option>'; } } $out .= '</select>'; break; //fonts dropdown //fonts dropdown case 'select_font': $options = ThemexCore::$components['fonts']; asort($options); $out .= self::renderOption(array('id' => $option['id'], 'type' => 'select', 'wrap' => false, 'default' => $option['value'], 'options' => $options)); break; //countries dropdown //countries dropdown case 'select_country': $options = ThemexCore::$components['countries']; $options = array_merge(array('0' => '–'), $options); $out .= self::renderOption(array('id' => $option['id'], 'type' => 'select', 'wrap' => false, 'default' => $option['value'], 'attributes' => themex_array('attributes', $option, array()), 'options' => $options)); break; //cities dropdown //cities dropdown case 'select_city': $fields = $wpdb->get_results("\r\n\t\t\t\t\tSELECT DISTINCT user_id, meta_key, meta_value FROM {$wpdb->usermeta}\r\n\t\t\t\t\tWHERE (meta_key = 'billing_country'\r\n\t\t\t\t\tOR meta_key = 'billing_city')\r\n\t\t\t\t\tAND meta_value <> '0'\r\n\t\t\t\t\tORDER BY meta_key ASC, meta_value ASC\r\n\t\t\t\t"); $list = array(); foreach ($fields as $field) { if (!empty($field->meta_value)) { if ($field->meta_key == 'billing_city') { $list[$field->user_id]['city'] = $field->meta_value; } else { $list[$field->user_id]['country'] = $field->meta_value; } } } $out .= '<select name="' . $option['id'] . '" ' . $attributes . '><option value="0">–</option>'; foreach ($list as $item) { if (isset($item['city']) && isset($item['country'])) { if (!isset($tree[$item['country']][$item['city']])) { $selected = ''; if ($item['city'] == $option['value']) { $selected = 'selected="selected"'; } $out .= '<option value="' . $item['city'] . '" class="' . $item['country'] . '" ' . $selected . '>' . $item['city'] . '</option>'; } $tree[$item['country']][$item['city']] = $item['city']; } } $out .= '</select>'; break; //pages dropdown //pages dropdown case 'select_page': $args = array('selected' => $option['value'], 'echo' => 0, 'name' => $option['id'], 'id' => $option['id']); $out .= wp_dropdown_pages($args); break; //posts dropdown //posts dropdown case 'select_post': $atts = array('numberposts' => -1, 'post_type' => $option['post_type'], 'post_status' => array('publish', 'future', 'pending', 'draft'), 'orderby' => 'title', 'order' => 'ASC'); if (isset($post) && isset($post->ID)) { $atts['exclude'] = array($post->ID); } if ($option['post_type'] != 'product' && !current_user_can('manage_options')) { $atts['author'] = get_current_user_id(); } $items = get_posts($atts); $out .= '<select id="' . $option['id'] . '" name="' . $option['id'] . '" ' . $attributes . '>'; $out .= '<option value="0">–</option>'; foreach ($items as $item) { $selected = ''; if ($item->ID == $option['value']) { $selected = 'selected="selected"'; } $out .= '<option value="' . $item->ID . '" ' . $selected . '>' . $item->post_title . '</option>'; } $out .= '</select>'; break; //sidebars dropdown //sidebars dropdown case 'select_sidebar': $sidebars = array(); foreach ($wp_registered_sidebars as $sidebar) { $sidebars[$sidebar['name']] = $sidebar['name']; } $out .= self::renderOption(array('id' => $option['id'], 'type' => 'select', 'wrap' => false, 'options' => $sidebars)); break; //categories dropdown //categories dropdown case 'select_category': $args = array('hide_empty' => 0, 'echo' => 0, 'selected' => $option['value'], 'show_option_all' => '–', 'hierarchical' => true, 'name' => $option['id'], 'id' => $option['id'], 'taxonomy' => $option['taxonomy'], 'orderby' => 'NAME'); if (isset($option['attributes'])) { $args['class'] = $option['attributes']['class']; } $out .= wp_dropdown_categories($args); break; //range slider //range slider case 'slider': $out .= '<div class="themex-slider-controls"></div><div class="themex-slider-value"></div>'; $out .= '<input type="hidden" class="slider-max" value="' . $option['max_value'] . '" />'; $out .= '<input type="hidden" class="slider-min" value="' . $option['min_value'] . '" />'; $out .= '<input type="hidden" class="slider-unit" value="' . $option['unit'] . '" />'; $out .= '<input type="hidden" class="slider-value" name="' . $option['id'] . '" id="' . $option['id'] . '" value="' . $option['value'] . '" />'; break; //users manager //users manager case 'users': $users = $wpdb->get_results($wpdb->prepare("\r\n\t\t\t\t\tSELECT user_id FROM {$wpdb->usermeta} \r\n\t\t\t\t\tWHERE meta_key='_" . THEMEX_PREFIX . "membership' \r\n\t\t\t\t\tAND meta_value=%d\r\n\t\t\t\t", $post->ID)); $users = wp_list_pluck($users, 'user_id'); $out .= '<div class="themex-row clearfix">'; $out .= wp_dropdown_users(array('echo' => false, 'exclude' => $users, 'name' => 'add_user_id', 'id' => 'add_user_id')); $out .= '<input type="submit" name="add_user" class="button" value="' . __('Add', 'makery') . '" /></div>'; if (!empty($users)) { $out .= '<div class="themex-row clearfix">'; $out .= wp_dropdown_users(array('echo' => false, 'include' => $users, 'name' => 'remove_user_id', 'id' => 'remove_user_id')); $out .= '<input type="submit" name="remove_user" class="button" value="' . __('Remove', 'makery') . '" /></div>'; } break; //module settings //module settings case 'module': $out .= '<div class="' . substr(strtolower(implode('-', preg_split('/(?=[A-Z])/', str_replace(THEMEX_PREFIX, '', $option['id'])))), 1) . '">'; if (isset($option['slug'])) { $out .= call_user_func(array(str_replace(THEMEX_PREFIX, '', $option['id']), 'renderSettings'), $option['slug']); } else { $out .= call_user_func(array(str_replace(THEMEX_PREFIX, '', $option['id']), 'renderSettings')); } $out .= '</div>'; break; } //option after if (isset($option['after'])) { $out .= $option['after']; } //wrap option if (!isset($option['wrap']) || $option['wrap']) { $out .= '</div>'; } return $out; }
continue; } ?> <tr> <th><?php echo $field['label']; ?> </th> <td> <?php if (in_array($field['type'], array('select', 'select_country'))) { ?> <div class="element-select"> <span></span> <?php echo ThemexInterface::renderOption(array('id' => $field['name'], 'type' => $field['type'], 'options' => themex_array('options', $field), 'value' => esc_attr(ThemexUser::$data['current']['profile']['billing_country']), 'wrap' => false)); ?> </div> <?php } else { ?> <div class="field-wrap"> <input type="text" name="<?php echo esc_attr($field['name']); ?> " value="<?php echo esc_attr(ThemexUser::$data['current']['profile'][$field['name']]); ?> " /> </div> <?php
<div class="element-select"> <span></span> <?php echo ThemexInterface::renderOption(array('id' => 'local_delivery_availability', 'type' => 'select', 'options' => array('all' => __('All Countries', 'makery'), 'specific' => __('Specific Countries', 'makery')), 'attributes' => array('class' => 'element-trigger'), 'value' => themex_value('availability', $shipping['local_delivery'], 'all'), 'wrap' => false)); ?> </div> </td> </tr> <tr class="trigger-local-delivery-availability-specific"> <th><?php _e('Countries', 'makery'); ?> </th> <td> <?php echo ThemexInterface::renderOption(array('id' => 'local_delivery_countries[]', 'type' => 'select', 'options' => ThemexWoo::getShippingCountries(), 'value' => themex_array('countries', $shipping['local_delivery']), 'wrap' => false, 'attributes' => array('class' => 'element-chosen', 'multiple' => 'multiple', 'data-placeholder' => __('Select Options', 'makery')))); ?> </td> </tr> <tr> <th><?php _e('Cost', 'makery'); ?> </th> <td> <div class="field-wrap"> <input type="text" name="local_delivery_cost" value="<?php echo ThemexWoo::formatPrice(themex_value('cost', $shipping['local_delivery'], '0')); ?> " /> </div>
<td><?php _e('All Classes', 'makery'); ?> </td> <td> <div class="field-wrap"> <input type="text" name="flat_rate_default_cost" value="<?php echo themex_value('default_cost', $shipping['flat_rate'], '0'); ?> " /> </div> </td> </tr> <?php $classes = ThemexWoo::getShippingClasses(); $costs = themex_array('costs', $shipping['flat_rate']); foreach ($classes as $index => $class) { ?> <tr> <td><?php echo $class->name; ?> </td> <td> <div class="field-wrap"> <input type="text" name="flat_rate_cost[<?php echo $index; ?> ]" value="<?php echo themex_value($class->slug, $costs, '0'); ?>