private function get_taxonomy_from_instance($instance) { $taxonomy = isset($instance['taxonomy']) ? $instance['taxonomy'] : json_encode($this->args['taxonomy']); $taxonomy = hocwp_json_string_to_array($taxonomy); if (!hocwp_array_has_value($taxonomy)) { $taxonomy = array(array('value' => apply_filters('hocwp_widget_term_default_taxonomy', 'category', $this))); } return $taxonomy; }
function hocwp_meta_box_google_maps($args = array()) { global $pagenow; if ('post-new.php' == $pagenow || 'post.php' == $pagenow) { $post_id = hocwp_get_value_by_key($_REQUEST, 'post'); $id = hocwp_get_value_by_key($args, 'id', 'google_maps_box'); $title = hocwp_get_value_by_key($args, 'title', __('Maps', 'hocwp-theme')); $post_types = hocwp_get_value_by_key($args, 'post_types', array('post')); $meta = new HOCWP_Meta('post'); $meta->set_title($title); $meta->set_id($id); $meta->set_post_types($post_types); $map_args = array('id' => 'maps_content', 'label' => '', 'field_callback' => 'hocwp_field_google_maps', 'names' => array('google_maps')); if (hocwp_id_number_valid($post_id)) { $google_maps = hocwp_get_post_meta('google_maps', $post_id); $google_maps = hocwp_json_string_to_array($google_maps); $map_args['lat'] = hocwp_get_value_by_key($google_maps, 'lat'); $map_args['long'] = hocwp_get_value_by_key($google_maps, 'lng'); } $meta->add_field($map_args); //$meta->add_field(array('id' => 'google_maps', 'label' => '', 'field_callback' => 'hocwp_field_input_hidden')); $meta->init(); } }
public function form($instance) { $this->instance = $instance; $title = hocwp_get_value_by_key($instance, 'title'); $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'); $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_field_widget_before($this->admin_args['class']); hocwp_widget_field_title($this->get_field_id('title'), $this->get_field_name('title'), $title); $args = array('id' => $this->get_field_id('number'), 'name' => $this->get_field_name('number'), 'value' => $number, 'label' => __('Number:', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_number', $args); $lists = $this->args['times']; $all_option = ''; foreach ($lists as $key => $lvalue) { $all_option .= hocwp_field_get_option(array('value' => $key, 'text' => $lvalue, 'selected' => $time)); } $args = array('id' => $this->get_field_id('time'), 'name' => $this->get_field_name('time'), 'all_option' => $all_option, 'value' => $time, 'label' => __('Time:', 'hocwp-theme'), 'multiple' => true); hocwp_widget_field('hocwp_field_select', $args); $lists = get_users(); $all_option = ''; foreach ($lists as $lvalue) { $selected = ''; foreach ($users as $data) { $user_name = hocwp_get_value_by_key($data, 'value'); if ($lvalue->ID == $user_name) { $selected = $user_name; } } $all_option .= hocwp_field_get_option(array('value' => $lvalue->ID, 'text' => $lvalue->display_name, 'selected' => $selected)); } $args = array('id' => $this->get_field_id('exclude_users'), 'name' => $this->get_field_name('exclude_users'), 'all_option' => $all_option, 'value' => $exclude_users, 'label' => __('Exclude users:', 'hocwp-theme'), 'placeholder' => __('Choose user', 'hocwp-theme'), 'multiple' => true); hocwp_widget_field('hocwp_field_select_chosen', $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('link_author_name'), 'name' => $this->get_field_name('link_author_name'), 'value' => $link_author_name, 'label' => __('Link author name', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input_checkbox', $args); $args = array('id' => $this->get_field_id('none_text'), 'name' => $this->get_field_name('none_text'), 'value' => $none_text, 'label' => __('No commenter text:', 'hocwp-theme')); hocwp_widget_field('hocwp_field_input', $args); hocwp_field_widget_after(); }
function hocwp_compress_style_and_script_ajax_callback() { $result = array(); $type = hocwp_get_method_value('type'); $type = hocwp_json_string_to_array($type); $force_compress = hocwp_get_method_value('force_compress'); $force_compress = hocwp_string_to_bool($force_compress); $compress_core = hocwp_get_method_value('compress_core'); $compress_core = hocwp_string_to_bool($compress_core); $args = array('type' => $type, 'force_compress' => $force_compress, 'compress_core' => $compress_core); hocwp_compress_style_and_script($args); wp_send_json($result); }
function hocwp_get_dailymotion_data($id) { $transient_name = 'hocwp_dailymotion_%s_data'; $transient_name = hocwp_build_transient_name($transient_name, $id); if (false === ($data = get_transient($transient_name))) { $fields = array('thumbnail_small_url', 'thumbnail_medium_url', 'thumbnail_large_url', 'thumbnail_720_url'); $fields = apply_filters('hocwp_dailymotion_data_fields', $fields); $fields = implode(',', $fields); $url = 'https://api.dailymotion.com/video/' . $id . '?fields=' . $fields; $data = file_get_contents($url); $data = hocwp_json_string_to_array($data); set_transient($transient_name, $data, YEAR_IN_SECONDS); } return $data; }
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(); }
function hocwp_setup_theme_remove_term_base() { $hocwp_permalinks = get_option('hocwp_permalink'); if (isset($hocwp_permalinks['remove_taxonomy_base'])) { $json_taxs = $hocwp_permalinks['remove_taxonomy_base']; $json_taxs = hocwp_json_string_to_array($json_taxs); if (hocwp_array_has_value($json_taxs)) { $taxonomies = array(); foreach ($json_taxs as $data) { $id = hocwp_get_value_by_key($data, 'id'); if (!empty($id)) { $taxonomies[] = $id; } } if (hocwp_array_has_value($taxonomies)) { $rewrite = new HOCWP_Rewrite(); $rewrite->set_taxonomies($taxonomies); $rewrite->remove_taxonomy_base(); } } } }
function hocwp_user_viewed_posts_hook() { $use = hocwp_track_user_viewed_posts(); if ($use && is_singular()) { $expired_interval = HOUR_IN_SECONDS; $expired_interval = apply_filters('hocwp_track_user_viewed_posts_expired_interval', $expired_interval); $now = time(); if (is_user_logged_in()) { $user = wp_get_current_user(); $viewed_posts = get_user_meta($user->ID, 'viewed_posts', true); $viewed_posts = hocwp_sanitize_array($viewed_posts); $post_id = get_the_ID(); $viewed_posts[$post_id] = $now; foreach ($viewed_posts as $post_id => $time) { $dif = $now - $time; if ($expired_interval < $dif) { unset($viewed_posts[$post_id]); } } update_user_meta($user->ID, 'viewed_posts', $viewed_posts); } else { $viewed_posts = isset($_SESSION['viewed_posts']) ? $_SESSION['viewed_posts'] : ''; if (!empty($viewed_posts)) { $viewed_posts = hocwp_json_string_to_array($viewed_posts); } $viewed_posts = hocwp_sanitize_array($viewed_posts); $post_id = get_the_ID(); $viewed_posts[$post_id] = $now; foreach ($viewed_posts as $post_id => $time) { $dif = $now - $time; if ($expired_interval < $dif) { unset($viewed_posts[$post_id]); } } $_SESSION['viewed_posts'] = json_encode($viewed_posts); } } }
function hocwp_std_object_to_array($object) { return hocwp_json_string_to_array(json_encode($object)); }
function hocwp_field_sortable_taxonomy($args = array()) { $value = isset($args['value']) ? $args['value'] : ''; $items = isset($args['items']) ? $args['items'] : ''; $connect = hocwp_get_value_by_key($args, 'connect', false); if (empty($items)) { $active_items = hocwp_json_string_to_array($value); $default_args = array('public' => true); $taxonomy_args = isset($args['taxonomy_args']) ? $args['taxonomy_args'] : array(); $taxonomy_args = wp_parse_args($taxonomy_args, $default_args); $lists = get_taxonomies($taxonomy_args, 'objects'); hocwp_exclude_special_taxonomies($lists); if ((bool) $connect) { foreach ($active_items as $aitem) { if (hocwp_array_has_value($aitem)) { unset($lists[$aitem['id']]); } } } else { $results = hocwp_json_string_to_array($value); if (hocwp_array_has_value($results)) { $new_lists = array(); foreach ($results as $data) { $id = isset($data['id']) ? $data['id'] : ''; $item = get_taxonomy($id); if (hocwp_object_valid($item) && taxonomy_exists($item)) { foreach ($lists as $key => $taxonomy) { if ($taxonomy->name == $item->name) { $new_lists[] = $item; unset($lists[$key]); break; } } } } $lists = $new_lists + $lists; } } foreach ($lists as $key => $list_item) { $li = new HOCWP_HTML('li'); $li->set_class('ui-state-default'); $attributes = array('data-id' => $key); $li->set_attribute_array($attributes); $li->set_text($list_item->labels->singular_name); $items .= $li->build(); } } if ((bool) $connect) { $active_items = isset($args['active_items']) ? $args['active_items'] : ''; if (empty($active_items)) { $lists = hocwp_json_string_to_array($value); foreach ($lists as $data) { $id = isset($data['id']) ? $data['id'] : ''; $item = get_taxonomy($id); if (hocwp_object_valid($item) && isset($item->name) && taxonomy_exists($item->name)) { $li = new HOCWP_HTML('li'); $li->set_class('ui-state-default'); $attributes = array('data-id' => $id); $li->set_attribute_array($attributes); $li->set_text($item->labels->singular_name); $active_items .= $li->build(); } } } $args['active_items'] = $active_items; } $args['items'] = $items; $class = isset($args['class']) ? $args['class'] : ''; hocwp_add_string_with_space_before($class, 'taxonomy-sortable'); $args['class'] = $class; hocwp_field_sortable($args); }