function hocwp_theme_meta_box_ads_information($post_type, $post) { global $pagenow; if ('hocwp_ads' == $post_type) { if (hocwp_is_post($post)) { $post_id = $post->ID; } else { $post_id = 0; } $meta = new HOCWP_Meta('post'); $meta->add_post_type('hocwp_ads'); $meta->set_id('hocwp_ads_information'); $meta->set_title(__('Ads Information', 'hocwp-theme')); $meta->add_field(array('id' => 'image', 'label' => __('Image:', 'hocwp-theme'), 'container' => true, 'field_callback' => 'hocwp_field_media_upload')); $meta->add_field(array('id' => 'url', 'label' => __('Url:', 'hocwp-theme'))); $positions = hocwp_get_ads_positions(); if (hocwp_array_has_value($positions)) { $all_option = hocwp_field_get_option(array('text' => '--Choose Position--')); $selected = get_post_meta($post_id, 'position', true); foreach ($positions as $position) { $all_option .= hocwp_field_get_option(array('text' => $position['name'], 'value' => $position['id'], 'selected' => $selected)); } $field_args = array('id' => 'position', 'label' => __('Position:', 'hocwp-theme'), 'field_callback' => 'hocwp_field_select', 'all_option' => $all_option); $meta->add_field($field_args); } $meta->add_field(array('id' => 'expire', 'label' => __('Expire:', 'hocwp-theme'), 'field_callback' => 'hocwp_field_datetime_picker')); do_action('hocwp_meta_box_ads_fields', $meta, $post); $meta->init(); $args = array('id' => 'code_box', 'title' => __('Code:', 'hocwp-theme'), 'field_id' => 'code', 'post_type' => $post_type, 'field_args' => array('teeny' => true)); hocwp_meta_box_editor($args); } }
function hocwp_shortcode_post_callback($atts = array(), $content = null) { $defaults = array('order' => 'desc', 'orderby' => 'date', 'by' => 'related', 'post_type' => 'post', 'title' => __('Related posts', 'hocwp-theme'), 'offset' => 0, 'column' => 4, 'number' => hocwp_get_posts_per_page(), 'border_color' => '', 'exclude_current' => true, 'display' => 'left', 'excerpt_length' => 0, 'style' => '', 'post' => '', 'posts' => '', 'thumbnail_size' => '180,110', 'interval' => ''); $attributes = shortcode_atts($defaults, $atts); $transient_name = 'hocwp_shortcode_post_%s'; $transient_name = hocwp_build_transient_name($transient_name, $attributes); if (false === ($html = get_transient($transient_name))) { $order = $attributes['order']; $orderby = $attributes['orderby']; $by = $attributes['by']; $post_type = hocwp_string_to_array(',', $attributes['post_type']); $post_type = array_map('trim', $post_type); $offset = $attributes['offset']; $column = $attributes['column']; if (!hocwp_is_positive_number($column)) { $column = 1; } $number = $attributes['number']; $posts_per_page = hocwp_get_first_divisible_of_divisor($number, $column); $exclude_current = (bool) $attributes['exclude_current']; $display = $attributes['display']; $display = trim($display); $excerpt_length = $attributes['excerpt_length']; $post = $attributes['post']; $post = hocwp_find_post($post); $posts = $attributes['posts']; $posts = hocwp_string_to_array(',', $posts); $thumbnail_size = $attributes['thumbnail_size']; $thumbnail_size = hocwp_sanitize_size($thumbnail_size); $interval = $attributes['interval']; if (hocwp_is_post($post)) { $display = 'full'; } $class = 'hocwp-shortcode-post'; hocwp_add_string_with_space_before($class, $order); hocwp_add_string_with_space_before($class, $by); hocwp_add_string_with_space_before($class, hocwp_sanitize_html_class($display)); if ('100%' == $display) { $class = hocwp_add_more_class($class, 'full-width'); } hocwp_add_string_with_space_before($class, implode(' ', $post_type)); $query = null; if (!hocwp_is_post($post)) { $args = array('post_type' => $post_type, 'posts_per_page' => $posts_per_page, 'offset' => $offset, 'order' => $order, 'orderby' => $orderby); if (!empty($interval)) { hocwp_query_sanitize_date_query_args($interval, $args); } if ($exclude_current && is_singular()) { $post_id = get_the_ID(); $args['post__not_in'] = array($post_id); } if (hocwp_array_has_value($posts)) { $args['post__in'] = $posts; } $query = hocwp_query_by($by, $args); } else { if (!hocwp_is_positive_number($excerpt_length)) { $excerpt_length = 200; } } if (hocwp_is_post($post) || hocwp_object_valid($query) && $query->have_posts()) { $html = hocwp_shortcode_before($class, $attributes); $width = $thumbnail_size[0]; if (hocwp_is_post($post)) { global $post; setup_postdata($post); ob_start(); ?> <div class="one-post"> <div <?php post_class('', $post); ?> > <?php if ($width > 0) { hocwp_post_thumbnail(array('width' => $thumbnail_size[0], 'height' => $thumbnail_size[1], 'post_id' => $post->ID)); } hocwp_post_title_link(array('title' => $post->post_title, 'permalink' => get_permalink($post))); if (hocwp_is_positive_number($excerpt_length)) { hocwp_entry_summary($excerpt_length); } ?> </div> </div> <?php $html .= ob_get_clean(); wp_reset_postdata(); } else { $html .= '<div class="in-loop row-small">'; $loop = apply_filters('hocwp_shortcode_post_pre_loop', '', $query, $attributes); if (empty($loop)) { $count = 1; $style = ''; if ('left' != $display && 'right' != $display) { $style = 'width:' . hocwp_column_width_percentage($column); } while ($query->have_posts()) { $query->the_post(); $html_loop = apply_filters('hocwp_shortcode_post_loop', '', $attributes); if (empty($html_loop)) { $item_class = 'item'; if (hocwp_is_last_item($count, $column)) { hocwp_add_string_with_space_before($item_class, 'last-item'); } elseif (hocwp_is_first_item($count, $column)) { hocwp_add_string_with_space_before($item_class, 'first-item'); } ob_start(); ?> <div class="<?php echo $item_class; ?> " style="<?php echo $style; ?> "> <div <?php post_class(); ?> > <?php if ($width > 0) { hocwp_post_thumbnail(array('width' => $thumbnail_size[0], 'height' => $thumbnail_size[1])); } hocwp_post_title_link(); if (hocwp_is_positive_number($excerpt_length)) { hocwp_entry_summary($excerpt_length); } ?> </div> </div> <?php $html_loop = ob_get_clean(); } $loop .= $html_loop; $count++; } wp_reset_postdata(); } $html .= $loop; $html .= '</div>'; } $html .= hocwp_shortcode_after(); } else { $html = ''; } if (!empty($html)) { set_transient($transient_name, $html, WEEK_IN_SECONDS); } } return apply_filters('hocwp_shortcode_post', $html, $attributes, $content); }
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_show_ads($args = array()) { $ads = $args; $position = ''; if (!is_object($args)) { if (!is_array($args)) { $args = array('position' => $args); } $position = hocwp_get_value_by_key($args, 'position'); if (!empty($position)) { $random = (bool) hocwp_get_value_by_key($args, 'random'); $current_datetime = date(hocwp_get_date_format()); $current_datetime = strtotime($current_datetime); $query_args = array('post_type' => 'hocwp_ads', 'posts_per_page' => 1, 'meta_query' => array('relation' => 'AND', array('relation' => 'OR', array('key' => 'expire', 'compare' => 'NOT EXISTS'), array('key' => 'expire', 'value' => '', 'compare' => '='), array('key' => 'expire', 'value' => 0, 'type' => 'numeric'), array('key' => 'expire', 'value' => $current_datetime, 'type' => 'numeric', 'compare' => '>=')), array('key' => 'active', 'value' => 1, 'type' => 'numeric'))); if ($random) { $query_args['orderby'] = 'rand'; } $ads = hocwp_get_post_by_meta('position', $position, $query_args); if ($ads->have_posts()) { $posts = $ads->posts; $ads = array_shift($posts); } } } if (hocwp_is_post($ads) && 'hocwp_ads' == $ads->post_type) { $code = hocwp_get_post_meta('code', $ads->ID); if (empty($code)) { $image = hocwp_get_post_meta('image', $ads->ID); $image = hocwp_sanitize_media_value($image); $image = $image['url']; if (!empty($image)) { $img = new HOCWP_HTML('img'); $img->set_image_src($image); $url = hocwp_get_post_meta('url', $ads->ID); if (!empty($url)) { $a = new HOCWP_HTML('a'); $a->set_href($url); $a->set_text($img); $code = $a->build(); } else { $code = $img->build(); } } } if (!empty($code)) { $class = hocwp_get_value_by_key($args, 'class'); hocwp_add_string_with_space_before($class, 'hocwp-ads text-center ads'); if (!empty($position)) { hocwp_add_string_with_space_before($class, 'position-' . $position); $position = hocwp_sanitize_html_class($position); $class = hocwp_add_more_class($class, $position); } hocwp_add_string_with_space_before($class, $ads->post_name); $div = new HOCWP_HTML('div'); $div->set_class($class); $div->set_text($code); $html = $div->build(); $html = apply_filters('hocwp_ads_html', $html, $ads_or_args = $args); echo $html; } } }
function hocwp_find_post($data, $post_type = 'post') { $result = null; if (!empty($data)) { if (hocwp_id_number_valid($data)) { $temp = get_post($data); if (hocwp_is_post($temp) && $temp->post_type == $post_type) { $result = $temp; } } else { $result = hocwp_get_post_by_slug($data, $post_type); } } return $result; }
public function attachment_meta_fields($form_fields, $post) { $fields = $this->get_fields(); if (hocwp_array_has_value($fields)) { foreach ($fields as $field) { $this->sanitize_field_args($field); $callback = hocwp_get_value_by_key($field, 'field_callback', hocwp_get_value_by_key($field, 'callback')); if (hocwp_callback_exists($callback)) { $name = hocwp_get_value_by_key($field, 'name'); if (!empty($name)) { if (!isset($field['value']) && hocwp_is_post($post)) { $value = hocwp_get_post_meta($name, $post->ID); $field['value'] = $value; } if (isset($field['input'])) { $field_args = $field; unset($field_args['label']); unset($field_args['title']); ob_start(); call_user_func($callback, $field_args); $html = ob_get_clean(); $field[$field['input']] = $html; } $form_fields[$name] = $field; } } } } return $form_fields; }
function hocwp_get_parent_menu_item($menu_item) { $result = null; if (hocwp_is_post($menu_item) && is_nav_menu_item($menu_item->ID)) { if ($menu_item->menu_item_parent && hocwp_id_number_valid($menu_item->menu_item_parent)) { $parent = get_post($menu_item->menu_item_parent); if (is_nav_menu_item($parent)) { $result = wp_setup_nav_menu_item($parent); } } } return $result; }
function hocwp_setup_theme_woocommerce_product_tabs_callback($key, $tab) { $content = hocwp_get_post_meta($key, get_the_ID()); $content = trim($content); $title = hocwp_get_value_by_key($tab, 'title'); if (empty($content)) { $slug = hocwp_sanitize_html_class($key); $hocwp_product_tab = hocwp_get_post_by_slug($slug, 'hocwp_product_tab'); if (!hocwp_is_post($hocwp_product_tab)) { $hocwp_product_tab = hocwp_get_post_by_column('post_title', $title); } if (hocwp_is_post($hocwp_product_tab)) { $content = $hocwp_product_tab->post_content; $content = trim($content); } } if (!empty($content)) { if (!empty($title)) { echo hocwp_wrap_tag($title, 'h2', 'tab-title'); } echo '<div class="hocwp-product-info">'; $embed = new WP_Embed(); $content = $embed->run_shortcode($content); $content = $embed->autoembed($content); hocwp_the_custom_content($content); echo '</div>'; } }