<?php /*----------------------------------------------------------------------------------- Here we have all the custom functions for the theme Please be extremely cautious editing this file. You have been warned! -------------------------------------------------------------------------------------*/ //CHILD THEME require_once('inc/aq_resizer.php'); require_once(get_template_directory().'/inc/ads/ads-logic.php'); add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' ); function enqueue_parent_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); wp_enqueue_script( 'script', get_template_directory_uri() . '/assets/js/custom.js', array ( 'jquery' ), 1.1, true); if(is_front_page()) { wp_enqueue_script( 'custom-homepage-script', get_template_directory_uri() . '/assets/js/custom-homepage.js', array ( 'jquery' ), null, true); wp_enqueue_script( 'owl-script', get_template_directory_uri() . '/assets/js/vendor/owl.carousel.min.js', array('jquery'), null, true); wp_enqueue_style( 'owl-style', get_template_directory_uri() . '/assets/css/owl.carousel.min.css'); } } require get_stylesheet_directory() .'/inc/wp3menu.php'; require get_stylesheet_directory() .'/inc/misc.php'; function add_custom_sizes() { add_image_size( 'home-thumb', 300, 300, true ); } function update_accent_color() { $options = get_option(ot_options_id()); $options['accent_color'] = '#a07d14'; update_option(ot_options_id(), $options); } add_action('after_setup_theme','update_accent_color'); add_action('after_setup_theme','add_custom_sizes'); add_action('wp_ajax_search_post', 'search_post'); add_action('wp_ajax_nopriv_search_post', 'search_post'); function search_post() { $extra_params = $_POST['extra_params']; $page = $_POST["page"]; $search = $_POST['search']; $author = json_decode($extra_params['author']); $item_count_limit = $_POST['item_count_limit']; $sort_by = $_POST['sort_by_filter']; $show_only_filter = $_POST['show_only_filter']; $show_author_content = !json_decode($extra_params['other']); if($author){ $args_author = array( 'post_type' => array('magazine-article', 'editorial-article', 'sponsored-content'), 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'order' => 'DESC', 'orderby' => 'post_date', 'author' => (int)$author, 'posts_per_page' => $item_count_limit, // 'sentence' => true, 'paged' => $page, // 'offset' => $offset, // 's' => $search, ); } $args = array( 'post_type' => array('magazine-article', 'editorial-article', 'sponsored-content'), 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'order' => 'DESC', 'orderby' => 'post_date', // 'sentence' => true, 'posts_per_page' => $item_count_limit, // 'offset' => $offset, 'paged' => $page, 's' => $search, ); if ($author) { $args['author__not_in'] = array($author); } if (!empty($extra_params['post__not_in'])) { // $args['post__not_in'] = $extra_params['post__not_in']; $args['post__not_in'] = array_map(function ($el) {return (int)$el;}, $extra_params['post__not_in']); } if($show_only_filter == 0) { $date_param = array( 'date_query' => array( array( 'column' => 'post_date_gmt', 'after' => '1 week ago', ), ), ); $args = wp_parse_args($date_param, $args); if($author !== false){ $args_author = wp_parse_args($date_param, $args_author ); } } else if($show_only_filter == 1) { $date_param = array( 'date_query' => array( array( 'column' => 'post_date_gmt', 'after' => '1 month ago', ), ), ); $args = wp_parse_args($date_param, $args); if($author !== false){ $args_author = wp_parse_args($date_param, $args_author ); } } if($sort_by == 1) { $sort_param = array( 'meta_key' => '_fb_share_count', 'orderby' => 'meta_value_num', ); $args = wp_parse_args($sort_param, $args); if($author !== false){ $args_author = wp_parse_args($sort_param, $args_author ); } } else if($sort_by == 2) { //disqus version $api_key = '43fBTKoc54baPw7QyP8vmdkxYxk9f30gzuqOLC3lqt9K4IdsrR3mGqdJJIeb97YB'; $interval = '7d'; $forum = 'jck-2'; $limit = 100; $url_call = "http://disqus.com/api/3.0/threads/listPopular.json?api_key=" . $api_key . "&forum=" . $forum . "&interval=" . $interval . "&limit=" . $limit; $get_contents = file_get_contents($url_call); $call = json_decode($get_contents); $post_ids = array(); foreach ($call->response as $response) { $post_id = explode(" ", $response->identifiers[0])[0]; array_push($post_ids, $post_id); } $posts = $post_ids; $args = wp_parse_args( array( 'post__in' => $posts, ) , $args); if($author !== false){ $args_author = wp_parse_args( array( 'post__in' => $posts, ) , $args_author ); } } /***** queries to calculate the total *****/ $total = 0; if ($author) { $args_author_total = $args_author; if (isset($date_param) && is_array($date_param)) { $args_author_total = wp_parse_args($sort_param, $args_author_total ); } $query_author_total = new WP_Query($args_author_total); $total += $query_author_total->found_posts; } $args_total = $args; if (isset($date_param) && is_array($date_param)) { $args_total = wp_parse_args($sort_param, $args_total ); } $query_total = new WP_Query($args_total); $total += $query_total->found_posts; if (!empty($extra_params['post__not_in'])) { $total += count($extra_params['post__not_in']); } /***** query to calculate the total *****/ $return = array(); ob_start(); if ($show_author_content) { $query = new WP_Query($args_author); if ($query->post_count < $item_count_limit) { $return['empty_author'] = true; $args['posts_per_page'] = $item_count_limit - $query->post_count; $query2 = new WP_Query($args); $return['post__not_in'] = array_map(function ($p) {return $p->ID;}, $query2->posts); } } else { $query = new WP_Query($args); } $return['found_posts'] = $total; if( $query->have_posts()) { // $return['found_posts'] += $query->found_posts; while ( $query->have_posts() ) : $query->the_post(); get_template_part( 'inc/templates/loop/style1' ); endwhile; } if( isset($query2) && $query2->have_posts()) { // $return['found_posts'] += $query2->found_posts; while ( $query2->have_posts() ) : $query2->the_post(); get_template_part( 'inc/templates/loop/style1' ); endwhile; } $return['posts'] = ob_get_clean(); echo json_encode($return); } add_action('wp_ajax_search_category', 'search_category'); add_action('wp_ajax_nopriv_search_category', 'search_category'); function search_category(){ $page = $_REQUEST["page"]; $offset = $_REQUEST['offset']; $hide_father_category = false; $style = 'style2'; $item_count = $_REQUEST["item_count"]; $item_count_limit = $_REQUEST['item_count_limit']; $cats = $_REQUEST['search']; $cats = explode(',',$cats); $featured_index = $_REQUEST["featured_index"]; $featured_index = empty($featured_index) ? array() : explode(',',$featured_index); $args = array( 'post_type' => get_post_types('', 'names'), 'post_status' => 'publish', 'ignore_sticky_posts' => 1, ); $args = wp_parse_args( array( 'posts_per_page' => $item_count_limit, 'offset' => $offset, 'category__in' => $cats, ) , $args ); $posts = query_posts($args); ob_start(); if( have_posts()) { set_query_var( 'hide_father_category', $hide_father_category ); if ($style == 'style1') { $i = 1; while ( have_posts() ) : the_post(); get_template_part( 'inc/templates/loop/style6' ); $i++; endwhile; } else if ($style == 'style4') { $i = 1; while ( have_posts() ) : the_post(); get_template_part( 'inc/templates/loop/style7' ); $i++; endwhile; } else if ($style == 'style2') { $i = 1; while ( have_posts() ) : the_post(); if (in_array($i, $featured_index )) { get_template_part( 'inc/templates/loop/style7' ); } else { get_template_part( 'inc/templates/loop/style1' ); } $i++; endwhile; } else if ($style == 'style3') { $i = 1; while ( have_posts() ) : the_post(); get_template_part( 'inc/templates/loop/style2' ); $i++; endwhile; } else if ($style == 'style5') { $i = 1; while ( have_posts() ) : the_post(); get_template_part( 'inc/templates/loop/style9' ); $i++; endwhile; } } } add_action('wp_ajax_call_post', 'call_post'); add_action('wp_ajax_nopriv_call_post', 'call_post'); function call_post() { $sidebar_id = $_POST["sidebar_id"]; $cats = $_POST["cats"]; $item_count = $_POST["item_count"]; $item_count_lm = $_POST["item_count_lm"]; $page = $_POST["page"] - 1; $featured_index = $_POST["featured_index"]; $featured_index = empty($featured_index) ? array() : explode(',',$featured_index); $hide_father_category = $_POST["hide_father_category"]; $style = $_POST["style"]; $offset = $_POST["offset"]; $ads = $_POST["ads"]; $ads = explode(",",$ads); $cats = explode(',',$cats); $i=0; foreach ($ads as $ad) { $ads[$i] = explode("*",$ad); $i++; } $current_ad = $ads[$sidebar_id-1]; $args = array( 'post_type' => get_post_types('', 'names'), 'post_status' => 'publish', 'ignore_sticky_posts' => 1, ); $args = wp_parse_args( array( 'posts_per_page' => $item_count_lm, 'category__in' => $cats, 'category__not_in' => '1', 'offset' => $item_count + ($page * $item_count_lm) + $offset, ) , $args ); $posts = query_posts( $args ); ob_start(); if( have_posts()) { ?> <div class="row row-fluid home-column-group"> <div class="news-trends-home-data wpb_column columns small-12 medium-9 news-trends-home-data-load-more"> <div class="vc_column-inner"> <div class="wpb_wrapper articles-top-container"> <div class="posts border "> <?php set_query_var( 'hide_father_category', $hide_father_category ); if ($style == 'style1') { $i = 1; while ( have_posts() ) : the_post(); get_template_part( 'inc/templates/loop/style6' ); $i++; endwhile; } else if ($style == 'style4') { $i = 1; while ( have_posts() ) : the_post(); get_template_part( 'inc/templates/loop/style7' ); $i++; endwhile; } else if ($style == 'style2') { $i = 1; while ( have_posts() ) : the_post(); if (in_array($i, $featured_index )) { get_template_part( 'inc/templates/loop/style7' ); } else { get_template_part( 'inc/templates/loop/style1' ); } $i++; endwhile; } else if ($style == 'style3') { $i = 1; while ( have_posts() ) : the_post(); get_template_part( 'inc/templates/loop/style2' ); $i++; endwhile; } else if ($style == 'style5') { $i = 1; while ( have_posts() ) : the_post(); get_template_part( 'inc/templates/loop/style9' ); $i++; endwhile; } $rand = mt_rand(); ?> </div> </div> </div> </div> <div class="wpb_column columns small-12 medium-3"> <div class="vc_column-inner fixed-me"> <div class="wpb_wrapper"> <div class="wpb_widgetised_column wpb_content_element class"> <div class="wpb_wrapper newcol-<?= $rand; ?>"> <script type="text/javascript"> $container = jQuery(jQuery('.wpb_column.columns.home-lateral-bar .wpb_wrapper .wpb_content_element')[<?= ($sidebar_id-1) ?>]) $index = $container.index(); $cloned = $container.clone(); $target = jQuery('.newcol-<?= $rand; ?>'); if($index > 0) { $target.append($cloned); } else { $target.prepend($cloned); } </script> <?php $sizes = array(); $sizes['mobile'] = str_replace ('x', ',', $current_ad[3]); $sizes['desktop'] = str_replace ('x', ',', $current_ad[2]); $ad_kw = $current_ad[0]; $ad_name = $current_ad[1]; if(isset($current_ad[4])) { $ad_position = $current_ad[4]; } if(isset($current_ad[5])) { $ad_css_class = $current_ad[5]; } echo print_ad($ad_kw, $ad_name, $sizes, $ad_position, $ad_css_class); ?> </div> </div> </div> </div> </div> <?php $args = wp_parse_args( array( 'offset' => $item_count + (($page+1) * $item_count_lm) + $offset, ) , $args ); $posts = query_posts( $args ); if( !have_posts()) { echo "{{NO-MORE-POSTS}}"; } } } add_action('wp_ajax_save_post_featured_order', 'save_post_featured_order'); add_action('wp_ajax_nopriv_save_post_featured_order', 'save_post_featured_order'); function save_post_featured_order() { $data = $_REQUEST["data"]; $data = stripslashes($data); $data = json_decode($data, true); update_post_meta(76, 'my_key', 'Steve'); $i = 0; foreach ($data as $post) { update_post_meta($post['post_id'], 'wpcf-index_value', $post['index']); $i++; } echo "success"; } add_action('wp_ajax_remove_post_featured_order', 'remove_post_featured_order'); add_action('wp_ajax_nopriv_remove_post_featured_order', 'remove_post_featured_order'); function remove_post_featured_order() { $post_id = $_REQUEST["post_id"]; $meta_key = 'wpcf-featured-on-homepage'; $meta_value = get_post_meta( $post_id, $meta_key, true ); if($meta_value) { delete_post_meta( $post_id, $meta_key, $meta_value ); } echo "success"; } add_action( 'admin_menu', 'my_admin_menu' ); function my_admin_menu() { add_menu_page( 'Articles Featured / Homepage', 'Articles Featured / Homepage', 'manage_options', 'article-featured/article_featured-admin-page.php', 'article_featured_admin_page', 'dashicons-tickets', 6 ); add_menu_page( 'How To Sponsorship', 'How To Sponsorship', 'manage_options', 'how-to-sponsorship/how-to-sponsorship.php', 'how_to_sponsorship_admin_page', 'dashicons-tickets', 7 ); } function article_featured_admin_page() { ?> <div class="wrap"> <h2>Article Featured Homepage</h2> <br/> <br/> <table class="wp-list-table widefat fixed striped posts" id="table-1"> <thead> <tr> <td>Title</td> <td>Author</td> <td>Categories</td> <td>Date</td> <td>Remove from Featured</td> </tr> </thead> <tbody id="the-list"> <?php $args = array( 'post_type' => get_post_types('', 'names'), 'post_status' => 'publish', 'ignore_sticky_posts' => 1, 'orderby' => 'meta_value', 'meta_key' => 'wpcf-index_value', 'order'=> 'ASC', 'meta_query' => array( array( 'key' => 'wpcf-featured-on-homepage', 'compare' => 'EXISTS', ), ), ); $posts = query_posts( $args ); ob_start(); $i = 1; while ( have_posts() ) : the_post(); get_template_part( 'inc/templates/loop/featured-homepage-admin-item' ); $i++; endwhile; ?> </tbody> </table> <div style="float: right; margin-top: 20px;"> <a href="#/" id="saveFeaturedArticle" class="button action">Save Order</a> </div> </div> <script src="https://cdn.jsdelivr.net/jquery.tablednd/0.8/jquery.tablednd.0.8.min.js"></script> <script type="text/javascript"> jQuery(function() { jQuery("#table-1").tableDnD(); jQuery("#saveFeaturedArticle").click(function(e) { e.preventDefault(); var dataToSend = []; jQuery("tr.post-featured-home").each(function(index, item) { var postId = jQuery(this).data('id'); var obj = { post_id: postId, index: index }; dataToSend.push(obj); }); dataToSend = JSON.stringify(dataToSend); var button = jQuery(this); jQuery.ajax({ method: "POST", url: "<?php echo admin_url('admin-ajax.php'); ?>", data: "action=save_post_featured_order&data="+dataToSend, success: function(data) { //console.log("data: ",data); } }); }); jQuery("a.removeFeaturedArticle").click(function(e) { e.preventDefault(); var r = confirm('Are you sure you want to remove this post from featured on homepage?'); if (r != true) { return false; } var $item = jQuery(this).closest('tr'); var postId = $item.data('id'); jQuery.ajax({ method: "POST", url: "<?php echo admin_url('admin-ajax.php'); ?>", data: "action=remove_post_featured_order&post_id="+postId, success: function(data) { $item.remove(); } }); }); }); </script> <?php } function upload_user_file($file = array(), $path, $url) { if(!empty($file)) { $upload_dir = $path; $uploaded = move_uploaded_file($file['tmp_name'], $upload_dir.$file['name']); return array($uploaded, esc_url($url . $file['name'])); } } function how_to_sponsorship_admin_page() { if(isset($_POST['upload'])) { if($_FILES['file']['size'] && $_FILES['file']['name'] != '') { $file = $_FILES['file']; // file array $folder = '/howto-sponsored/'; $upload_dir = wp_upload_dir(); $path = $upload_dir['basedir'] . $folder; //upload dir. $url = $upload_dir['baseurl'] . $folder; if(!is_dir($path)) { mkdir($path); } $attachment_id = upload_user_file($file, $path, $url); update_option('howto_sponsored_image', $attachment_id[1]); } } if (isset($_POST['active_sponsorship'])) { update_option('howto_active_sponsorship', $_POST['active_sponsorship']); } $sponsored_image = get_option('howto_sponsored_image'); $active_sponsorship = get_option('howto_active_sponsorship', 'false'); ?> <div class="wrap"> <h2>How To Sponsorship</h2> <br/> <br/> <form action="" method="post" enctype="multipart/form-data"> <table class="form-table"> <tbody> <tr> <th scope="row"> <label>Active Sponsorship</label> </th> <td> <select class="active_sponsorship" name="active_sponsorship"> <option <?php if($active_sponsorship == 'true') { echo 'selected="selected"'; } ?> value="true">YES</option> <option <?php if($active_sponsorship == 'false') { echo 'selected="selected"'; } ?> value="false">NO</option> </select> </td> </tr> <tr> <th scope="row"> <label>Sponsored By Logo</label> </th> <td> <input type="file" name="file" id="imgInp"> </td> </tr> <tr> <th scope="row"> <label>Preview</label> </th> <td> <div class="image-preview-container"> <img class="image-preview" src="<?= $sponsored_image; ?>" id="imagePreview"> </div> </td> </tr> </tbody> </table> <p class="submit"> <input type="submit" name="upload" class="button action" value="Save Changes"> </p> </form> </div> <script type="text/javascript"> if('<?= $sponsored_image; ?>' == '') { jQuery('#imagePreview').hide(); } function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function (e) { jQuery('#imagePreview').attr('src', e.target.result); jQuery('#imagePreview').show(); } reader.readAsDataURL(input.files[0]); } } jQuery("#imgInp").change(function(){ readURL(this); }); </script> <style type="text/css"> .image-preview-container { width: 180px; height: auto; border: 1px solid grey; padding: 4px; margin: 20px 0; } .image-preview { width: 100%; vertical-align: middle; } .active_sponsorship { min-width: 120px; } </style> <?php } function add_sponsors_box() { $screens = ['sponsored-content']; foreach ($screens as $screen) { add_meta_box( 'sponsors_box', // Unique ID 'Sponsors', // Box title 'sponsors_box_html', // Content callback, must be of type callable $screen // Post type ); } } /* Save the meta box's post metadata. */ function sponsors_box_save_post_meta( $post_id, $post ) { /* Get the posted data and sanitize it for use as an HTML class. */ $new_meta_value = ( isset( $_POST['sponsors_box_field'] ) ? $_POST['sponsors_box_field'] : '' ); /* Get the meta key. */ $meta_key = 'sponsors_box_slug'; //$meta_key_val = 'sponsors_box_slug'; /* Get the meta value of the custom field key. */ $meta_value = get_post_meta( $post_id, $meta_key, true ); /* If a new meta value was added and there was no previous value, add it. */ if ( $new_meta_value && '' == $meta_value ) add_post_meta( $post_id, $meta_key, $new_meta_value, true ); /* If the new meta value does not match the old value, update it. */ elseif ( $new_meta_value && $new_meta_value != $meta_value ) update_post_meta( $post_id, $meta_key, $new_meta_value ); /* If there is no new meta value but an old value exists, delete it. */ elseif ( '' == $new_meta_value && $meta_value ) delete_post_meta( $post_id, $meta_key, $meta_value ); } function sponsors_box_html($post, $box, $selected_sponsor = null, $show_all = false) { $id = $post->ID; if(!isset($selected_sponsor)) { $selected_sponsor = get_post_meta($id, 'sponsors_box_slug', true); } $args = array( 'post_type'=>'sponsor', 'post_status' => 'publish', 'posts_per_page' => -1, ); $posts = get_posts($args); if(count($posts)) { echo '<select name="sponsors_box_field" id="sponsors_box_field" class="postbox">'; if($show_all) { echo "<option value=''>All Sponsors</option>"; } foreach($posts as $post): $id = $post->ID; $title = get_the_title($id); $selected = ''; if($selected_sponsor == $id) { $selected = "selected='selected'"; } echo "<option ".$selected."value='$id'>$title</option>"; endforeach; echo '</select>'; } } add_action('save_post_sponsored-content', 'sponsors_box_save_post_meta', 10, 3); add_action('add_meta_boxes', 'add_sponsors_box'); function add_users_box() { $screens = ['writer']; foreach ($screens as $screen) { add_meta_box( 'users_box', // Unique ID 'Users', // Box title 'users_box_html', // Content callback, must be of type callable $screen // Post type ); } } /* Save the meta box's post metadata. */ function users_box_save_post_meta( $post_id, $post ) { /* Get the posted data and sanitize it for use as an HTML class. */ $new_meta_value = ( isset( $_POST['users_box_field'] ) ? $_POST['users_box_field'] : '' ); /* Get the meta key. */ $meta_key = 'users_box_slug'; //$meta_key_val = 'sponsors_box_slug'; /* Get the meta value of the custom field key. */ $meta_value = get_post_meta( $post_id, $meta_key, true ); /* If a new meta value was added and there was no previous value, add it. */ if ( $new_meta_value && '' == $meta_value ) add_post_meta( $post_id, $meta_key, $new_meta_value, true ); /* If the new meta value does not match the old value, update it. */ elseif ( $new_meta_value && $new_meta_value != $meta_value ) update_post_meta( $post_id, $meta_key, $new_meta_value ); /* If there is no new meta value but an old value exists, delete it. */ elseif ( '' == $new_meta_value && $meta_value ) delete_post_meta( $post_id, $meta_key, $meta_value ); } function users_box_html($post) { $id = $post->ID; $selected_user = get_post_meta($id, 'users_box_slug', true); $users = get_users(); ?> <select name="users_box_field" id="users_box_field" class="postbox"> <?php foreach ( $users as $user ) { $id = $user->id; $selected = ''; if($selected_user == $id) { $selected = "selected='selected'"; } echo '<option '.$selected."value='$id' >" . esc_html( $user->display_name ) . '</option>'; } ?> </select> <?php } add_action('save_post_writer', 'users_box_save_post_meta', 10, 3); add_action('add_meta_boxes', 'add_users_box'); add_filter( 'category_template', function ( $single_template ) { $current_category = single_cat_title("", false); $current_slug = sanitize_title($current_category); $cat_loop = get_category_by_slug( $current_slug ); $cat_blog = get_category_by_slug( 'blogs' ); $has_an = false; if (cat_is_ancestor_of($cat_blog->term_id, $cat_loop->term_id)) { $has_an = true; } if(is_category('blogs')) { $single_template = get_template_directory(). '/inc/templates/single/blogs.php'; } else if($has_an) { $single_template = get_template_directory(). '/inc/templates/single/blogs-subcategories.php'; } else { $single_template = get_template_directory(). '/category.php'; } return $single_template; }, 10, 2 ); function editorial_article_enqueue_admin_script( $hook ) { global $post; $post_type = ''; if (!empty($post)) { $post_type = get_post_type($post->ID); } if (('post-new.php' != $hook && 'post.php' != $hook) || $post_type != 'editorial-article') { return; } wp_enqueue_script( 'editorial_article_script', get_template_directory_uri() . '/assets/js/editorial-article.js', array(), null, true ); } add_action( 'admin_enqueue_scripts', 'editorial_article_enqueue_admin_script' ); function custom_post_types_enqueue_admin_script( $hook ) { global $post; $post_type = ''; if (!empty($post)) { $post_type = get_post_type($post->ID); } if (('post-new.php' != $hook && 'post.php' != $hook) || $post_type != 'post') { return; } wp_enqueue_script( 'custom_post_types_script', get_template_directory_uri() . '/assets/js/custom-post-types.js', array(), null, true ); wp_enqueue_style( 'custom_post_types_style', get_template_directory_uri() . '/assets/css/custom-post-types.css'); } add_action( 'admin_enqueue_scripts', 'custom_post_types_enqueue_admin_script' ); function googletagservices() { ?> <script async='async' src='https://www.googletagservices.com/tag/js/gpt.js'></script> <script> var googletag = googletag || {}; googletag.cmd = googletag.cmd || []; </script> <script type="text/javascript"> var resizeTimer; var arrayAds = []; function resizer() { //g.fixedPosition.init(); for(var a in arrayAds) { googletag.pubads().refresh([arrayAds[a]]); } }; window.addEventListener("resize", function(){ clearTimeout(resizeTimer); resizeTimer = setTimeout(resizer, 250); }); </script> <?php } add_action('wp_head', 'googletagservices'); function googleanalytics() { $uaid = ot_get_option('ga_uaid'); ?> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', '<?= $uaid; ?>', 'auto'); ga('send', 'pageview'); </script> <?php } add_action('wp_head', 'googleanalytics'); //Last Issue Widget function latestIssueJCK() { $args = array( 'numberposts' => 1, 'post_type' => 'magazine-issue-item', ); $posts = get_posts($args); foreach($posts as $post): $id = $post->ID; $link = get_permalink($id); $meta = get_post_meta($id); $content = '<div id="footer-col3-left"> <a href="#"><img src="' . $meta['wpcf-magazine-cover'][0] . '"/></a> </div> <div id="footer-col3-right"> <div id="footer-col3-tit"> <strong>Check out</strong> the latest<br> issue of JCK<br> Magazine </div> <div id="footer-col3-butt"><a class="btn small bordered" href="' . $link . '" role="button">Go Now!</a></div> </div>'; endforeach; echo $content; } wp_register_sidebar_widget( 'latest-issue', // your unique widget id 'Latest Issue', // widget name 'latestIssueJCK', // callback function array( // options 'description' => 'Latest JCK Issue', ) ); add_action('widgets_init', 'newsletter_widget'); function newsletter_widget() { register_sidebar([ 'name' => __('Newsletter', 'sage'), 'id' => 'sidebar-newsletter', 'before_widget' => '<section class="newsletter_custom %1$s %2$s">', 'after_widget' => '</section>', 'before_title' => '<h3>', 'after_title' => '</h3>', ]); } function jck_ajax_more_issues() { $qxpg = esc_attr( $_REQUEST['qxpg'] ); $page = esc_attr( $_REQUEST['page'] ); $total = esc_attr( $_REQUEST['total'] ); $offset = $page * $qxpg; if ($total == 0) { $count_query = new WP_Query( array( 'post_type' => 'magazine-issue-item', 'posts_per_page' => 100000, 'offset' => 0, ) ); $total = $count_query->post_count; } $custom_query = new WP_Query( array( 'post_type' => 'magazine-issue-item', 'posts_per_page' => $qxpg, 'offset' => $offset, ) ); while($custom_query->have_posts()) : $custom_query->the_post(); $meta = get_post_meta( get_the_ID() ); $result['html'] .= '<li> <a href="'.get_the_permalink().'"> <figure><img src="'.$meta['wpcf-magazine-cover'][0].'" width="197" height="237"></figure> <p>'.get_the_title().'</p> </a> </li>'; endwhile; echo json_encode( array( 'result' => true, 'total' => $total, 'content' => $result['html'] ) ); exit; } add_action("wp_ajax_jck_ajax_more_issues", "jck_ajax_more_issues"); add_action("wp_ajax_nopriv_jck_ajax_more_issues", "jck_ajax_more_issues"); function ads_shortcode( $atts, $content = null ) { $class = $atts['class']; if(isset($atts['name']) && isset($atts['size-d']) && isset($atts['size-m']) && isset($atts['kw']) && isset($atts['position'])) { $sizes = array(); $sizes['desktop'] = str_replace('x', ',', $atts['size-d']); $sizes['mobile'] = str_replace('x', ',', $atts['size-m']); $name = $atts['name']; $position = $atts['position']; $kw = $atts['kw']; echo print_ad($kw, $name, $sizes, $position, $class); } } add_shortcode('ads', 'ads_shortcode'); function jck_ajax_more_blog_articles() { $categ = esc_attr( $_REQUEST['categ'] ); $cat = get_category_by_slug( $categ ); $qxpg = esc_attr( $_REQUEST['qxpg'] ); $page = esc_attr( $_REQUEST['page'] ); $total = esc_attr( $_REQUEST['total'] ); $offset = $page * $qxpg; if ($total == 0) { $count_query = get_posts( array( 'post_type' => 'editorial-article', 'posts_per_page' => 100000, 'offset' => 0, 'category' => $cat->cat_ID, ) ); $total = count($count_query); } $posts = get_posts( array( 'post_type' => 'editorial-article', 'posts_per_page' => $qxpg, 'offset' => $offset, 'orderby' => 'date', 'order' => 'DESC', 'category' => $cat->cat_ID, ) ); foreach ( $posts as $p) { $meta = get_post_meta( $p->ID ); $link = get_permalink( $p->ID ); if ( isset( $meta['_thumbnail_id'][0] ) ) { $img = wp_get_attachment_image_src($meta['_thumbnail_id'][0], 'thumbnail', false); $image = '<div class="small-12 medium-5 large-6 columns"> <figure class="post-gallery "> <a href="' . $link . '" title="' . $p->post_title . '"><img width="300" height="300" src="' . $img[0] . '" class="attachment-home-thumb size-home-thumb wp-post-image" alt="" sizes="(max-width: 300px) 100vw, 300px"></a> </figure> </div>'; $cls = 'small-12 medium-7 large-6 columns'; } else { $image = ''; $cls = 'small-12 medium-12 large-12 columns'; } $author = get_user_by( 'id', $p->post_author ); $result['html'] .= '<article itemscope="" itemtype="http://schema.org/Article" class="post style1 post-' . $p->ID . ' editorial-article type-editorial-article status-publish hentry category-' . $categ . '" id="post-' . $p->ID . '"> <div class="row align-middle"> ' . $image . ' <div class="' . $cls . '"> <aside class="post-meta cf"> <a class="category" href="/category/news-trends/blogs/' . $categ . '/">' . $cat->name . '</a> </aside> <header class="post-title entry-header"> <h3 itemprop="headline"><a href="' . $link . '" title="' . $p->post_title . '">' . $p->post_title . '</a></h3> </header> <div class="post-content small"> ' . esc_attr( strip_tags( substr( $p->post_content, 0, 79 ) ) ) . '... </div> <aside class="post-author cf"> By ' . esc_attr( $author->display_name ) . ' <span class="pipe">|</span> <time class="time" datetime="' . get_the_date( 'F j, Y', $p->ID ) . '" itemprop="datePublished" content="' . get_the_date( 'F j, Y', $p->ID ) . '">' . get_the_date( 'F j, Y', $p->ID ) . '</time> </aside> </div> </div> </article>'; } echo json_encode( array( 'result' => true, 'total' => $total, 'content' => $result['html'] ) ); exit; } add_action("wp_ajax_jck_ajax_more_blog_articles", "jck_ajax_more_blog_articles"); add_action("wp_ajax_nopriv_jck_ajax_more_blog_articles", "jck_ajax_more_blog_articles"); function sponsored_posts_filter( $query ) { global $pagenow; $value = ''; if (!empty($_GET['sponsors_box_field'])) { $value = $_GET['sponsors_box_field']; } $post_type = ''; if (!empty($_GET['post_type'])) { $post_type = $_GET['post_type']; } // $post_t = $query->query_vars['post_type']; $post_t = get_query_var('post_type'); if ( $post_type == 'sponsored-content' && is_admin() && $pagenow == 'edit.php' && $value != '' && $post_t == 'sponsored-content') { $query->query_vars['meta_query'] = array( 'meta_query' => array( array( 'key' => 'sponsors_box_slug', 'value' => $value, 'compare' => '=', ), ), ); } } add_filter( 'parse_query', 'sponsored_posts_filter' ); function add_post_formats_filter_to_post_administration() { global $post_type; global $post; $sponsor_field = 0; if (!empty($_GET['sponsors_box_field'])) { $sponsor_field = $_GET['sponsors_box_field']; } if($post_type == 'sponsored-content') { sponsors_box_html($post, null, $sponsor_field, true); } } add_action('restrict_manage_posts','add_post_formats_filter_to_post_administration'); add_filter('manage_editorial-article_posts_columns', 'editorial_article_columns_head'); function editorial_article_columns_head($defaults) { $defaults['author'] = 'Author'; return $defaults; } add_action('wp_insert_post', 'fb_share_count_save', 10 , 3); function fb_share_count_save($post_id, $post, $update) { $metadata = get_post_meta($post_id, '_fb_share_count', true); if(!isset($metadata) || $metadata == '') { add_post_meta($post_id, '_fb_share_count', 0); } } add_action('wp_ajax_more_writers', 'more_writers'); add_action('wp_ajax_nopriv_more_writers', 'more_writers'); function more_writers() { $page = $_REQUEST["page"]; $offset = $_REQUEST['offset']; $author = $_REQUEST['author']; $item_count = $_REQUEST["item_count"]; $item_count_limit = $_REQUEST['item_count_limit']; $args = wp_parse_args( array( 'post_type' => array('editorial-article', 'sponsored-content', 'magazine-article'), 'author' => $author, 'posts_per_page' => $item_count_limit, 'offset' => $offset, 'orderby' => 'post_date', 'order' => 'DESC', ) , $args ); $posts = query_posts($args); ob_start(); if(have_posts()) { $i = 1; while ( have_posts() ) : the_post(); get_template_part( 'inc/templates/loop/style1' ); $i++; endwhile; } } // add_filter( 'comments_open', 'my_custom_comments_open',$open, $post_id); add_filter( 'comments_open', 'my_custom_comments_open'); function my_custom_comments_open($post_id = null) { if (!$post_id) { return 'close'; } $_post = get_post( $post_id ); if (!$_post) { return 'close'; } $open = ( 'open' == $_post->comment_status ); $categories = get_the_category($post_id); foreach($categories as $c){ if($c->category_nicename == 'sponsored-content'){ $_post->comment_status = 'close'; } } if ($_post->post_type == 'sponsored-content'){ $_post->comment_status = 'close'; }else{ $_post->comment_status = 'open'; } if ($_post->post_type == 'editorial-article'){ $_post->comment_status = 'open'; } if ($_post->post_type == 'magazine-article'){ $_post->comment_status = 'open'; } return $open; } add_action('admin_head', 'my_custom_fonts'); function my_custom_fonts() { echo '<style> .post-php #categorydiv #category-93 ul li label:before{ content: "How to: "; } .post-php #categorydiv #category-93 ul li label input{ float: left; margin-top: 4px; } </style>'; } add_filter( 'manage_magazine-article_posts_columns', 'jck_add_posts_columns' ); function jck_add_posts_columns( $column ) { $column['author'] = 'Author'; $column['post_author'] = 'Post author'; $column['magazine_issue'] = 'Magazine Issue'; $column['magazine_cover'] = 'Magazine cover'; return $column; } add_filter( 'manage_magazine-article_posts_custom_column', 'jck_add_posts_custom_columns', 10, 3 ); function jck_add_posts_custom_columns( $column_name, $post_id ) { switch ($column_name) { case 'magazine_issue' : $related_magazine_id = get_post_meta($post_id)["_wpcf_belongs_magazine-issue-item_id"][0]; $related_magazine_title = get_post_meta($related_magazine_id)["wpcf-cover-article-title"][0]; echo $related_magazine_title; break; case 'post_author' : $post_author = get_post_meta($post_id)["wpcf-author"][0]; echo $post_author; break; case 'magazine_cover' : $related_magazine_id = get_post_meta($post_id)["_wpcf_belongs_magazine-issue-item_id"][0]; $magazine_cover = get_post_meta($related_magazine_id)["wpcf-magazine-cover"][0]; echo '<img src="'.$magazine_cover.'" width="80"/>'; break; default: } } // open links in new tab for every post_type + comments add_filter('get_comment_author_link', 'open_links_in_new_tab'); add_filter('comment_text', 'open_links_in_new_tab'); add_filter('the_content', 'open_links_in_new_tab'); function open_links_in_new_tab($text) { $return = preg_replace(['/<a (.*?) target=".*?"(.*?)>/i', '/<a (.*?)>/i'], ['<a $1$2>', '<a $1 target="_blank">'], $text); return $return; } function get_excerpt($limit, $source = null){ global $post; $source == "content" ? ($excerpt = get_the_content()) : ($excerpt = get_the_excerpt()); $excerpt = preg_replace(" (\[.*?\])",'',$excerpt); $excerpt = strip_shortcodes($excerpt); $excerpt = strip_tags($excerpt); if(strlen($excerpt) > $limit){ $excerpt = substr($excerpt, 0, $limit); $excerpt = substr($excerpt, 0, strripos($excerpt, " ")); $excerpt = $excerpt.'...'; }else{ $excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt)); } return $excerpt; } /** * JCK Wrapper for OT plugins performance issues. */ $jckoptions = ''; if ( ! function_exists( 'jck_get_option' ) ) { function jck_get_option( $option_id, $default = '' ) { global $jckoptions; if (!$jckoptions) $jckoptions = get_option( ot_options_id() ); /* look for the saved value */ if ( isset( $jckoptions[$option_id] ) && '' != $jckoptions[$option_id] ) { return ot_wpml_filter( $jckoptions, $option_id ); } return $default; } } /** * Looks for post writer and saves it. */ function jck_save_post($pID) { if ( wp_is_post_revision($pID)) return; // Get current post. $cPost = get_post($pID); if ($cPost) if ($cPost->post_type == 'magazine-article') : // Find writer post by post author. $writer = get_posts( array( 'post_type' => 'writer', 'meta_query' => array( array( 'key' => 'users_box_slug', 'value' => $cPost->post_author, 'compare' => '=' ), ) ) ); if (!empty($writer)) update_post_meta($pID, 'post_author_writer', $writer[0]->ID); endif; } add_action('save_post', 'jck_save_post'); function get_post_writer ($pID, $pAuthor) { $wID = (int)get_post_meta($pID, 'post_author_writer', true); if ($wID > 0) : return get_post($wID); else : $writer = get_posts( array( 'post_type' => 'writer', 'meta_query' => array( array( 'key' => 'users_box_slug', 'value' => $pAuthor, 'compare' => '=' ), ) ) ); return $writer[0]; endif; } add_filter('tiny_mce_before_init','TMCEBeforeInit'); function TMCEBeforeInit( $mceInit ) { $mceInit['allow_unsafe_link_target']=true; return $mceInit; } ?>
0.4.18