function hocwp_meta_box_side_image($args = array()) { global $pagenow; if ('post-new.php' == $pagenow || 'post.php' == $pagenow) { $id = hocwp_get_value_by_key($args, 'id', 'secondary_image_box'); $title = hocwp_get_value_by_key($args, 'title', __('Secondary Image', 'hocwp-theme')); $post_types = hocwp_get_value_by_key($args, 'post_type'); if ('all' == $post_types) { $post_types = array(); $types = get_post_types(array('public' => true), 'objects'); hocwp_exclude_special_post_types($types); foreach ($types as $key => $object_type) { $post_types[] = $key; } } $post_types = hocwp_sanitize_array($post_types); $field_id = hocwp_get_value_by_key($args, 'field_id', 'secondary_image'); $post_types = apply_filters('hocwp_post_type_user_large_thumbnail', $post_types); if (!hocwp_array_has_value($post_types)) { return; } $meta = new HOCWP_Meta('post'); $meta->set_post_types($post_types); $meta->set_id($id); $meta->set_title($title); $meta->set_context('side'); $meta->set_priority('low'); $field_args = array('id' => $field_id, 'field_callback' => 'hocwp_field_media_upload_simple'); $field_name = hocwp_get_value_by_key($args, 'field_name', $field_id); $field_args['name'] = $field_name; $meta->add_field($field_args); $meta->init(); } }
public function widget($args, $instance) { $this->instance = $instance; $order = hocwp_get_value_by_key($instance, 'order', hocwp_get_value_by_key($this->args, 'order')); $orders = explode(',', $order); $orders = array_map('trim', $orders); $orders = hocwp_sanitize_array($orders); $option_names = $this->args['option_names']; $options = hocwp_get_option('option_social'); $icons = $this->args['icons']; $description = hocwp_get_value_by_key($instance, 'description'); hocwp_widget_before($args, $instance); ob_start(); if (!empty($description)) { echo hocwp_wrap_tag(wpautop($description), 'div', 'description'); } if (hocwp_array_has_value($orders)) { foreach ($orders as $social) { $option_name = hocwp_get_value_by_key($option_names, $social); $item = hocwp_get_value_by_key($options, $option_name); if (!empty($item)) { $icon = '<i class="fa ' . $icons[$social] . '"></i>'; $a = new HOCWP_HTML('a'); $a->set_href($item); $a->set_class('social-item link-' . $social); $a->set_text($icon); $a->output(); } } } $widget_html = ob_get_clean(); $widget_html = apply_filters('hocwp_widget_social_html', $widget_html, $args, $instance, $this); echo $widget_html; hocwp_widget_after($args, $instance); }
public function form($instance) { $this->instance = $instance; $title = isset($instance['title']) ? $instance['title'] : ''; $category = $this->get_category_from_instance($instance); hocwp_field_widget_before($this->admin_args['class']); hocwp_widget_field_title($this->get_field_id('title'), $this->get_field_name('title'), $title); $all_option = ''; $lists = hocwp_get_terms('link_category'); foreach ($lists as $lvalue) { $selected = ''; if (!hocwp_array_has_value($category)) { $category[] = array('value' => ''); } foreach ($category as $ptvalue) { $ptype = isset($ptvalue['value']) ? $ptvalue['value'] : ''; if ($lvalue->term_id == $ptype) { $selected = $lvalue->term_id; break; } } $all_option .= hocwp_field_get_option(array('value' => $lvalue->term_id, 'text' => $lvalue->name, 'selected' => $selected)); } $args = array('id' => $this->get_field_id('category'), 'name' => $this->get_field_name('category'), 'all_option' => $all_option, 'value' => $category, 'label' => __('Category:', 'hocwp-theme'), 'placeholder' => __('Choose category', 'hocwp-theme'), 'multiple' => true); hocwp_widget_field('hocwp_field_select_chosen', $args); hocwp_field_widget_after(); }
function hocwp_option_home_setting_defaults() { $alls = hocwp_option_defaults(); $defaults = hocwp_get_value_by_key($alls, 'home_setting'); if (!hocwp_array_has_value($defaults)) { $defaults = array('recent_posts' => 1, 'posts_per_page' => hocwp_get_posts_per_page(), 'pagination' => 1); } return apply_filters('hocwp_option_home_setting_defaults', $defaults); }
function hocwp_option_theme_setting_defaults() { $alls = hocwp_option_defaults(); $defaults = hocwp_get_value_by_key($alls, 'theme_setting'); if (!hocwp_array_has_value($defaults)) { $defaults = array('language' => 'vi'); } return apply_filters('hocwp_option_theme_setting_defaults', $defaults); }
function hocwp_option_utilities_defaults() { $alls = hocwp_option_defaults(); $defaults = hocwp_get_value_by_key($alls, 'utilities'); if (!hocwp_array_has_value($defaults)) { $defaults = array('link_manager' => 0, 'dashboard_widget' => 1, 'force_admin_english' => 1); } return apply_filters('hocwp_option_utilities_defaults', $defaults); }
function hocwp_option_optimize_defaults() { $alls = hocwp_option_defaults(); $defaults = hocwp_get_value_by_key($alls, 'optimize'); if (!hocwp_array_has_value($defaults)) { $defaults = array('use_jquery_cdn' => 1, 'use_bootstrap_cdn' => 1, 'use_fontawesome_cdn' => 1, 'use_superfish_cdn' => 1); } return apply_filters('hocwp_option_optimize_defaults', $defaults); }
function hocwp_option_reading_defaults() { $alls = hocwp_option_defaults(); $defaults = hocwp_get_value_by_key($alls, 'reading'); if (!hocwp_array_has_value($defaults)) { $defaults = array('statistics' => 0, 'trending' => 0, 'search_tracking' => 0, 'enlarge_thumbnail' => 0, 'excerpt_length' => 75, 'post_statistics' => 0, 'sticky_widget' => 0, 'redirect_404' => 0, 'breadcrumb_label' => '', 'disable_post_title_breadcrumb' => 0, 'link_last_item_breadcrumb' => 0, 'go_to_top' => 0, 'go_to_top_on_left' => 0, 'scroll_top_icon' => '', 'content_none_title' => '', 'thumbnail_image_sizes' => array(), 'products_per_page' => hocwp_get_product_posts_per_page()); } return apply_filters('hocwp_option_reading_defaults', $defaults); }
function hocwp_option_theme_custom_defaults() { $alls = hocwp_option_defaults(); $defaults = hocwp_get_value_by_key($alls, 'theme_custom'); if (!hocwp_array_has_value($defaults)) { $defaults = array('background_lazyload' => 0); } return apply_filters('hocwp_option_theme_custom_defaults', $defaults); }
function hocwp_plugin_upgrader_process_complete($upgrader, $options) { $plugins = hocwp_get_value_by_key($options, 'plugins'); if (!hocwp_array_has_value($plugins)) { return; } foreach ($plugins as $plugin) { $slug = hocwp_get_plugin_slug_from_file_path($plugin); $transient_name = 'hocwp_plugins_api_' . $slug . '_plugin_information'; $transient_name = hocwp_sanitize_id($transient_name); delete_transient($transient_name); } }
function hocwp_video_source_meta_box($post_types = array()) { if (!hocwp_array_has_value($post_types)) { $post_types[] = 'post'; } $meta = new HOCWP_Meta('post'); $meta->set_post_types($post_types); $meta->set_title(__('Video Source Information', 'hocwp-theme')); $meta->set_id('hocwp_theme_video_source_information'); $meta->add_field(array('field_args' => array('id' => 'video_url', 'label' => 'Video URL:'))); $meta->add_field(array('field_args' => array('id' => 'video_code', 'label' => 'Video code:'), 'field_callback' => 'hocwp_field_textarea')); $meta->init(); }
public function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = strip_tags(hocwp_get_value_by_key($new_instance, 'title')); $instance['fields'] = $this->get_value_fields($new_instance); $all_fields = explode(',', $instance['fields']); foreach ($all_fields as $field_name) { $field = hocwp_get_value_by_key($this->args['fields'], $field_name); if (hocwp_array_has_value($field)) { foreach ($field as $key => $data) { $real_name = 'subscribe_' . $field_name . '_' . $key; $instance[$real_name] = $this->get_value_field($new_instance, $field_name, $key); } } } $instance['button_text'] = hocwp_get_value_by_key($new_instance, 'button_text', hocwp_get_value_by_key($this->args, 'button_text')); $instance['description'] = hocwp_get_value_by_key($new_instance, 'description', hocwp_get_value_by_key($this->args, 'description')); $instance['desc_position'] = hocwp_get_value_by_key($new_instance, 'desc_position', $this->args['desc_position']); $instance['captcha'] = hocwp_checkbox_post_data_value($new_instance, 'captcha'); $instance['captcha_label'] = hocwp_get_value_by_key($new_instance, 'captcha_label', hocwp_get_value_by_key($this->args, 'captcha_label')); $instance['captcha_placeholder'] = hocwp_get_value_by_key($new_instance, 'captcha_placeholder', hocwp_get_value_by_key($this->args, 'captcha_placeholder')); $instance['register'] = hocwp_checkbox_post_data_value($new_instance, 'register'); return $instance; }
function hocwp_theme_option_sidebar_tab() { global $hocwp_tos_tabs; if (hocwp_array_has_value($hocwp_tos_tabs)) { $current_page = hocwp_get_current_admin_page(); ?> <ul class="list-tabs"> <?php foreach ($hocwp_tos_tabs as $key => $value) { ?> <?php $admin_url = admin_url('admin.php'); $admin_url = add_query_arg(array('page' => $key), $admin_url); $item_class = hocwp_sanitize_html_class($key); if ($key == $current_page) { hocwp_add_string_with_space_before($item_class, 'active'); $admin_url = 'javascript:;'; } $text = hocwp_get_value_by_key($value, 'text'); if (empty($text)) { continue; } ?> <li class="<?php echo $item_class; ?> "><a href="<?php echo $admin_url; ?> "><span><?php echo $text; ?> </span></a></li> <?php } ?> </ul> <?php } }
function hocwp_term_meta_different_name_field($taxonomies = array()) { global $pagenow; if ('edit-tags.php' == $pagenow || 'term.php' == $pagenow) { if (!hocwp_array_has_value($taxonomies)) { $taxonomies = get_taxonomies(array('public' => true)); } $taxonomies = apply_filters('hocwp_term_different_name_field_taxonomies', $taxonomies); hocwp_exclude_special_taxonomies($taxonomies); if (!hocwp_array_has_value($taxonomies)) { $taxonomies = array('category'); } $meta = new HOCWP_Meta('term'); $meta->set_taxonomies($taxonomies); $meta->add_field(array('id' => 'different_name', 'label' => __('Different Name', 'hocwp-theme'))); $meta->init(); } }
public function widget($args, $instance) { $this->instance = $instance; $number = hocwp_get_value_by_key($instance, 'number', hocwp_get_value_by_key($this->args, 'number')); $time = hocwp_get_value_by_key($instance, 'time', hocwp_get_value_by_key($this->args, 'time')); $exclude_users = hocwp_get_value_by_key($instance, 'exclude_users'); $exclude_users = hocwp_json_string_to_array($exclude_users); $show_count = hocwp_get_value_by_key($instance, 'show_count', hocwp_get_value_by_key($this->args, 'show_count')); $link_author_name = hocwp_get_value_by_key($instance, 'link_author_name', hocwp_get_value_by_key($this->args, 'link_author_name')); $none_text = hocwp_get_value_by_key($instance, 'none_text', hocwp_get_value_by_key($this->args, 'none_text')); hocwp_widget_before($args, $instance); $condition = ''; if (hocwp_array_has_value($exclude_users)) { $not_in = array(); foreach ($exclude_users as $data) { $uid = hocwp_get_value_by_key($data, 'value'); if (hocwp_id_number_valid($uid)) { $not_in[] = $uid; } } if (hocwp_array_has_value($not_in)) { $condition = 'AND user_id NOT IN (' . implode(', ', $not_in) . ')'; } } $commenters = hocwp_get_top_commenters($number, $time, $condition); ob_start(); if (!hocwp_array_has_value($commenters)) { echo wpautop($none_text); } else { ?> <ol class="list-commenters"> <?php foreach ($commenters as $commenter) { $url = $commenter->comment_author_url; $author = $commenter->comment_author; $count = absint($commenter->comments_count); $email = $commenter->comment_author_email; $user_id = 0; if (!empty($commenter->user_id)) { $user_id = $commenter->user_id; } if ((bool) $show_count) { $author .= " ({$count})"; } if (empty($url) || 'http://' == $url || !(bool) $link_author_name) { $url = $author; } else { $url = "<a href='{$url}' rel='external nofollow' class='url'>{$author}</a>"; } ?> <li class="commenter"><?php echo $url; ?> </li> <?php } ?> </ol> <?php } $widget_html = ob_get_clean(); $widget_html = apply_filters('hocwp_widget_top_commenter_html', $widget_html, $args, $instance, $this); echo $widget_html; hocwp_widget_after($args, $instance); }
function hocwp_setup_theme_save_post_meta_hook($post_id) { if (!hocwp_can_save_post($post_id)) { return $post_id; } $post = get_post($post_id); $post_type = $post->post_type; global $hocwp_metas; if (hocwp_array_has_value($hocwp_metas)) { foreach ($hocwp_metas as $meta) { if ('post' == $meta->get_type()) { $post_types = $meta->get_post_types(); $fields = $meta->get_fields(); foreach ($fields as $field) { $meta->save_post_meta_helper($post_id, $field); } $fields = $meta->get_custom_fields(); if (is_array($fields)) { foreach ($fields as $field) { $meta->save_post_meta_helper($post_id, $field); } } } } } $value = isset($_POST['featured']) ? 1 : 0; update_post_meta($post_id, 'featured', $value); $value = isset($_POST['active']) ? 1 : 0; update_post_meta($post_id, 'active', $value); if ('hocwp_subscriber' == $post->post_type) { update_post_meta($post_id, 'subscriber_verified', $value); } switch ($post_type) { case 'hocwp_sidebar': if (isset($_POST['sidebar_id'])) { update_post_meta($post_id, 'sidebar_id', hocwp_sanitize_id($_POST['sidebar_id'])); } if (isset($_POST['sidebar_name'])) { update_post_meta($post_id, 'sidebar_name', sanitize_text_field($_POST['sidebar_name'])); } if (isset($_POST['sidebar_description'])) { update_post_meta($post_id, 'sidebar_description', sanitize_text_field($_POST['sidebar_description'])); } if (isset($_POST['sidebar_tag'])) { update_post_meta($post_id, 'sidebar_tag', sanitize_text_field($_POST['sidebar_tag'])); } break; case 'hocwp_slider': if (isset($_POST['slider_items'])) { update_post_meta($post_id, 'slider_items', $_POST['slider_items']); } if (isset($_POST['position'])) { update_post_meta($post_id, 'position', $_POST['position']); } $fit_width = hocwp_get_method_value('fit_width'); update_post_meta($post_id, 'fit_width', $fit_width); if (isset($_POST['height'])) { update_post_meta($post_id, 'height', $_POST['height']); } break; case 'hocwp_ads': if (isset($_POST['position'])) { update_post_meta($post_id, 'position', $_POST['position']); } if (isset($_POST['expire'])) { update_post_meta($post_id, 'expire', strtotime($_POST['expire'])); } if (isset($_POST['code'])) { update_post_meta($post_id, 'code', $_POST['code']); } $image = hocwp_get_method_value('image'); update_post_meta($post_id, 'image', $image); $url = hocwp_get_method_value('url'); update_post_meta($post_id, 'url', $url); break; case 'hocwp_subscriber': if (isset($_POST['subscriber_name'])) { update_post_meta($post_id, 'subscriber_name', sanitize_text_field($_POST['subscriber_name'])); } if (isset($_POST['subscriber_phone'])) { update_post_meta($post_id, 'subscriber_phone', sanitize_text_field($_POST['subscriber_phone'])); } break; case 'coupon': if (isset($_POST['expired_date'])) { update_post_meta($post_id, 'expired_date', strtotime($_POST['expired_date'])); } break; case 'product': $args = array('posts_per_page' => -1, 'post_type' => 'hocwp_product_tab'); $query = hocwp_query($args); if ($query->have_posts()) { foreach ($query->posts as $product) { $field_name = hocwp_sanitize_id($product->post_name); if (isset($_POST[$field_name])) { update_post_meta($post_id, $field_name, $_POST[$field_name]); } } } break; case 'partner': if (isset($_POST['url'])) { update_post_meta($post_id, 'url', esc_url($_POST['url'])); } if (isset($_POST['thumbnail'])) { update_post_meta($post_id, 'thumbnail', $_POST['thumbnail']); } break; } return $post_id; }
public function form($instance) { $this->instance = $instance; $title = hocwp_get_value_by_key($instance, 'title'); $post_type = $this->get_post_type_from_instance($instance); $number = hocwp_get_value_by_key($instance, 'number', hocwp_get_value_by_key($this->args, 'number')); $by = hocwp_get_value_by_key($instance, 'by', hocwp_get_value_by_key($this->args, 'by')); $category = hocwp_get_value_by_key($instance, 'category', json_encode(hocwp_get_value_by_key($this->args, 'category'))); $category = hocwp_json_string_to_array($category); $thumbnail_size = hocwp_get_value_by_key($instance, 'thumbnail_size', hocwp_get_value_by_key($this->args, 'thumbnail_size')); $full_width_post = hocwp_get_value_by_key($instance, 'full_width_post', hocwp_get_value_by_key($this->args, 'full_width_post')); $title_length = hocwp_get_value_by_key($instance, 'title_length', hocwp_get_value_by_key($this->args, 'title_length')); $excerpt_length = hocwp_get_value_by_key($instance, 'excerpt_length', hocwp_get_value_by_key($this->args, 'excerpt_length')); $hide_thumbnail = hocwp_get_value_by_key($instance, 'hide_thumbnail', hocwp_get_value_by_key($this->args, 'hide_thumbnail')); $widget_title_link_category = hocwp_get_value_by_key($instance, 'widget_title_link_category', hocwp_get_value_by_key($this->args, 'widget_title_link_category')); $category_as_widget_title = hocwp_get_value_by_key($instance, 'category_as_widget_title', hocwp_get_value_by_key($this->args, 'category_as_widget_title')); hocwp_field_widget_before($this->admin_args['class']); hocwp_widget_field_title($this->get_field_id('title'), $this->get_field_name('title'), $title); $lists = get_post_types(array('_builtin' => false, 'public' => true), 'objects'); if (!array_key_exists('post', $lists)) { $lists[] = get_post_type_object('post'); } $all_option = ''; foreach ($lists as $lvalue) { $selected = ''; if (!hocwp_array_has_value($post_type)) { $post_type[] = array('value' => 'post'); } foreach ($post_type as $ptvalue) { $ptype = isset($ptvalue['value']) ? $ptvalue['value'] : ''; if ($lvalue->name == $ptype) { $selected = $lvalue->name; break; } } $all_option .= hocwp_field_get_option(array('value' => $lvalue->name, 'text' => $lvalue->labels->singular_name, 'selected' => $selected)); } $args = array('id' => $this->get_field_id('post_type'), 'name' => $this->get_field_name('post_type'), 'all_option' => $all_option, 'value' => $post_type, 'label' => __('Post type:', 'hocwp-theme'), 'placeholder' => __('Choose post types', 'hocwp-theme'), 'multiple' => true); hocwp_widget_field('hocwp_field_select_chosen', $args); $args = array('id' => $this->get_field_id('number'), 'name' => $this->get_field_name('number'), 'value' => $number, 'label' => __('Number posts:', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_number', $args); $lists = $this->args['bys']; $all_option = ''; foreach ($lists as $lkey => $lvalue) { $all_option .= hocwp_field_get_option(array('value' => $lkey, 'text' => $lvalue, 'selected' => $by)); } $args = array('id' => $this->get_field_id('by'), 'name' => $this->get_field_name('by'), 'value' => $by, 'all_option' => $all_option, 'label' => __('Get by:', 'hocwp-theme'), 'class' => 'get-by'); hocwp_widget_field('hocwp_field_select', $args); $all_option = ''; $taxonomies = hocwp_get_hierarchical_taxonomies(); foreach ($taxonomies as $tkey => $tax) { $lists = hocwp_get_hierarchical_terms(array($tkey)); if (hocwp_array_has_value($lists)) { $all_option .= '<optgroup label="' . $tax->labels->singular_name . '">'; foreach ($lists as $lvalue) { $selected = ''; if (hocwp_array_has_value($category)) { foreach ($category as $cvalue) { $term_id = isset($cvalue['value']) ? $cvalue['value'] : 0; if ($lvalue->term_id == $term_id) { $selected = $lvalue->term_id; break; } } } $all_option .= hocwp_field_get_option(array('value' => $lvalue->term_id, 'text' => $lvalue->name, 'selected' => $selected, 'attributes' => array('data-taxonomy' => $tkey))); } $all_option .= '</optgroup>'; } } $args = array('id' => $this->get_field_id('category'), 'name' => $this->get_field_name('category'), 'all_option' => $all_option, 'value' => $category, 'label' => __('Category:', 'hocwp-theme'), 'placeholder' => __('Choose terms', 'hocwp-theme'), 'multiple' => true, 'class' => 'select-category'); if ('category' != $by) { $args['hidden'] = true; } hocwp_widget_field('hocwp_field_select_chosen', $args); $args = array('id_width' => $this->get_field_id('thumbnail_size_width'), 'name_width' => $this->get_field_name('thumbnail_size_width'), 'id_height' => $this->get_field_id('thumbnail_size_height'), 'name_height' => $this->get_field_name('thumbnail_size_height'), 'value' => $thumbnail_size, 'label' => __('Thumbnail size:', 'hocwp-theme')); hocwp_widget_field('hocwp_field_size', $args); $lists = $this->args['full_width_posts']; $all_option = ''; foreach ($lists as $lkey => $lvalue) { $all_option .= hocwp_field_get_option(array('value' => $lkey, 'text' => $lvalue, 'selected' => $full_width_post)); } $args = array('id' => $this->get_field_id('full_width_post'), 'name' => $this->get_field_name('full_width_post'), 'value' => $full_width_post, 'all_option' => $all_option, 'label' => __('Full width posts:', 'hocwp-theme'), 'class' => 'full-width-post'); hocwp_widget_field('hocwp_field_select', $args); $args = array('id' => $this->get_field_id('title_length'), 'name' => $this->get_field_name('title_length'), 'value' => $title_length, 'label' => __('Title length:', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_number', $args); $args = array('id' => $this->get_field_id('excerpt_length'), 'name' => $this->get_field_name('excerpt_length'), 'value' => $excerpt_length, 'label' => __('Excerpt length:', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_number', $args); $slider = hocwp_get_value_by_key($instance, 'slider', hocwp_get_value_by_key($this->args, 'slider')); $args = array('id' => $this->get_field_id('slider'), 'name' => $this->get_field_name('slider'), 'value' => $slider, 'label' => __('Display post as slider?', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_checkbox', $args); $args = array('id' => $this->get_field_id('hide_thumbnail'), 'name' => $this->get_field_name('hide_thumbnail'), 'value' => $hide_thumbnail, 'label' => __('Hide post thumbnail?', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_checkbox', $args); $args = array('id' => $this->get_field_id('widget_title_link_category'), 'name' => $this->get_field_name('widget_title_link_category'), 'value' => $widget_title_link_category, 'label' => __('Link widget title with category?', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_checkbox', $args); $args = array('id' => $this->get_field_id('category_as_widget_title'), 'name' => $this->get_field_name('category_as_widget_title'), 'value' => $category_as_widget_title, 'label' => __('Display category name as widget title?', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_checkbox', $args); hocwp_field_widget_after(); }
public function form($instance) { $this->instance = $instance; $title = hocwp_get_value_by_key($instance, 'title'); $taxonomy = $this->get_taxonomy_from_instance($instance); $number = hocwp_get_value_by_key($instance, 'number', hocwp_get_value_by_key($this->args, 'number')); $thumbnail_size = hocwp_get_value_by_key($instance, 'thumbnail_size', hocwp_get_value_by_key($this->args, 'thumbnail_size')); $full_width_item = hocwp_get_value_by_key($instance, 'full_width_item', hocwp_get_value_by_key($this->args, 'full_width_item')); $count_format = hocwp_get_value_by_key($instance, 'count_format', hocwp_get_value_by_key($this->args, 'count_format')); $show_count = hocwp_get_value_by_key($instance, 'show_count', hocwp_get_value_by_key($this->args, 'show_count')); $hide_thumbnail = hocwp_get_value_by_key($instance, 'hide_thumbnail', hocwp_get_value_by_key($this->args, 'hide_thumbnail')); $only_thumbnail = hocwp_get_value_by_key($instance, 'only_thumbnail', hocwp_get_value_by_key($this->args, 'only_thumbnail')); $order = hocwp_get_value_by_key($instance, 'order', hocwp_get_value_by_key($this->args, 'order')); $orderby = hocwp_get_value_by_key($instance, 'orderby', hocwp_get_value_by_key($this->args, 'orderby')); $different_name = (bool) hocwp_get_value_by_key($instance, 'different_name', hocwp_get_value_by_key($this->args, 'different_name')); $in_current_post = (bool) hocwp_get_value_by_key($instance, 'in_current_post', hocwp_get_value_by_key($this->args, 'in_current_post')); $hide_empty = hocwp_get_value_by_key($instance, 'hide_empty', hocwp_get_value_by_key($this->args, 'hide_empty')); $only_parent = hocwp_get_value_by_key($instance, 'only_parent', hocwp_get_value_by_key($this->args, 'only_parent')); $child_of_current = hocwp_get_value_by_key($instance, 'child_of_current', hocwp_get_value_by_key($this->args, 'child_of_current')); $child_of_parent = hocwp_get_value_by_key($instance, 'child_of_parent', hocwp_get_value_by_key($this->args, 'child_of_parent')); $parent_as_title = hocwp_get_value_by_key($instance, 'parent_as_title', hocwp_get_value_by_key($this->args, 'parent_as_title')); hocwp_field_widget_before($this->admin_args['class']); hocwp_widget_field_title($this->get_field_id('title'), $this->get_field_name('title'), $title); $lists = get_taxonomies(array('_builtin' => false, 'public' => true), 'objects'); if (!array_key_exists('post_tag', $lists)) { array_unshift($lists, get_taxonomy('post_tag')); } if (!array_key_exists('category', $lists)) { array_unshift($lists, get_taxonomy('category')); } $all_option = ''; foreach ($lists as $lvalue) { $selected = ''; if (!hocwp_array_has_value($taxonomy)) { $taxonomy[] = array('value' => 'category'); } foreach ($taxonomy as $ptvalue) { $ptype = isset($ptvalue['value']) ? $ptvalue['value'] : ''; if ($lvalue->name == $ptype) { $selected = $lvalue->name; break; } } $all_option .= hocwp_field_get_option(array('value' => $lvalue->name, 'text' => $lvalue->labels->singular_name, 'selected' => $selected)); } $args = array('id' => $this->get_field_id('taxonomy'), 'name' => $this->get_field_name('taxonomy'), 'all_option' => $all_option, 'value' => $taxonomy, 'label' => __('Taxonomy:', 'hocwp-theme'), 'placeholder' => __('Choose taxonomy', 'hocwp-theme'), 'multiple' => true); hocwp_widget_field('hocwp_field_select_chosen', $args); $args = array('id' => $this->get_field_id('number'), 'name' => $this->get_field_name('number'), 'value' => $number, 'label' => __('Number items:', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_number', $args); $lists = $this->args['orderbys']; $all_option = ''; foreach ($lists as $lkey => $lvalue) { $all_option .= hocwp_field_get_option(array('value' => $lkey, 'text' => $lvalue, 'selected' => $orderby)); } $args = array('id' => $this->get_field_id('orderby'), 'name' => $this->get_field_name('orderby'), 'value' => $orderby, 'all_option' => $all_option, 'label' => __('Order by:', 'hocwp-theme'), 'class' => 'orderby'); hocwp_widget_field('hocwp_field_select', $args); $lists = $this->args['orders']; $all_option = ''; foreach ($lists as $lkey => $lvalue) { $all_option .= hocwp_field_get_option(array('value' => strtolower($lvalue), 'text' => strtoupper($lvalue), 'selected' => $order)); } $args = array('id' => $this->get_field_id('order'), 'name' => $this->get_field_name('order'), 'value' => $order, 'all_option' => $all_option, 'label' => __('Order:', 'hocwp-theme'), 'class' => 'order'); hocwp_widget_field('hocwp_field_select', $args); $args = array('id_width' => $this->get_field_id('thumbnail_size_width'), 'name_width' => $this->get_field_name('thumbnail_size_width'), 'id_height' => $this->get_field_id('thumbnail_size_height'), 'name_height' => $this->get_field_name('thumbnail_size_height'), 'value' => $thumbnail_size, 'label' => __('Thumbnail size:', 'hocwp-theme')); hocwp_widget_field('hocwp_field_size', $args); $lists = $this->args['full_width_items']; $all_option = ''; foreach ($lists as $lkey => $lvalue) { $all_option .= hocwp_field_get_option(array('value' => $lkey, 'text' => $lvalue, 'selected' => $full_width_item)); } $args = array('id' => $this->get_field_id('full_width_item'), 'name' => $this->get_field_name('full_width_item'), 'value' => $full_width_item, 'all_option' => $all_option, 'label' => __('Full width items:', 'hocwp-theme'), 'class' => 'full-width-item'); hocwp_widget_field('hocwp_field_select', $args); $args = array('id' => $this->get_field_id('count_format'), 'name' => $this->get_field_name('count_format'), 'value' => $count_format, 'label' => __('Count format:', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input', $args); $args = array('id' => $this->get_field_id('hide_thumbnail'), 'name' => $this->get_field_name('hide_thumbnail'), 'value' => $hide_thumbnail, 'label' => __('Hide term thumbnail?', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_checkbox', $args); $args = array('id' => $this->get_field_id('show_count'), 'name' => $this->get_field_name('show_count'), 'value' => $show_count, 'label' => __('Show count?', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_checkbox', $args); $args = array('id' => $this->get_field_id('only_thumbnail'), 'name' => $this->get_field_name('only_thumbnail'), 'value' => $only_thumbnail, 'label' => __('Only thumbnail?', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_checkbox', $args); $args = array('id' => $this->get_field_id('different_name'), 'name' => $this->get_field_name('different_name'), 'value' => $different_name, 'label' => __('Use different term name?', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_checkbox', $args); $args = array('id' => $this->get_field_id('in_current_post'), 'name' => $this->get_field_name('in_current_post'), 'value' => $in_current_post, 'label' => __('Get term in current post?', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_checkbox', $args); $args = array('id' => $this->get_field_id('only_parent'), 'name' => $this->get_field_name('only_parent'), 'value' => $only_parent, 'label' => __('Show terms have no parent only?', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_checkbox', $args); $args = array('id' => $this->get_field_id('child_of_current'), 'name' => $this->get_field_name('child_of_current'), 'value' => $child_of_current, 'label' => __('Get all childs of current term?', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_checkbox', $args); $args = array('id' => $this->get_field_id('child_of_parent'), 'name' => $this->get_field_name('child_of_parent'), 'value' => $child_of_parent, 'label' => __('Get all childs of parent if current term has no child?', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_checkbox', $args); $args = array('id' => $this->get_field_id('parent_as_title'), 'name' => $this->get_field_name('parent_as_title'), 'value' => $parent_as_title, 'label' => __('Display parent term as widget title?', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_checkbox', $args); $args = array('id' => $this->get_field_id('hide_empty'), 'name' => $this->get_field_name('hide_empty'), 'value' => $hide_empty, 'label' => __('Hide term if it doesn\'t have post.', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_checkbox', $args); hocwp_field_widget_after(); }
function hocwp_change_nav_menu_css_class($terms, $classes, $item) { if (hocwp_array_has_value($terms)) { foreach ($terms as $term) { if ($term->term_id == $item->object_id) { $classes[] = 'current-menu-item'; break; } } } return $classes; }
public function default_field_callback($args) { $callback = isset($args['field_callback']) ? $args['field_callback'] : 'hocwp_field_input'; if (hocwp_callback_exists($callback)) { $name = isset($args['name']) ? hocwp_sanitize_array($args['name']) : array(); if (!hocwp_array_has_value($name)) { $name = isset($args['id']) ? hocwp_sanitize_array($args['id']) : array(); } if (!hocwp_array_has_value($name)) { _e('Please set name for this field.', 'hocwp-theme'); return; } $base_name = $name; unset($args['class']); if (!isset($args['value'])) { $default = hocwp_get_value_by_key($args, 'default'); $value = $this->get_by_key($name, $default); if (is_array($value) && 'hocwp_field_input' == $callback) { $value = ''; } $args['value'] = $value; } if ('hocwp_field_size' == $callback || 'hocwp_field_input_size' == $callback) { $tmp_name = $name; $tmp_name[] = 'width'; $args['name_width'] = $this->get_field_name($tmp_name); $args['id_width'] = $this->get_field_id($tmp_name); $tmp_name = $name; $tmp_name[] = 'height'; $args['name_height'] = $this->get_field_name($tmp_name); $args['id_height'] = $this->get_field_id($tmp_name); $tmp_sizes = $this->get_by_key($name, hocwp_get_value_by_key($args, 'default')); $sizes = array(); } $args['name'] = $this->get_field_name($name); $args['id'] = $this->get_field_id($name); $options = isset($args['options']) ? $args['options'] : array(); if (hocwp_array_has_value($options)) { $tmp_options = array(); foreach ($options as $option) { $name = isset($option['name']) ? hocwp_sanitize_array($option['name']) : array(); if (!hocwp_array_has_value($name)) { if (!empty($base_name)) { $name = hocwp_sanitize_array($base_name); } else { $name = isset($option['id']) ? hocwp_sanitize_array($option['id']) : array(); } } if (!hocwp_array_has_value($name)) { continue; } if (!isset($option['value'])) { $value = $this->get_by_key($name, hocwp_get_value_by_key($option, 'default')); if (is_array($value) && 'hocwp_field_input' == $callback) { $value = ''; } $option['value'] = $value; } $option['name'] = $this->get_field_name($name); $option['id'] = $this->get_field_id($name); $tmp_options[] = $option; } $args['options'] = $tmp_options; unset($tmp_options); } call_user_func($callback, $args); } else { _e('Please set a valid callback for this field.', 'hocwp-theme'); } }
public function check_from_server($args = array()) { $transient_name = hocwp_build_transient_name('hocwp_check_license_from_server_%s', $args); if (false === ($valid = get_transient($transient_name))) { $customer_email = hocwp_get_value_by_key($args, 'customer_email', hocwp_get_value_by_key($args, 'email', hocwp_get_admin_email())); if (!is_email($customer_email)) { $customer_email = hocwp_get_admin_email(); } $code = hocwp_get_value_by_key($args, 'license_code', hocwp_get_value_by_key($args, 'code')); $domain = hocwp_get_value_by_key($args, 'customer_domain', hocwp_get_value_by_key($args, 'domain', home_url())); $use_for = hocwp_get_value_by_key($args, 'use_for'); if (empty($domain)) { $domain = esc_url(hocwp_get_root_domain_name(home_url())); } $meta_item = array('relation' => 'AND', array('key' => 'customer_domain', 'value' => untrailingslashit(esc_url(hocwp_get_root_domain_name($domain)))), array('key' => 'forever_domain', 'value' => 1, 'type' => 'numeric')); if (hocwp_is_localhost()) { array_push($meta_item, array('key' => 'customer_email', 'value' => sanitize_email($customer_email))); } $data = hocwp_api_get_by_meta($meta_item, 'license-api'); if (hocwp_array_has_value($data)) { $valid = true; } else { $meta_item = array('relation' => 'AND', array('key' => 'customer_email', 'value' => sanitize_email($customer_email)), array('key' => 'forever_email', 'value' => 1, 'type' => 'numeric'), array('key' => 'use_for', 'value' => $use_for)); $data = hocwp_api_get_by_meta($meta_item, 'license-api'); if (hocwp_array_has_value($data)) { $valid = true; } else { $meta_item = array('relation' => 'AND', array('key' => 'customer_domain', 'value' => esc_url(untrailingslashit($domain))), array('key' => 'customer_email', 'value' => sanitize_email($customer_email)), array('key' => 'license_code', 'value' => $code), array('key' => 'use_for', 'value' => $use_for)); $data = hocwp_api_get_by_meta($meta_item, 'license-api'); if (hocwp_array_has_value($data)) { $valid = true; } } } set_transient($transient_name, $valid, 15 * MINUTE_IN_SECONDS); } $valid = (bool) $valid; return apply_filters('hocwp_check_license_on_server', $valid, $args); }
public function add_rewrite_rule($taxonomy_name, $tax_base, $wp_query_var, $query_var, $rules) { global $wp_rewrite; $new_rules = array(); $taxonomy = get_taxonomy($taxonomy_name); $permalink_structure = get_option('permalink_structure'); $blog_prefix = ''; if (is_multisite() && !is_subdomain_install() && is_main_site() && 0 === strpos($permalink_structure, '/blog/')) { $blog_prefix = 'blog/'; } $terms = hocwp_get_terms($taxonomy_name, array('hide_empty' => false)); if (hocwp_array_has_value($terms)) { foreach ($terms as $term) { $term_nicename = $term->slug; if ($term->parent == $term->cat_ID) { $term->parent = 0; } elseif ($taxonomy->rewrite['hierarchical'] != 0 && $term->parent != 0) { $parents = hocwp_get_term_parents($taxonomy_name, $term->parent, false, '/', true); if (!is_wp_error($parents)) { $term_nicename = $parents . $term_nicename; } unset($parents); } $new_rules[$blog_prefix . '(' . $term_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?' . $wp_query_var . '=$matches[1]&feed=$matches[2]'; $new_rules[$blog_prefix . '(' . $term_nicename . ')/' . $wp_rewrite->pagination_base . '/?([0-9]{1,})/?$'] = 'index.php?' . $wp_query_var . '=$matches[1]&paged=$matches[2]'; $new_rules[$blog_prefix . '(' . $term_nicename . ')/?$'] = 'index.php?' . $wp_query_var . '=$matches[1]'; } unset($terms, $term, $term_nicename); } $old_base = $wp_rewrite->get_extra_permastruct($taxonomy_name); $old_base = str_replace('%' . $tax_base . '%', '(.+)', $old_base); $old_base = trim($old_base, '/'); $new_rules[$old_base . '$'] = 'index.php?' . $query_var . '=$matches[1]'; if (hocwp_array_has_value($new_rules)) { $rules = $new_rules; } unset($new_rules, $old_base); return $rules; }
function hocwp_post_get_first_term($post_id = null, $taxonomy = 'category') { $post_id = hocwp_return_post($post_id, 'id'); $terms = wp_get_post_terms($post_id, $taxonomy); if (hocwp_array_has_value($terms)) { $terms = current($terms); } return $terms; }
public function save_post_meta_helper($post_id, $field) { $type = isset($field['type']) ? $field['type'] : hocwp_get_value_by_key($field, 'data_type', 'default'); $name = isset($field['field_args']['name']) ? $field['field_args']['name'] : ''; if (empty($name)) { $name = hocwp_get_value_by_key($field, 'name'); } if (empty($name)) { return; } $value = hocwp_sanitize_form_post($name, $type); update_post_meta($post_id, $name, $value); $names = hocwp_get_value_by_key($field, 'names'); if (hocwp_array_has_value($names)) { $names = array_combine($names, $names); foreach ($names as $child_name => $child) { $type = hocwp_get_value_by_key($child, 'type', hocwp_get_value_by_key($field, 'data_type', 'default')); $value = hocwp_sanitize_form_post($child_name, $type); update_post_meta($post_id, $child_name, $value); } } }
function hocwp_query_post_in_same_category($args = array()) { $post_id = absint(isset($args['post_id']) ? $args['post_id'] : get_the_ID()); $query = new WP_Query(); if (!hocwp_id_number_valid($post_id)) { return $query; } $cache = (bool) hocwp_get_value_by_key($args, 'cache', true); $transient_name = 'hocwp_query_post_' . $post_id . '_in_same_category_%s'; $transient_name = hocwp_build_transient_name($transient_name, $args); $query = get_transient($transient_name); if (!$cache || false === $query) { $taxonomies = get_post_taxonomies($post_id); foreach ($taxonomies as $key => $tax_name) { $taxonomy = get_taxonomy($tax_name); if (!$taxonomy->hierarchical) { unset($taxonomies[$key]); } } if (hocwp_array_has_value($taxonomies)) { $defaults = array(); foreach ($taxonomies as $taxonomy) { $term_ids = wp_get_post_terms($post_id, $taxonomy, array('fields' => 'ids')); if (hocwp_array_has_value($term_ids)) { $tax_item = array('taxonomy' => $taxonomy, 'field' => 'id', 'terms' => $term_ids); $defaults = hocwp_query_sanitize_tax_query($tax_item, $defaults); } } $args = wp_parse_args($args, $defaults); $args['tax_query']['relation'] = 'OR'; $query = hocwp_query($args); if ($cache && $query->have_posts()) { set_transient($transient_name, $query, DAY_IN_SECONDS); } } } return $query; }
function hocwp_notification_posts_ajax_callback() { $lists = get_option('hocwp_notification_posts'); $lists = hocwp_to_array($lists); if (hocwp_array_has_value($lists)) { $query = hocwp_get_post_by_meta('subscriber_verified', 1, array('post_type' => 'hocwp_subscriber')); if ($query->have_posts()) { $subscribers = $query->posts; $date = hocwp_get_current_date(); $transient_name = hocwp_build_transient_name('hocwp_notification_posts_table_%s', $date); if (false === ($table_content = get_transient($transient_name))) { $table = new HOCWP_HTML('table'); $table->set_attribute('align', 'center'); $table->set_attribute('width', '100%'); $table->set_attribute('cellspacing', 0); $table->set_attribute('border', 0); $table->set_attribute('cellpadding', 0); $table->set_attribute('bgcolor', '#ffffff'); $table_content = ''; foreach ($lists as $post_id) { $obj = get_post($post_id); $post_type = get_post_type_object($obj->post_type); if (!is_object($post_type) || !$post_type->public) { continue; } $notified = (bool) hocwp_get_post_meta('hocwp_notification_posts_sent', $post_id); if ($notified) { continue; } $inner_table = $table; $tbody = new HOCWP_HTML('tbody'); $tr = new HOCWP_HTML('tr'); $td = new HOCWP_HTML('td'); $td->set_attribute('style', 'font-size:1px;line-height:1px'); $tr->set_text($td); $tr2 = new HOCWP_HTML('tr'); $td2 = new HOCWP_HTML('td'); $td2->set_attribute('style', 'border-bottom:2px dotted #808285;padding-bottom:12px'); $a = new HOCWP_HTML('a'); $a->set_attribute('target', '_blank'); $a->set_href(get_permalink($obj)); $a->set_attribute('style', 'font-family: Helvetica,arial,sans-serif; font-size: 20px; color: rgb(22, 63, 144); text-align: left; font-weight: 500; text-decoration: none; line-height: 27px;'); $a->set_text(get_the_title($obj)); $p = new HOCWP_HTML('p'); $excerpt = get_the_excerpt($obj); if (empty($excerpt)) { $excerpt = $obj->post_content; $excerpt = strip_tags($excerpt); $excerpt = apply_filters('excerpt_length', $excerpt, 150); } $p->set_text($excerpt); $td2->set_text($a->build() . $p->build()); $tr2->set_text($td2); $tbody->set_text($tr->build() . $tr2->build()); $inner_table->set_text($tbody); $table_content .= $inner_table->build(); update_post_meta($post_id, 'hocwp_notification_posts_sent', 1); } if (!empty($table_content)) { $tbody = new HOCWP_HTML('tbody'); $tr = new HOCWP_HTML('tr'); $td = new HOCWP_HTML('td'); $td->set_text($table_content); $tr->set_text($td); $tbody->set_text($tr); $table->set_text($tbody); $table_content = $table->build(); } } if (!empty($table_content)) { foreach ($subscribers as $subscriber) { $email = hocwp_get_post_meta('subscriber_email', $subscriber->ID); if (is_email($email)) { $transient_name = 'hocwp_notification_posts_to_user_' . md5($email); $transient_name = hocwp_build_transient_name($transient_name . '_%s', $table_content); if (false === get_transient($transient_name)) { $subject = '[' . get_bloginfo('name') . '] New content updated on ' . hocwp_get_current_date(hocwp_get_date_format()); $message = $table_content; $message = hocwp_mail_unsubscribe_link_footer($message, $email); $sent = hocwp_send_html_mail($email, $subject, $message); if ($sent) { set_transient($transient_name, 1, DAY_IN_SECONDS); } } } } } } } exit; }
function hocwp_slider_html($args = array()) { if (!is_array($args)) { $position = $args; } else { $position = hocwp_get_value_by_key($args, 'position'); } $slider = hocwp_get_slider_by_position($position); if (hocwp_is_post($slider)) { $items = hocwp_get_post_meta('slider_items', $slider->ID); $order = hocwp_get_value_by_key($items, 'order'); if (!empty($order)) { $order = explode(',', $order); $items = hocwp_get_value_by_key($items, 'items'); $slider_class = 'hocwp-slider'; $thumbs = (bool) hocwp_get_value_by_key($args, 'thumbs', false); if ($thumbs) { hocwp_add_string_with_space_before($slider_class, 'thumbs-paging'); } hocwp_add_string_with_space_before($slider_class, hocwp_sanitize_html_class($position)); $custom_arrow = hocwp_get_value_by_key($args, 'custom_arrow'); if ($custom_arrow) { $slider_class = hocwp_add_more_class($slider_class, 'custom-arrow'); } $fit_width = hocwp_get_post_meta('fit_width', $slider->ID); $fit_width = hocwp_int_to_bool($fit_width); $height = hocwp_get_post_meta('height', $slider->ID); if (!hocwp_is_positive_number($height)) { $height = 350; } $atts = array('data-height="' . $height . '"'); if ($fit_width) { $atts[] = 'data-fit-width="1"'; } $atts = implode(' ', $atts); if (!empty($atts)) { $atts = ' ' . $atts; $atts = rtrim($atts); } echo '<div class="' . $slider_class . '">'; echo '<ul class="list-unstyled list-items slickslide list-inline"' . $atts . '>'; $list_paging = ''; $lazyload = hocwp_get_value_by_key($args, 'lazyload'); foreach ($order as $item_id) { $item = hocwp_get_value_by_key($items, $item_id); if (hocwp_array_has_value($item)) { $title = hocwp_get_value_by_key($item, 'title'); $link = hocwp_get_value_by_key($item, 'link'); $description = hocwp_get_value_by_key($item, 'description'); $image_url = hocwp_get_value_by_key($item, 'image_url'); $image_id = hocwp_get_value_by_key($item, 'image_id'); $image_url = hocwp_return_media_url($image_url, $image_id); $img = new HOCWP_HTML('img'); $img->set_image_src($image_url); $img->add_class('slider-image'); $li = new HOCWP_HTML('li'); $li->set_text($img); $li->add_class('slider-item'); if ($lazyload) { $li->add_class('lazyload'); $img->set_attribute('data-original', $image_url); $img->set_image_src(hocwp_get_image_url('transparent.gif')); } $list_paging .= $li->build(); if (!empty($link)) { $a = new HOCWP_HTML('a'); $a->set_href($link); $a->set_text($img); $li->set_text($a); } else { $li->set_text($img); } $li->output(); } } echo '</ul>'; if ($thumbs) { echo '<div class="thumbs-paging slick-thumbs">'; echo '<ul class="list-unstyled list-paging">'; echo $list_paging; echo '</ul>'; echo '</div>'; } echo '</div>'; } } }
function hocwp_translate_x_string_transaltion_update() { if (isset($_REQUEST['hocwp_action']) && 'string_translation' == $_REQUEST['hocwp_action']) { unset($_REQUEST['hocwp_action']); $search = hocwp_get_method_value('s', 'request'); $strings = hocwp_get_method_value('strings'); if (hocwp_array_has_value($strings)) { $mo = new HOCWP_MO(); $saved_strings = hocwp_get_registered_string_language(); foreach ($strings as $encrypted_string) { unset($saved_strings[$encrypted_string]); $mo->delete_from_db($encrypted_string, true); } update_option('hocwp_string_translations', $saved_strings); hocwp_delete_transient('hocwp_string_translation_registered'); } $args = array_intersect_key($_REQUEST, array_flip(array('s', 'paged', 'group'))); if (!empty($search)) { $args['s'] = $search; } if (!empty($args['s'])) { $args['s'] = urlencode($args['s']); } $translations = hocwp_get_method_value('translation'); if (hocwp_array_has_value($translations)) { foreach ($translations as $key => $value) { if (!empty($value)) { $mo = hocwp_get_post_by_column('post_title', 'hocwp_mo_' . $key, OBJECT, array('post_type' => 'hocwp_mo')); if (is_a($mo, 'WP_Post')) { $obj = new HOCWP_MO($mo->ID); $obj->export_to_db($mo->post_excerpt, $value); } } } } $url = add_query_arg($args, wp_get_referer()); wp_safe_redirect($url); exit; } }
function hocwp_shortcode_support_form_callback($atts = array(), $content = null) { $defaults = array('style' => '', 'name' => 'full_name,email,phone,message', 'label' => array(__('Full name', 'hocwp-theme'), __('Email', 'hocwp-theme'), __('Phone', 'hocwp-theme'), __('Message', 'hocwp-theme')), 'type' => 'text,email,text,textarea', 'placehoder' => '', 'captcha' => false, 'admin_email' => hocwp_get_admin_email()); $attributes = shortcode_atts($defaults, $atts); $name = hocwp_get_value_by_key($attributes, 'name'); $names = explode(',', $name); if (hocwp_array_has_value($names)) { $show_form = true; $label = hocwp_get_value_by_key($attributes, 'label'); if (!is_array($label)) { $label = explode(',', $label); $label = array_map('trim', $label); } $type = hocwp_get_value_by_key($attributes, 'type'); $type = explode(',', $type); $type = array_map('trim', $type); $placeholder = hocwp_get_value_by_key($attributes, 'placeholder'); if (!empty($placeholder)) { $placeholder = explode(',', $placeholder); $placeholder = array_map('trim', $placeholder); } $captcha = hocwp_get_value_by_key($attributes, 'captcha'); $names = array_map('trim', $names); $html = hocwp_shortcode_before('support-form', $attributes); if (isset($_POST['submit'])) { if (hocwp_check_nonce('hocwp_support_form')) { if (hocwp_check_captcha()) { $body = ''; foreach ($names as $index => $name) { if (empty($name)) { continue; } if ('name' == $name) { $name = 'full_name'; } $field_type = isset($type[$index]) ? $type[$index] : 'text'; $field_label = isset($label[$index]) ? $label[$index] : ''; $field_placeholder = isset($placeholder[$index]) ? $placeholder[$index] : ''; $row = isset($_POST[$name]) ? $_POST[$name] : ''; if (!empty($field_label)) { $last_char = hocwp_get_last_char($field_label); if (':' != $last_char) { $field_label .= ':'; } $row = $field_label . ' ' . $row; } if (!empty($row)) { $body .= wpautop($row); } } if (empty($body)) { $html .= hocwp_build_message(__('You must fill all required fields.', 'hocwp-theme'), 'danger'); } else { $full_name = __('Guest', 'hocwp-theme'); if (isset($_POST['full_name'])) { $full_name = $_POST['full_name']; } $subject = sprintf(__('[%1$s] Contact message from %2$s', 'hocwp-theme'), get_bloginfo('name'), $full_name); $admin_email = hocwp_get_value_by_key($attributes, 'admin_email'); if (!is_email($admin_email)) { $admin_email = hocwp_get_admin_email(); } $sent = hocwp_send_html_mail($admin_email, $subject, $body); if ($sent) { $show_form = false; $html .= hocwp_build_message(__('Your message has been sent, we will reply to you as soon as possible.', 'hocwp-theme'), 'success'); } else { $html .= hocwp_build_message(__('There was an error occurred, please try again or contact administrators.', 'hocwp-theme'), 'danger'); } } } else { $html .= hocwp_build_message(__('Captcha code is not valid.', 'hocwp-theme'), 'danger'); } } } if ($show_form) { ob_start(); ?> <form class="hocwp-support-form" action="" method="post"> <?php foreach ($names as $index => $name) { if (empty($name)) { continue; } if ('name' == $name) { $name = 'full_name'; } $field_type = isset($type[$index]) ? $type[$index] : 'text'; $field_label = isset($label[$index]) ? $label[$index] : ''; $field_placeholder = isset($placeholder[$index]) ? $placeholder[$index] : ''; ?> <div class="form-group form-row"> <div class="row"> <div class="col-sm-2"> <label for="<?php echo esc_attr($name); ?> "><?php echo $field_label; ?> </label> </div> <div class="col-sm-10"> <?php $value = isset($_POST[$name]) ? $_POST[$name] : ''; switch ($field_type) { case 'longtext': case 'textarea': ?> <textarea id="<?php echo esc_attr($name); ?> " name="<?php echo esc_attr($name); ?> " class="form-control" placeholder="<?php echo esc_attr($field_placeholder); ?> "><?php echo $value; ?> </textarea> <?php break; default: $input_type = 'text'; if ('email' == $field_type) { $input_type = 'email'; } ?> <input id="<?php echo esc_attr($name); ?> " placeholder="<?php echo esc_attr($field_placeholder); ?> " value="<?php echo esc_attr($value); ?> " name="<?php echo esc_attr($name); ?> " type="<?php echo esc_attr($input_type); ?> "> <?php } ?> </div> </div> </div> <?php } if ($captcha) { echo '<div class="form-group form-row"><div class="row"><div class="col-sm-2"></div><div class="col-sm-10">'; hocwp_field_captcha(array('input_width' => 180)); echo '</div></div></div>'; } ?> <div class="form-hidden-fields"> <?php hocwp_nonce('hocwp_support_form'); ?> </div> <div class="form-group form-row"> <div class="row"> <div class="col-sm-2"></div> <div class="col-sm-10"> <input type="submit" name="submit" class="btn btn-warning" value="<?php _e('Send', 'hocwp-theme'); ?> "> </div> </div> </div> </form> <?php $html .= ob_get_clean(); } $html .= hocwp_shortcode_after(); } return apply_filters('hocwp_shortcode_support_form', $html, $attributes, $content); }
public function license_valid() { $license = new HOCWP_License(); $license->set_type('plugin'); $license->set_use_for($this->basename); $license->set_option_name('hocwp_plugin_license'); $data = $this->license_data; if (!hocwp_array_has_value($data)) { $data = $this->license_data(); } $result = $license->check_valid($data); unset($license); return $result; }