public function get_wc_slider_ms_slides_shortcode() { if (!isset($this->parsed_slider_data['slides'])) { return ''; } $slides = $this->parsed_slider_data['slides']; $query = array(); $query['image_from'] = $this->parsed_slider_data['setting']['ps_image_from']; $query['excerpt_length'] = $this->parsed_slider_data['setting']['ps_excerpt_len']; $exclude_posts_no_img = $this->parsed_slider_data['setting']['ps_exclude_no_img']; $query['only_featured'] = $this->parsed_slider_data['setting']['wc_only_featured']; $query['only_instock'] = $this->parsed_slider_data['setting']['wc_only_instock']; $query['only_onsale'] = $this->parsed_slider_data['setting']['wc_only_onsale']; if (!empty($this->parsed_slider_data['setting']['ps_post_type'])) { $query['post_type'] = $this->parsed_slider_data['setting']['ps_post_type']; } $query['orderby'] = $this->parsed_slider_data['setting']['ps_orderby']; $query['order'] = $this->parsed_slider_data['setting']['ps_order']; $query['posts_per_page'] = $this->parsed_slider_data['setting']['ps_post_count']; if (!empty($this->parsed_slider_data['setting']['ps_posts_not_in'])) { $posts_not_in = explode(',', $this->parsed_slider_data['setting']['ps_posts_not_in']); $query['post__not_in'] = array_filter($posts_not_in); } if (!empty($this->parsed_slider_data['setting']['ps_posts_in'])) { $posts_in = explode(',', $this->parsed_slider_data['setting']['ps_posts_in']); $query['post__in'] = array_filter($posts_in); } $query['offset'] = $this->parsed_slider_data['setting']['ps_offset']; $taxs_data = array(); if (!empty($this->parsed_slider_data['setting']['ps_tax_term_ids'])) { $taxs_data = explode(',', $this->parsed_slider_data['setting']['ps_tax_term_ids']); } $tax_query = array(); $wcs = msp_get_wc_slider_class(); $query['tax_query'] = $wcs->get_tax_query($taxs_data); $this->post_slider_args = $query; $slides_shortcode = ''; $th_wp_query = $wcs->get_query_results($query); if ($th_wp_query->have_posts()) { while ($th_wp_query->have_posts()) { $th_wp_query->the_post(); $product = get_product($th_wp_query->post); $slide_content = ''; $attrs = ''; $this->post_id = $th_wp_query->post->ID; if (empty($this->parsed_slider_data['setting']['ps_slide_bg'])) { $the_media = msp_get_auto_post_thumbnail_src($th_wp_query->post, $query['image_from']); } else { $the_media = $this->parsed_slider_data['setting']['ps_slide_bg']; } // skip this post if it does not have image and $exclude_posts_no_img is enabled if (empty($the_media) && 'true' == $exclude_posts_no_img) { continue; } $attrs .= sprintf('%s="%s" ', 'src', esc_attr($the_media)); // generate slide_info shortcode if slideinfo control is added if (isset($this->parsed_slider_data['setting']['slideinfo']) && 'true' == $this->parsed_slider_data['setting']['slideinfo']) { if (!empty($slides['0']['info'])) { $slide_info = preg_replace_callback('/{{[\\w-]+}}/', array($this, 'do_template_tag'), $slides['0']['info']); } else { $slide_info = " "; } $slide_content .= $this->get_ms_slide_info_shortcode($slide_info); } if ($this->parsed_slider_data['setting']['ps_link_slide']) { $attrs .= sprintf('%s="%s" ', 'link', get_the_permalink($th_wp_query->post->ID)); } $attrs .= sprintf('%s="%s" ', 'title', $this->escape_square_brackets(get_the_title($th_wp_query->post->ID))); $attrs .= sprintf('%s="%s" ', 'alt', $this->escape_square_brackets(get_the_title($th_wp_query->post->ID))); $attrs .= sprintf('%s="%s" ', 'target', $this->parsed_slider_data['setting']['ps_link_target']); $attrs .= sprintf('%s="%s" ', 'delay', $slides['0']['delay']); // bg color and align for slides $attrs .= sprintf('%s="%s" ', 'bgalign', $slides['0']['bgalign']); $attrs .= sprintf('%s="%s" ', 'bgcolor', $slides['0']['bgcolor']); if ('true' == $this->parsed_slider_data['setting']['thumbs']) { if ('thumbs' == $this->parsed_slider_data['setting']['thumbs_type']) { if (!empty($the_media)) { // set custom thumb size if slider template is gallery if ('image-gallery' == $this->parsed_slider_data['setting']['template']) { $thumb = msp_get_the_resized_image_src($the_media, 175, 140, true); } else { $thumb = msp_get_the_resized_image_src($the_media, $this->parsed_slider_data['setting']['thumbs_width'], $this->parsed_slider_data['setting']['thumbs_height'], true); } $thumb = msp_get_the_relative_media_url($thumb); $attrs .= sprintf('%s="%s" ', 'thumb', $thumb); } else { $tab = '<div class="ms-thumb-alt">' . get_the_title($th_wp_query->post->ID) . '</div>'; $attrs .= sprintf('%s="%s" ', 'tab', $tab); } } elseif ('tabs' == $this->parsed_slider_data['setting']['thumbs_type']) { // if "insert thumb" option was enabled generate and add the thumbnail if ('true' == $this->parsed_slider_data['setting']['thumbs_in_tab']) { $thumb_height = $this->parsed_slider_data['setting']['thumbs_height']; $tab_thumb = msp_get_auto_post_thumbnail_src($the_wp_query->post, 'featured', $thumb_height, $thumb_height, true); $attrs .= sprintf('%s="%s" ', 'tab_thumb', $tab_thumb); } if (!empty($slides['0']['info'])) { $tab_context = preg_replace_callback('/{{[\\w-]+}}/', array($this, 'do_template_tag'), $slides['0']['info']); } else { $tab_context = get_the_title($th_wp_query->post->ID); } $attrs .= sprintf('%s="%s" ', 'tab', $this->escape_special($tab_context)); } } $slide_content .= $this->get_ms_layers_shortcode($slides['0']['layers']); $slides_shortcode .= sprintf('[%1$s %2$s]%4$s%3$s[/%1$s]%4$s', 'ms_slide', $attrs, $slide_content, "\n"); } } // Restore original Post Data wp_reset_postdata(); return $slides_shortcode; }
public function get_posts_result($args) { $slide_image_target = isset($args['image_from']) ? $args['image_from'] : 'auto'; $th_wp_query = $this->get_query_results($args); ob_start(); if ($th_wp_query->have_posts()) { while ($th_wp_query->have_posts()) { $th_wp_query->the_post(); $the_excerpt = get_the_excerpt(); $excerpt_length = isset($args['excerpt_length']) ? $args['excerpt_length'] : ''; if (!empty($excerpt_length)) { $the_excerpt = msp_get_trimmed_string(get_the_excerpt(), (int) $excerpt_length); } $the_media = ''; $the_media_src = msp_get_auto_post_thumbnail_src($th_wp_query->post->ID, $slide_image_target); if (!empty($the_media_src)) { $the_media_tag = msp_get_the_resized_image($the_media_src, 80, 80, true, 100); $the_media = sprintf('<div class="msp-entry-media" ><a href="%s" target="_blank">%s</a></div>', get_the_permalink(), $the_media_tag); } ?> <article class="msp-post msp-post-<?php echo $th_wp_query->post->ID; ?> msp-post-<?php echo $th_wp_query->post->post_type; ?> "> <figure> <?php echo $the_media; ?> <figcaption> <div class="msp-entry-header"> <h4 class="msp-entry-title"><a href="<?php the_permalink(); ?> " target="_blank"><?php the_title(); ?> </a></h4> </div> <div class="msp-entry-content"> <time datetime="<?php the_time('Y-m-d'); ?> " title="<?php the_time('Y-m-d'); ?> " ><?php the_time('F j, Y'); ?> </time> ( <span class="ps-post-id">Post ID: <?php the_ID(); ?> </span> ) <p><?php echo $the_excerpt; ?> </p> </div> </figcaption> </figure> </article> <?php } } return ob_get_clean(); }
function msp_get_template_tag_value($tag_name, $post = null, $args = null) { $post = get_post($post); $value = '{{' . $tag_name . '}}'; switch ($tag_name) { case 'title': $value = $post->post_title; break; case 'content': $value = $post->post_content; break; case 'excerpt': $value = $post->post_excerpt; if (empty($value)) { $excerpt_length = isset($args['excerpt_length']) ? (int) $args['excerpt_length'] : 80; $value = msp_get_the_trim_excerpt($value, $excerpt_length); } break; case 'permalink': $value = $post->guid; break; case 'author': $value = get_the_author_meta('display_name', (int) $post->post_author); break; case 'post_id': $value = $post->ID; break; case 'categories': $taxonomy_objects = get_object_taxonomies($post, 'objects'); $value = ''; foreach ($taxonomy_objects as $tax_name => $tax_info) { if (1 == $tax_info->hierarchical) { $term_list = wp_get_post_terms($post->ID, $tax_name, array("fields" => "names")); $value .= implode(' / ', $term_list); } } $value = rtrim($value, ' / '); break; case 'tags': $taxonomy_objects = get_object_taxonomies($post, 'objects'); $value = ''; foreach ($taxonomy_objects as $tax_name => $tax_info) { if (1 !== $tax_info->hierarchical) { $term_list = wp_get_post_terms($post->ID, $tax_name, array("fields" => "names")); $value .= implode(' / ', $term_list) . ' / '; } } $value = rtrim($value, ' / '); break; case 'image': $value = msp_get_auto_post_thumbnail_src($post, 'featured'); if (!empty($value)) { $value = sprintf('<img src="%s" alt="%s" />', $value, $post->post_title); } break; case 'image-url': case 'slide-image-url': $value = msp_get_auto_post_thumbnail_src($post, 'auto'); break; case 'year': $value = strtotime($post->post_date); $value = date_i18n('Y', $value); break; case 'daynum': $value = strtotime($post->post_date); $value = date_i18n('j', $value); break; case 'day': $value = strtotime($post->post_date); $value = date_i18n('l', $value); break; case 'monthnum': $value = strtotime($post->post_date); $value = date_i18n('m', $value); break; case 'month': $value = strtotime($post->post_date); $value = date_i18n('F', $value); break; case 'time': $value = strtotime($post->post_date); $value = date_i18n('g:i A', $value); break; case 'date-published': $value = $post->post_date; break; case 'date-modified': $value = $post->post_modified; break; case 'commentnum': $value = $post->comment_count; break; case 'wc_price': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = wc_format_decimal($product->get_price(), 2); break; case 'wc_regular_price': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = wc_format_decimal($product->get_regular_price(), 2); break; case 'wc_sale_price': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = $product->get_sale_price() ? wc_format_decimal($product->get_sale_price(), 2) : ''; break; case 'wc_stock_status': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = $product->is_in_stock() ? __('In Stock', 'master-slider') : __('Out of Stock', 'master-slider'); break; case 'wc_stock_quantity': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = (int) $product->get_stock_quantity(); break; case 'wc_weight': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = $product->get_weight() ? wc_format_decimal($product->get_weight(), 2) : ''; break; case 'wc_product_cats': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = wp_get_post_terms($product->id, 'product_cat', array('fields' => 'names')); break; case 'wc_product_tags': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = wp_get_post_terms($product->id, 'product_tag', array('fields' => 'names')); break; case 'wc_total_sales': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = metadata_exists('post', $product->id, 'total_sales') ? (int) get_post_meta($product->id, 'total_sales', true) : 0; break; case 'wc_average_rating': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = wc_format_decimal($product->get_average_rating(), 2); break; case 'wc_rating_count': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = (int) $product->get_rating_count(); break; default: $value = get_post_meta($post->ID, $tag_name, true); break; } return apply_filters('masterslider_get_template_tag_value', $value, $tag_name, $post, $args); }
function msp_get_template_tag_value($tag_name, $post = null, $args = null) { $post = get_post($post); $value = '{{' . $tag_name . '}}'; switch ($tag_name) { case 'title': $value = $post->post_title; break; case 'linked_title': $value = sprintf('<a href="%s" >%s</a>', $post->guid, $post->post_title); break; case 'content': $value = $post->post_content; break; case 'excerpt': $excerpt_length = isset($args['excerpt_length']) ? (int) $args['excerpt_length'] : 80; $value = msp_get_the_excerpt_by_id($post->ID, $excerpt_length); break; case 'permalink': $value = $post->guid; break; case 'author': $value = get_the_author_meta('display_name', (int) $post->post_author); break; case 'post_id': $value = $post->ID; break; case 'categories': $taxonomy_objects = get_object_taxonomies($post, 'objects'); $value = ''; foreach ($taxonomy_objects as $tax_name => $tax_info) { if (1 == $tax_info->hierarchical) { $term_list = wp_get_post_terms($post->ID, $tax_name, array("fields" => "names")); $value .= implode(' / ', $term_list); } } $value = rtrim($value, ' / '); break; case 'tags': $taxonomy_objects = get_object_taxonomies($post, 'objects'); $value = ''; foreach ($taxonomy_objects as $tax_name => $tax_info) { if (1 !== $tax_info->hierarchical) { $term_list = wp_get_post_terms($post->ID, $tax_name, array("fields" => "names")); $value .= implode(' / ', $term_list) . ' / '; } } $value = rtrim($value, ' / '); break; case 'image': $value = msp_get_auto_post_thumbnail_src($post, 'featured'); if (!empty($value)) { $value = sprintf('<img src="%s" alt="%s" />', $value, $post->post_title); } break; case 'image-url': case 'slide-image-url': $value = msp_get_auto_post_thumbnail_src($post, 'auto'); break; case 'thumbnail': $value = msp_get_auto_post_thumbnail_src($post, 'featured', 150, 150); if (!empty($value)) { $value = sprintf('<img src="%s" alt="%s" />', $value, $post->post_title); } break; case 'thumbnailurl': $value = msp_get_auto_post_thumbnail_src($post, 'auto', 150, 150); break; case 'year': $value = strtotime($post->post_date); $value = date_i18n('Y', $value); break; case 'daynum': $value = strtotime($post->post_date); $value = date_i18n('j', $value); break; case 'day': $value = strtotime($post->post_date); $value = date_i18n('l', $value); break; case 'monthnum': $value = strtotime($post->post_date); $value = date_i18n('m', $value); break; case 'month': $value = strtotime($post->post_date); $value = date_i18n('F', $value); break; case 'time': $value = strtotime($post->post_date); $value = date_i18n('g:i A', $value); break; case 'date-published': $value = $post->post_date; break; case 'date-modified': $value = $post->post_modified; break; case 'commentnum': $value = $post->comment_count; break; case 'wc_price': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = wc_format_decimal($product->get_price(), 2); break; case 'wc_regular_price': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = wc_format_decimal($product->get_regular_price(), 2); break; case 'wc_sale_price': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = $product->get_sale_price() ? wc_format_decimal($product->get_sale_price(), 2) : ''; break; case 'wc_stock_status': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = $product->is_in_stock() ? __('In Stock', MSWP_TEXT_DOMAIN) : __('Out of Stock', MSWP_TEXT_DOMAIN); break; case 'wc_stock_quantity': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = (int) $product->get_stock_quantity(); break; case 'wc_weight': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = $product->get_weight() ? wc_format_decimal($product->get_weight(), 2) : ''; break; case 'wc_product_cats': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = wp_get_post_terms($product->id, 'product_cat', array('fields' => 'names')); break; case 'wc_product_tags': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = wp_get_post_terms($product->id, 'product_tag', array('fields' => 'names')); break; case 'wc_total_sales': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = metadata_exists('post', $product->id, 'total_sales') ? (int) get_post_meta($product->id, 'total_sales', true) : 0; break; case 'wc_average_rating': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = wc_format_decimal($product->get_average_rating(), 2); break; case 'wc_rating_count': if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } $product = get_product($post); $value = (int) $product->get_rating_count(); break; default: // if the tag is {{content-150}} with dynamic length if (strpos($tag_name, 'content-') !== false) { preg_match("/([\\d]{1,})/", $tag_name, $matches); if (isset($matches[0]) && is_numeric($matches[0])) { $excerpt_length = (int) $matches[0]; $value = msp_get_the_trim_excerpt($post->ID, $excerpt_length); break; } // if the tag is {{wc_price-2}} with dynamic points length } elseif (strpos($tag_name, 'wc_price-') !== false) { if (!msp_is_plugin_active('woocommerce/woocommerce.php')) { break; } preg_match("/([\\d]{1,})/", $tag_name, $matches); if (isset($matches[0]) && is_numeric($matches[0])) { $points_length = (int) $matches[0]; $product = get_product($post); $value = wc_format_decimal($product->get_price(), $points_length); break; } // if the tag is {{thumbnail-150x150}} with dynamic dimensions } elseif (strpos($tag_name, 'image-') !== false) { preg_match_all("/([\\d]{1,})/", $tag_name, $matches); if (isset($matches[0])) { $image_width = isset($matches[0][0]) && is_numeric($matches[0][0]) ? (int) $matches[0][0] : null; $image_height = isset($matches[0][1]) && is_numeric($matches[0][1]) ? (int) $matches[0][1] : null; $value = msp_get_auto_post_thumbnail_src($post, 'featured', $image_width, $image_height, true); if (!empty($value)) { $value = sprintf('<img class="ms-custom-image" src="%s" alt="%s" />', $value, $post->post_title); } break; } // if the tag is {{thumbnail-150x150}} with dynamic dimensions } elseif (strpos($tag_name, 'thumbnail-') !== false) { preg_match_all("/([\\d]{1,})/", $tag_name, $matches); if (isset($matches[0])) { $thumb_width = isset($matches[0][0]) && is_numeric($matches[0][0]) ? (int) $matches[0][0] : null; $thumb_height = isset($matches[0][1]) && is_numeric($matches[0][1]) ? (int) $matches[0][1] : null; $value = msp_get_auto_post_thumbnail_src($post, 'featured', $thumb_width, $thumb_height, true); if (!empty($value)) { $value = sprintf('<img class="ms-tab-thumb" src="%s" alt="%s" />', $value, $post->post_title); } break; } // if the tag is {{thumbnail-url-150x150}} with dynamic dimensions } elseif (strpos($tag_name, 'thumbnailurl-') !== false) { preg_match_all("/([\\d]{1,})/", $tag_name, $matches); if (isset($matches[0])) { $thumb_width = isset($matches[0][0]) && is_numeric($matches[0][0]) ? (int) $matches[0][0] : null; $thumb_height = isset($matches[0][1]) && is_numeric($matches[0][1]) ? (int) $matches[0][1] : null; $value = msp_get_auto_post_thumbnail_src($post, 'featured', $thumb_width, $thumb_height, true); break; } } $value = get_post_meta($post->ID, $tag_name, true); break; } return apply_filters('masterslider_get_template_tag_value', $value, $tag_name, $post, $args); }
function msp_get_auto_post_thumbnail_url($post_id = null, $image_from = 'auto', $size = 'full', $crop = null, $quality = 100) { $image = msp_get_auto_post_thumbnail_src($post_id, $image_from, $size, $crop, $quality); return isset($image[0]) && !empty($image[0]) ? $image[0] : false; }
public function get_posts_result($args) { $slide_image_target = isset($args['image_from']) ? $args['image_from'] : 'auto'; $th_wp_query = $this->get_query_results($args); ob_start(); if ($th_wp_query->have_posts()) { while ($th_wp_query->have_posts()) { $th_wp_query->the_post(); $product = get_product($th_wp_query->post->ID); $the_excerpt = apply_filters('woocommerce_short_description', $product->get_post_data()->post_excerpt); $excerpt_length = isset($args['excerpt_length']) ? $args['excerpt_length'] : ''; if (!empty($excerpt_length)) { $the_excerpt = msp_get_trimmed_string($the_excerpt, (int) $excerpt_length); } $the_media = ''; $the_media_src = msp_get_auto_post_thumbnail_src($th_wp_query->post->ID, $slide_image_target); $premalink = $product->get_permalink(); if (!empty($the_media_src)) { $the_media_tag = msp_get_the_resized_image($the_media_src, 80, 80, true, 100); $the_media = sprintf('<div class="msp-entry-media" ><a href="%s" target="_blank">%s</a></div>', $premalink, $the_media_tag); } ?> <article class="msp-post msp-post-<?php echo $th_wp_query->post->ID; ?> msp-post-<?php echo $th_wp_query->post->post_type; ?> "> <figure> <?php echo $the_media; ?> <figcaption> <div class="msp-entry-header"> <h4 class="msp-entry-title"><a href="<?php echo $premalink; ?> " target="_blank"><?php the_title(); ?> </a></h4> </div> <div class="msp-entry-content"> <time datetime="<?php the_time('Y-m-d'); ?> " title="<?php the_time('Y-m-d'); ?> " ><?php the_time('F j, Y'); ?> </time> ( <span class="ps-post-id">Post ID: <?php the_ID(); ?> </span> ) <?php if ($regular_price = wc_format_decimal($product->get_regular_price(), 2)) { ?> ( <span class="regular-price"><?php _e('Regular Price', MSWP_TEXT_DOMAIN); echo ': ' . $regular_price; ?> </span> ) <?php } ?> <?php if ($sale_price = $product->get_sale_price() ? wc_format_decimal($product->get_sale_price(), 2) : null) { ?> ( <span class="sale-price"><?php _e('Sale Price', MSWP_TEXT_DOMAIN); echo ': ' . $sale_price; ?> </span> ) <?php } ?> <p><?php echo $the_excerpt; ?> </p> </div> </figcaption> </figure> </article> <?php } } // Restore original Post Data wp_reset_query(); return ob_get_clean(); }