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); }
function hocwp_theme_check_load_facebook_javascript_sdk($use) { $data = apply_filters('hocwp_load_facebook_javascript_sdk_on_page_sidebar', array()); foreach ($data as $value) { $conditional_functions = isset($value['condition']) ? $value['condition'] : ''; $conditional_functions = hocwp_sanitize_array($conditional_functions); $condition_result = false; foreach ($conditional_functions as $function) { if (!hocwp_callback_exists($function)) { continue; } if (call_user_func($function)) { $condition_result = true; break; } } $sidebar = isset($value['sidebar']) ? $value['sidebar'] : ''; $sidebars = hocwp_sanitize_array($sidebar); foreach ($sidebars as $sidebar) { if (is_active_sidebar($sidebar) && $condition_result && hocwp_sidebar_has_widget($sidebar, 'hocwp_widget_facebook_box')) { return true; } } } $comment_system = hocwp_theme_get_option('comment_system', 'discussion'); if ('facebook' == $comment_system || 'default_and_facebook' == $comment_system || 'tabs' == $comment_system) { if (is_singular()) { $post_id = get_the_ID(); if (comments_open($post_id) || get_comments_number($post_id)) { return true; } } } return $use; }
function hocwp_get_ads_positions() { global $hocwp_ads_positions; $hocwp_ads_positions = hocwp_sanitize_array($hocwp_ads_positions); $defaults = array('leaderboard' => array('id' => 'leaderboard', 'name' => __('Leaderboard', 'hocwp-theme'), 'description' => __('Display beside logo in header area.', 'hocwp-theme'))); $hocwp_ads_positions = wp_parse_args($hocwp_ads_positions, $defaults); return apply_filters('hocwp_ads_positions', $hocwp_ads_positions); }
function hocwp_the_social_list($args = array()) { $option_socials = hocwp_option_defaults(); $option_socials = $option_socials['social']; $order = hocwp_get_value_by_key($args, 'order', hocwp_get_value_by_key($option_socials, 'order')); $orders = explode(',', $order); $orders = array_map('trim', $orders); $orders = hocwp_sanitize_array($orders); $option_names = $option_socials['option_names']; $options = hocwp_get_option('option_social'); $icons = $option_socials['icons']; $list = (bool) hocwp_get_value_by_key($args, 'list'); if (hocwp_array_has_value($orders)) { if ($list) { echo '<ul class="list-socials list-unstyled list-inline">'; 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); $li = new HOCWP_HTML('li'); $li->set_text($a); $li->output(); } } echo '</ul>'; } else { 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(); } } } } }
function hocwp_meta_box_editor($args = array()) { global $pagenow; if ('post-new.php' == $pagenow || 'post.php' == $pagenow) { $post_type = hocwp_get_value_by_key($args, 'post_type'); if (!is_array($post_type)) { $post_type = array($post_type); } $box_title = hocwp_get_value_by_key($args, 'title', __('Additional Information', 'hocwp-theme')); $current_type = hocwp_get_current_post_type(); if (is_array($current_type)) { $current_type = current($current_type); } $box_id = hocwp_get_value_by_key($args, 'id'); if (empty($box_id)) { $box_id = hocwp_sanitize_id($box_title); if (empty($box_id)) { return; } } if (!empty($current_type)) { $box_id = $current_type . '_' . $box_id; } $field_args = hocwp_get_value_by_key($args, 'field_args', array()); $field_args = hocwp_sanitize_array($field_args); $field_args['field_callback'] = 'hocwp_field_editor'; $field_args['label'] = ''; $field_id = hocwp_get_value_by_key($args, 'field_id', hocwp_get_value_by_key($field_args, 'field_id')); $field_name = hocwp_get_value_by_key($args, 'field_name', hocwp_get_value_by_key($field_args, 'field_name')); hocwp_transmit_id_and_name($field_id, $field_name); if (empty($field_id)) { return; } $field_args['id'] = $field_id; $field_args['name'] = $field_name; $meta = new HOCWP_Meta('post'); $meta->set_title($box_title); $meta->set_id($box_id); $meta->set_post_types($post_type); $meta->add_field($field_args); $meta->init(); } }
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'); } }
function hocwp_get_post_by_column($column_name, $column_value, $output = 'OBJECT', $args = array()) { global $wpdb; $post_type = hocwp_get_value_by_key($args, 'post_type'); $post_types = hocwp_sanitize_array($post_type); $output = strtoupper($output); $sql = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE {$column_name} = %s", $column_value); $count_type = 0; foreach ($post_types as $post_type) { if (0 == $count_type) { $sql .= " AND post_type = '{$post_type}'"; } else { $sql .= " OR post_type = '{$post_type}'"; } $count_type++; } $post_id = $wpdb->get_var($sql); $result = ''; switch ($output) { case OBJECT: if (hocwp_id_number_valid($post_id)) { $result = get_post($post_id); } break; default: $result = $post_id; } return $result; }
public function add_post_type($post_type) { $this->post_types[] = $post_type; $this->set_post_types(hocwp_sanitize_array($this->get_post_types())); }
public function build_key_map() { $pieces = array(); $email = $this->get_customer_email(); $phone = $this->get_customer_phone(); $identity = $this->get_customer_identity(); if (empty($email) && empty($phone) && empty($identity)) { return $pieces; } if (!empty($email)) { $pieces[] = 'email'; } if (!empty($phone)) { $pieces[] = 'phone'; } if (!empty($identity)) { $pieces[] = 'identity'; } $pieces[] = 'code'; $pieces[] = 'domain'; $pieces[] = 'use_for'; shuffle($pieces); $pieces[] = 'hashed_password'; $pieces = hocwp_sanitize_array($pieces); $this->set_key_map($pieces); return $pieces; }
function hocwp_register_post_type_private($args = array()) { global $hocwp_private_post_types; $args['public'] = false; $args['exclude_from_search'] = true; $args['show_in_nav_menus'] = false; $args['show_in_admin_bar'] = false; $args['menu_position'] = 9999999; $args['has_archive'] = false; $args['query_var'] = false; $args['rewrite'] = false; $args['feeds'] = false; $slug = isset($args['slug']) ? $args['slug'] : ''; if (!empty($slug)) { $hocwp_private_post_types = hocwp_sanitize_array($hocwp_private_post_types); $hocwp_private_post_types[] = $slug; } hocwp_register_post_type($args); }
function hocwp_setup_theme_the_content($content) { $add_to_content = apply_filters('hocwp_add_to_the_content', false); if ($add_to_content) { $backup = $content; $delimiter = '</p>'; $paragrahps = explode($delimiter, $content); $count = 1; $custom = false; if (hocwp_array_has_value($paragrahps)) { $paragrahps = hocwp_sanitize_array($paragrahps); $count_p = count($paragrahps); foreach ($paragrahps as $key => $value) { if (trim($value)) { $paragrahps[$key] .= $delimiter; if (1 == $count) { $add = apply_filters('hocwp_add_to_the_content_after_first_paragraph', ''); if (!empty($add)) { $paragrahps[$key] .= $add; $custom = true; } } elseif (2 == $count) { $add = apply_filters('hocwp_add_to_the_content_after_second_paragraph', ''); if (!empty($add)) { $paragrahps[$key] .= $add; $custom = true; } } if ($count == $count_p - 1) { $add = apply_filters('hocwp_add_to_the_content_before_last_paragraph', ''); if (!empty($add)) { $paragrahps[$key] .= $add; $custom = true; } } $count++; } else { $count_p--; } } if ($custom) { $content = implode('', $paragrahps); } $content = apply_filters('hocwp_custom_the_content', $content, $backup); } } return $content; }
function hocwp_allow_role_upload_media($roles) { $roles = hocwp_sanitize_array($roles); $caps = array('upload_files', 'publish_pages', 'edit_published_pages', 'edit_others_pages'); foreach ($roles as $role) { $role = get_role($role); if (is_a($role, 'WP_Role')) { foreach ($caps as $cap) { $role->add_cap($cap); } } } }
function hocwp_theme_get_license_defined_data() { global $hocwp_theme_license_data; $hocwp_theme_license_data = hocwp_sanitize_array($hocwp_theme_license_data); return apply_filters('hocwp_theme_license_defined_data', $hocwp_theme_license_data); }
$option->add_field(array('id' => 'bold_first_paragraph', 'title' => __('Bold First Paragraph', 'hocwp-theme'), 'field_callback' => 'hocwp_field_input_checkbox', 'label' => __('Automatically bold first paragraph of content?', 'hocwp-theme'))); $option->add_field(array('id' => 'enlarge_thumbnail', 'title' => __('Enlarge Thumbnail', 'hocwp-theme'), 'field_callback' => 'hocwp_field_input_checkbox', 'label' => __('Enlarge post thumbnail when using mobile?', 'hocwp-theme'))); $option->add_field(array('id' => 'content_none_title', 'title' => __('Content None Title', 'hocwp-theme'))); $excerpt_length = hocwp_get_value_by_key($options, 'excerpt_length'); $option->add_field(array('id' => 'excerpt_length', 'title' => __('Excerpt Length', 'hocwp-theme'), 'field_callback' => 'hocwp_field_input_number', 'value' => $excerpt_length)); if (hocwp_wc_installed() || hocwp_is_shop_site()) { $value = hocwp_get_product_posts_per_page(); $option->add_field(array('id' => 'products_per_page', 'title' => __('Product Each Page', 'hocwp-theme'), 'field_callback' => 'hocwp_field_input_number', 'value' => $value)); } $option->add_section(array('id' => 'breadcrumb', 'title' => __('Breadcrumb', 'hocwp-theme'), 'description' => __('Custom breadcrumb on your site.', 'hocwp-theme'))); $option->add_field(array('id' => 'breadcrumb_label', 'title' => __('Breadcrumb Label', 'hocwp-theme'), 'value' => hocwp_wpseo_internallink_value('breadcrumbs-prefix'), 'section' => 'breadcrumb')); $option->add_field(array('id' => 'disable_post_title_breadcrumb', 'title' => __('Disable Post Title', 'hocwp-theme'), 'field_callback' => 'hocwp_field_input_checkbox', 'label' => __('Prevent post title to be shown on last item.', 'hocwp-theme'), 'section' => 'breadcrumb')); $option->add_field(array('id' => 'link_last_item_breadcrumb', 'title' => __('Link Last Item', 'hocwp-theme'), 'field_callback' => 'hocwp_field_input_checkbox', 'label' => __('Add link to last item instead of text.', 'hocwp-theme'), 'section' => 'breadcrumb')); $thumbnail_image_sizes = $options['thumbnail_image_sizes']; $thumbnail_image_sizes = apply_filters('hocwp_thumbnail_image_sizes', $thumbnail_image_sizes); $thumbnail_image_sizes = hocwp_sanitize_array($thumbnail_image_sizes); if (hocwp_array_has_value($thumbnail_image_sizes)) { $option->add_section(array('id' => 'thumbnail_images', 'title' => __('Thumbnail Images', 'hocwp-theme'), 'description' => __('These settings affect the display and dimensions of images in your catalog – the display on the front-end will still be affected by CSS styles.', 'hocwp-theme'))); foreach ($thumbnail_image_sizes as $thumbnail_size) { $thumbnail_size['section'] = 'thumbnail_images'; $thumbnail_size['field_callback'] = 'hocwp_field_size'; $option->add_field($thumbnail_size); } } $option->add_section(array('id' => 'scroll_top_section', 'title' => __('Scroll To Top', 'hocwp-theme'), 'description' => __('This option can help you to display scroll to top button on your site.', 'hocwp-theme'))); $option->add_field(array('id' => 'go_to_top', 'title' => __('Scroll Top Button', 'hocwp-theme'), 'field_callback' => 'hocwp_field_input_checkbox', 'label' => __('Display scroll to top button on the bottom of site.', 'hocwp-theme'), 'section' => 'scroll_top_section')); $option->add_field(array('id' => 'go_to_top_on_left', 'title' => __('Diplay On Left', 'hocwp-theme'), 'field_callback' => 'hocwp_field_input_checkbox', 'label' => __('Display scroll to top button on the left of site.', 'hocwp-theme'), 'section' => 'scroll_top_section')); $option->add_field(array('id' => 'scroll_top_icon', 'title' => __('Button Icon', 'hocwp-theme'), 'field_callback' => 'hocwp_field_media_upload', 'section' => 'scroll_top_section')); $option->add_option_tab($hocwp_tos_tabs); $option->set_page_header_callback('hocwp_theme_option_form_before'); $option->set_page_footer_callback('hocwp_theme_option_form_after');
function hocwp_field_select_term($args = array()) { hocwp_field_sanitize_args($args); $taxonomy = hocwp_get_value_by_key($args, 'taxonomy'); $taxonomies = hocwp_get_value_by_key($args, 'taxonomies'); $taxonomies = hocwp_sanitize_array($taxonomies); $taxonomies = hocwp_remove_empty_array_item($taxonomies); if (!hocwp_array_has_value($taxonomies) && empty($taxonomy)) { $taxonomy = 'category'; } $taxonomies[] = $taxonomy; $taxonomies = hocwp_sanitize_array($taxonomies); $options = isset($args['options']) ? $args['options'] : array(); $force_empty = isset($args['force_empty']) ? (bool) $args['force_empty'] : false; $tax = get_taxonomy($taxonomy); if (!$force_empty) { if (!hocwp_array_has_value($taxonomies) && !hocwp_array_has_value($options)) { _e('Please pass a taxonomy or set options for arguments.', 'hocwp-theme'); return; } } $only_parent = isset($args['only_parent']) ? $args['only_parent'] : false; $id = isset($args['id']) ? $args['id'] : ''; $name = isset($args['name']) ? $args['name'] : ''; $field_class = isset($args['field_class']) ? $args['field_class'] : ''; if (is_object($tax)) { hocwp_add_string_with_space_before($field_class, 'select-' . $tax->rewrite['slug'] . '-terms'); } $args['field_class'] = hocwp_add_string_with_space_before($field_class, 'select-term'); $label = isset($args['label']) ? $args['label'] : ''; $value = isset($args['value']) ? $args['value'] : ''; $description = isset($args['description']) ? $args['description'] : ''; $taxonomy_id = isset($args['taxonomy_id']) ? $args['taxonomy_id'] : ''; $taxonomy_name = isset($args['taxonomy_name']) ? $args['taxonomy_name'] : ''; $show_count = isset($args['show_count']) ? $args['show_count'] : true; $load_item = isset($args['load_item']) ? (bool) $args['load_item'] : true; $option_default = ''; if (isset($args['option_default'])) { $option_default = $args['option_default']; } else { $default_text = isset($args['default_text']) ? $args['default_text'] : __('Choose term'); $option_default = '<option value="0" data-taxonomy="">-- ' . $default_text . ' --</option>'; } $all_option = $option_default; if ($load_item) { $options = wp_parse_args($options, $taxonomies); $options = hocwp_sanitize_array($options); if (hocwp_array_has_value($options)) { foreach ($options as $tax) { if (!is_object($tax)) { $tax = get_taxonomy($tax); } $term_args = array(); if ($only_parent) { $term_args['parent'] = 0; } if (!is_object($tax)) { continue; } $terms = hocwp_get_terms($tax->name, $term_args); if (hocwp_array_has_value($terms)) { $show_count = isset($args['show_count']) ? $args['show_count'] : true; $hirachical = isset($args['hirachical']) ? $args['hirachical'] : true; $option_group = isset($args['option_group']) ? $args['option_group'] : true; $select_args = array('selected' => $value, 'taxonomy' => $tax->name, 'show_count' => $show_count, 'hirachical' => $hirachical); $select = hocwp_get_term_drop_down($select_args); $select = hocwp_remove_select_tag_keep_content($select); $tmp = ''; if (!empty($select)) { if ($option_group) { $tmp = '<optgroup label="' . $tax->labels->singular_name . '" data-taxonomy="' . $tax->name . '">'; $tmp .= $select; $tmp .= '</optgroup>'; } else { $tmp .= $select; } } $all_option .= $tmp; } } } } $args['all_option'] = $all_option; $args['label'] = $label; if (!isset($args['attributes']['data-taxonomy'])) { $args['attributes']['data-taxonomy'] = $taxonomy; } $args['attributes']['data-show-count'] = absint($show_count); hocwp_field_select($args); }