diff --git a/templates/sc-swiper-card-autoplay.php b/templates/sc-swiper-card-autoplay.php index 40b9494..a8a4d80 100644 --- a/templates/sc-swiper-card-autoplay.php +++ b/templates/sc-swiper-card-autoplay.php @@ -42,7 +42,7 @@ function bootscore_swiper_autoplay($atts) { ob_start(); - extract(shortcode_atts(array( + $atts = shortcode_atts(array( 'type' => 'post', 'order' => 'date', 'orderby' => 'date', @@ -55,19 +55,19 @@ function bootscore_swiper_autoplay($atts) { 'excerpt' => 'true', 'tags' => 'true', 'categories' => 'true', - ), $atts)); + ), $atts); $options = array( - 'post_type' => $type, - 'order' => $order, - 'orderby' => $orderby, - 'posts_per_page' => $posts, - 'category_name' => $category, - 'post_parent' => $post_parent, + 'post_type' => sanitize_text_field($atts['type']), + 'order' => sanitize_text_field($atts['order']), + 'orderby' => sanitize_text_field($atts['orderby']), + 'posts_per_page' => is_numeric($atts['posts']) ? (int) $atts['posts'] : -1, + 'category_name' => sanitize_text_field($atts['category']), + 'post_parent' => is_numeric($atts['post_parent']) ? (int) $atts['post_parent'] : '', ); - $tax = trim($tax); - $terms = trim($terms); + $tax = trim(sanitize_text_field($atts['tax'])); + $terms = trim(sanitize_text_field($atts['terms'])); if ($tax != '' && $terms != '') { $terms = explode(',', $terms); $terms = array_map('trim', $terms); @@ -81,8 +81,8 @@ function bootscore_swiper_autoplay($atts) { )); } - if ($id != '') { - $ids = explode(',', $id); + if ($atts['id'] != '') { + $ids = explode(',', sanitize_text_field($atts['id'])); $ids = array_map('intval', $ids); $ids = array_filter($ids); $ids = array_unique($ids); @@ -112,7 +112,7 @@ function bootscore_swiper_autoplay($atts) {
= strip_tags(get_the_excerpt()); ?> @@ -145,7 +145,7 @@ function bootscore_swiper_autoplay($atts) {
- + diff --git a/templates/sc-swiper-card-product.php b/templates/sc-swiper-card-product.php index 37dc99f..43ab29f 100644 --- a/templates/sc-swiper-card-product.php +++ b/templates/sc-swiper-card-product.php @@ -14,41 +14,46 @@ * [bs-swiper-card-product] * * Optional: - * category="cars, boats" Will pull products matching these categories (Default: '') - * id="1, 2, 3" Will show products matching these ids (Default: '') - * posts="12" Specify how many products will be shown (Default: 12) - * orderby="date" Specify how products will be ordered by (Default: date) * order="DESC" Specify if products will be ordered ASC or DESC (Default: DESC) - * featured="true" Will pull featured products (Default: false) - * outofstock="false" Will hide out of stock products (Default: true) + * orderby="date" Specify how products will be ordered by (Default: date) + * posts="12" Specify how many products will be shown (Default: -1) + * id="1, 2, 3" Will show products matching these ids (Default: '') + * category="cars, boats" Will pull products matching these categories (Default: '') + * brand="brand1, brand2" Will pull products matching these brands (Default: '') + * featured="true" Will pull featured products (Default: '') + * outofstock="true" Will show out of stock products (Default: '') + * onsale="true" Will show only onsale products (Default: '') * */ // Exit if accessed directly -defined( 'ABSPATH' ) || exit; +defined('ABSPATH') || exit; // Product Slider Shortcode add_shortcode('bs-swiper-card-product', 'bootscore_product_slider'); -function bootscore_product_slider($atts) { +function bootscore_product_slider($atts) +{ ob_start(); $atts = shortcode_atts(array( 'type' => 'product', 'order' => 'DESC', 'orderby' => 'date', - 'limit' => 12, - 'id' => '', + 'posts' => -1, + 'id' => '', 'category' => '', + 'brand' => '', 'featured' => '', 'outofstock' => '', + 'onsale' => '', ), $atts); $options = array( 'order' => sanitize_text_field($atts['order']), 'orderby' => sanitize_text_field($atts['orderby']), - 'posts_per_page' => is_numeric($atts['limit']) ? (int) $atts['limit'] : 12, + 'posts_per_page' => is_numeric($atts['posts']) ? (int) $atts['posts'] : -1, 'product_cat' => sanitize_text_field($atts['category']), 'post_type' => sanitize_text_field($atts['type']), ); @@ -57,6 +62,14 @@ function bootscore_product_slider($atts) { $options['post__in'] = array_map('trim', explode(',', sanitize_text_field($atts['id']))); } + if ($atts['brand']) { + $options['tax_query'][] = array( + 'taxonomy' => 'brand', + 'field' => 'slug', + 'terms' => array_map('trim', explode(',', sanitize_text_field($atts['brand']))), + ); + } + if ($atts['featured'] == 'true') { $options['tax_query'][] = array( 'taxonomy' => 'product_visibility', @@ -66,7 +79,7 @@ function bootscore_product_slider($atts) { ); } - if ($atts['outofstock'] == 'false') { + if ($atts['outofstock'] != 'true') { $options['meta_query'] = array( array( 'key' => '_stock_status', @@ -76,6 +89,24 @@ function bootscore_product_slider($atts) { ); } + if ($atts['onsale'] == 'true') { + $options['meta_query'][] = array( + 'relation' => 'OR', + array( + 'key' => '_sale_price', + 'value' => 0, + 'compare' => '>', + 'type' => 'numeric' + ), + array( + 'key' => '_min_variation_sale_price', + 'value' => 0, + 'compare' => '>', + 'type' => 'numeric' + ), + ); + } + $query = new WP_Query($options); if ($query->have_posts()) { ?> diff --git a/templates/sc-swiper-card.php b/templates/sc-swiper-card.php index 4c3156d..97fee35 100644 --- a/templates/sc-swiper-card.php +++ b/templates/sc-swiper-card.php @@ -42,7 +42,7 @@ function bootscore_swiper($atts) { ob_start(); - extract(shortcode_atts(array( + $atts = shortcode_atts(array( 'type' => 'post', 'order' => 'date', 'orderby' => 'date', @@ -55,19 +55,19 @@ function bootscore_swiper($atts) { 'excerpt' => 'true', 'tags' => 'true', 'categories' => 'true', - ), $atts)); + ), $atts); $options = array( - 'post_type' => $type, - 'order' => $order, - 'orderby' => $orderby, - 'posts_per_page' => $posts, - 'category_name' => $category, - 'post_parent' => $post_parent, + 'post_type' => sanitize_text_field($atts['type']), + 'order' => sanitize_text_field($atts['order']), + 'orderby' => sanitize_text_field($atts['orderby']), + 'posts_per_page' => is_numeric($atts['posts']) ? (int) $atts['posts'] : -1, + 'category_name' => sanitize_text_field($atts['category']), + 'post_parent' => is_numeric($atts['post_parent']) ? (int) $atts['post_parent'] : '', ); - $tax = trim($tax); - $terms = trim($terms); + $tax = trim(sanitize_text_field($atts['tax'])); + $terms = trim(sanitize_text_field($atts['terms'])); if ($tax != '' && $terms != '') { $terms = explode(',', $terms); $terms = array_map('trim', $terms); @@ -81,8 +81,8 @@ function bootscore_swiper($atts) { )); } - if ($id != '') { - $ids = explode(',', $id); + if ($atts['id'] != '') { + $ids = explode(',', sanitize_text_field($atts['id'])); $ids = array_map('intval', $ids); $ids = array_filter($ids); $ids = array_unique($ids); @@ -112,7 +112,7 @@ function bootscore_swiper($atts) {= strip_tags(get_the_excerpt()); ?> @@ -145,7 +145,7 @@ function bootscore_swiper($atts) {
- + diff --git a/templates/sc-swiper-hero-fade.php b/templates/sc-swiper-hero-fade.php index cdc94fb..5686da7 100644 --- a/templates/sc-swiper-hero-fade.php +++ b/templates/sc-swiper-hero-fade.php @@ -42,7 +42,7 @@ function bootscore_swiper_hero_fade($atts) { ob_start(); - extract(shortcode_atts(array( + $atts = shortcode_atts(array( 'type' => 'post', 'order' => 'date', 'orderby' => 'date', @@ -55,19 +55,19 @@ function bootscore_swiper_hero_fade($atts) { 'excerpt' => 'true', 'tags' => 'true', 'categories' => 'true', - ), $atts)); + ), $atts); $options = array( - 'post_type' => $type, - 'order' => $order, - 'orderby' => $orderby, - 'posts_per_page' => $posts, - 'category_name' => $category, - 'post_parent' => $post_parent, + 'post_type' => sanitize_text_field($atts['type']), + 'order' => sanitize_text_field($atts['order']), + 'orderby' => sanitize_text_field($atts['orderby']), + 'posts_per_page' => is_numeric($atts['posts']) ? (int) $atts['posts'] : -1, + 'category_name' => sanitize_text_field($atts['category']), + 'post_parent' => is_numeric($atts['post_parent']) ? (int) $atts['post_parent'] : '', ); - $tax = trim($tax); - $terms = trim($terms); + $tax = trim(sanitize_text_field($atts['tax'])); + $terms = trim(sanitize_text_field($atts['terms'])); if ($tax != '' && $terms != '') { $terms = explode(',', $terms); $terms = array_map('trim', $terms); @@ -81,8 +81,8 @@ function bootscore_swiper_hero_fade($atts) { )); } - if ($id != '') { - $ids = explode(',', $id); + if ($atts['id'] != '') { + $ids = explode(',', sanitize_text_field($atts['id'])); $ids = array_map('intval', $ids); $ids = array_filter($ids); $ids = array_unique($ids); @@ -111,7 +111,7 @@ function bootscore_swiper_hero_fade($atts) {= strip_tags(get_the_excerpt()); ?> @@ -136,7 +136,7 @@ function bootscore_swiper_hero_fade($atts) {
- + diff --git a/templates/sc-swiper-hero.php b/templates/sc-swiper-hero.php index 58e5c76..67ec00f 100644 --- a/templates/sc-swiper-hero.php +++ b/templates/sc-swiper-hero.php @@ -42,7 +42,7 @@ function bootscore_swiper_hero($atts) { ob_start(); - extract(shortcode_atts(array( + $atts = shortcode_atts(array( 'type' => 'post', 'order' => 'date', 'orderby' => 'date', @@ -55,19 +55,19 @@ function bootscore_swiper_hero($atts) { 'excerpt' => 'true', 'tags' => 'true', 'categories' => 'true', - ), $atts)); + ), $atts); $options = array( - 'post_type' => $type, - 'order' => $order, - 'orderby' => $orderby, - 'posts_per_page' => $posts, - 'category_name' => $category, - 'post_parent' => $post_parent, + 'post_type' => sanitize_text_field($atts['type']), + 'order' => sanitize_text_field($atts['order']), + 'orderby' => sanitize_text_field($atts['orderby']), + 'posts_per_page' => is_numeric($atts['posts']) ? (int) $atts['posts'] : -1, + 'category_name' => sanitize_text_field($atts['category']), + 'post_parent' => is_numeric($atts['post_parent']) ? (int) $atts['post_parent'] : '', ); - $tax = trim($tax); - $terms = trim($terms); + $tax = trim(sanitize_text_field($atts['tax'])); + $terms = trim(sanitize_text_field($atts['terms'])); if ($tax != '' && $terms != '') { $terms = explode(',', $terms); $terms = array_map('trim', $terms); @@ -81,8 +81,8 @@ function bootscore_swiper_hero($atts) { )); } - if ($id != '') { - $ids = explode(',', $id); + if ($atts['id'] != '') { + $ids = explode(',', sanitize_text_field($atts['id'])); $ids = array_map('intval', $ids); $ids = array_filter($ids); $ids = array_unique($ids); @@ -111,7 +111,7 @@ function bootscore_swiper_hero($atts) {= strip_tags(get_the_excerpt()); ?> @@ -136,7 +136,7 @@ function bootscore_swiper_hero($atts) {
- +