diff --git a/admin/js/admin-scripts.js b/admin/js/admin-scripts.js index b5669c1..7f093ee 100644 --- a/admin/js/admin-scripts.js +++ b/admin/js/admin-scripts.js @@ -226,6 +226,32 @@ jQuery( document ).ready( function( $ ) { } }); + // Edit link location + if ( ! $( '#wpsp-include-edit-link' ).is( ':checked' ) ) { + $( '#butterbean-control-wpsp_edit_link_location' ).hide(); + } + + $( '#wpsp-include-edit-link' ).change(function() { + if ( ! this.checked ) { + $( '#butterbean-control-wpsp_edit_link_location' ).hide(); + } else { + $( '#butterbean-control-wpsp_edit_link_location' ).show(); + } + }); + + // Add item location + if ( ! $( '#wpsp-include-add-item' ).is( ':checked' ) ) { + $( '#butterbean-control-wpsp_add_item_location' ).hide(); + } + + $( '#wpsp-include-add-item' ).change(function() { + if ( ! this.checked ) { + $( '#butterbean-control-wpsp_add_item_location' ).hide(); + } else { + $( '#butterbean-control-wpsp_add_item_location' ).show(); + } + }); + // Dealing with the social options $( '#wpsp-social-sharing' ).parent().parent().siblings().hide(); if ( $( '#wpsp-social-sharing' ).is( ':checked' ) ) { diff --git a/admin/metabox.php b/admin/metabox.php index bf30565..f438b8f 100644 --- a/admin/metabox.php +++ b/admin/metabox.php @@ -389,8 +389,31 @@ function wpsp_register( $butterbean, $post_type ) { ) ); + $manager->register_control( + 'wpsp_list_type', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_content', + 'label' => esc_html__( 'List type', 'wp-show-posts' ), + 'choices' => array( + 'ordered' => __( 'Ordered','wp-show-posts' ), + 'unordered' => __( 'Unordered','wp-show-posts' ), + 'none' => __( 'None','wp-show-posts' ) + ), + 'attr' => array( 'id' => 'wpsp-list-type' ) + ) + ); + + $manager->register_setting( + 'wpsp_list_type', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_list_type' ] ? $defaults[ 'wpsp_list_type' ] : 'none' + ) + ); + $manager->register_control( - 'wpsp_excerpt_length', // Same as setting name. + 'wpsp_excerpt_length', // Same as setting name. array( 'type' => 'number', 'section' => 'wpsp_content', @@ -471,6 +494,23 @@ function wpsp_register( $butterbean, $post_type ) { ) ); + $manager->register_control( + 'wpsp_in_text_link', // Same as setting name. + array( + 'type' => 'text', + 'section' => 'wpsp_content', + 'label' => esc_html__( 'In text link', 'wp-show-posts' ) + ) + ); + + $manager->register_setting( + 'wpsp_in_text_link', // Same as control name. + array( + 'sanitize_callback' => 'wp_kses_post', + 'default' => $defaults[ 'wpsp_in_text_link' ] ? $defaults[ 'wpsp_in_text_link' ] : '' + ) + ); + $manager->register_section( 'wpsp_post_meta', array( @@ -599,6 +639,86 @@ function wpsp_register( $butterbean, $post_type ) { ) ); + $manager->register_control( + 'wpsp_include_edit_link', + array( + 'type' => 'checkbox', + 'section' => 'wpsp_post_meta', + 'label' => __( 'Include edit link (only admins will see it)','wp-show-posts' ), + 'attr' => array( 'id' => 'wpsp-include-edit-link' ) + ) + ); + + $manager->register_setting( + 'wpsp_include_edit_link', + array( + 'sanitize_callback' => 'butterbean_validate_boolean', + 'default' => $defaults[ 'wpsp_include_edit_link' ] ? $defaults[ 'wpsp_include_edit_link' ] : false + ) + ); + + $manager->register_control( + 'wpsp_edit_link_location', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_post_meta', + 'label' => esc_html__( 'Edit link location', 'wp-show-posts' ), + 'choices' => array( + 'below-title' => __( 'Below title','wp-show-posts' ), + 'below-post' => __( 'Below post','wp-show-posts' ) + ), + 'attr' => array( 'id' => 'wpsp-edit-link-location' ) + ) + ); + + $manager->register_setting( + 'wpsp_edit_link_location', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_edit_link_location' ] ? $defaults[ 'wpsp_edit_link_location' ] : '' + ) + ); + + $manager->register_control( + 'wpsp_include_add_item', + array( + 'type' => 'checkbox', + 'section' => 'wpsp_post_meta', + 'label' => __( 'Include add item link (only admins will see it)','wp-show-posts' ), + 'attr' => array( 'id' => 'wpsp-include-add-item' ) + ) + ); + + $manager->register_setting( + 'wpsp_include_add_item', + array( + 'sanitize_callback' => 'butterbean_validate_boolean', + 'default' => $defaults[ 'wpsp_include_add_item' ] ? $defaults[ 'wpsp_include_add_item' ] : false + ) + ); + + $manager->register_control( + 'wpsp_add_item_location', // Same as setting name. + array( + 'type' => 'select', + 'section' => 'wpsp_post_meta', + 'label' => esc_html__( 'Add item location', 'wp-show-posts' ), + 'choices' => array( + 'right' => __( 'Upper right','wp-show-posts' ), + 'left' => __( 'Upper left','wp-show-posts' ) + ), + 'attr' => array( 'id' => 'wpsp-edit-link-location' ) + ) + ); + + $manager->register_setting( + 'wpsp_add_item_location', // Same as control name. + array( + 'sanitize_callback' => 'sanitize_text_field', + 'default' => $defaults[ 'wpsp_add_item_location' ] ? $defaults[ 'wpsp_add_item_location' ] : '' + ) + ); + $manager->register_control( 'wpsp_include_comments', array( diff --git a/inc/compat.php b/inc/compat.php index 699ba52..80f58bb 100644 --- a/inc/compat.php +++ b/inc/compat.php @@ -1,7 +1,6 @@ '', - 'wpsp_author_location' => 'below-post', - 'wpsp_columns' => 'col-6', - 'wpsp_columns_gutter' => '2em', - 'wpsp_content_type' => 'excerpt', - 'wpsp_date_location' => 'below-title', - 'wpsp_exclude_current' => false, - 'wpsp_excerpt_length' => 30, - 'wpsp_post_id' => '', - 'wpsp_exclude_post_id' => '', - 'wpsp_ignore_sticky_posts' => false, - 'wpsp_image' => true, - 'wpsp_image_alignment' => 'center', - 'wpsp_image_height' => '', - 'wpsp_image_location' => 'below-title', - 'wpsp_image_width' => '', - 'wpsp_include_title' => true, - 'wpsp_title_element' => 'h2', - 'wpsp_include_terms' => false, - 'wpsp_include_author' => false, - 'wpsp_include_date' => true, - 'wpsp_include_comments' => false, - 'wpsp_comments_location' => 'below-post', - 'wpsp_inner_wrapper' => 'article', - 'wpsp_inner_wrapper_class' => '', - 'wpsp_inner_wrapper_style' => '', - 'wpsp_itemtype' => 'CreativeWork', - 'wpsp_meta_key' => '', - 'wpsp_meta_value' => '', - 'wpsp_offset' => 0, - 'wpsp_order' => 'DESC', - 'wpsp_orderby' => 'date', - 'wpsp_pagination' => false, - 'wpsp_post_meta_bottom_style' => 'stack', - 'wpsp_post_meta_top_style' => 'inline', - 'wpsp_post_status' => 'publish', - 'wpsp_post_type' => 'post', - 'wpsp_posts_per_page' => 10, - 'wpsp_read_more_text' => '', - 'wpsp_tax_operator' => 'IN', - 'wpsp_tax_term' => '', - 'wpsp_taxonomy' => 'category', - 'wpsp_terms_location' => 'below-post', - 'wpsp_wrapper' => 'section', - 'wpsp_wrapper_class' => '', - 'wpsp_wrapper_id' => false, - 'wpsp_wrapper_style' => '', - 'wpsp_no_results' => __( 'Sorry, no posts were found.','wp-show-posts' ) - ); + /** + * Set all of our defaults + * @since 0.1 + */ + function wpsp_get_defaults() { + $defaults = array( + 'wpsp_author' => '', + 'wpsp_author_location' => 'below-post', + 'wpsp_columns' => 'col-6', + 'wpsp_columns_gutter' => '2em', + 'wpsp_content_type' => 'excerpt', + 'wpsp_list_type' => 'none', + 'wpsp_date_location' => 'below-title', + 'wpsp_exclude_current' => false, + 'wpsp_excerpt_length' => 30, + 'wpsp_post_id' => '', + 'wpsp_exclude_post_id' => '', + 'wpsp_ignore_sticky_posts' => false, + 'wpsp_image' => true, + 'wpsp_image_alignment' => 'center', + 'wpsp_image_height' => '', + 'wpsp_image_location' => 'below-title', + 'wpsp_image_width' => '', + 'wpsp_include_title' => true, + 'wpsp_title_element' => 'h2', + 'wpsp_include_terms' => false, + 'wpsp_include_author' => false, + 'wpsp_include_date' => true, + 'wpsp_include_add_item' => false, + 'wpsp_add_item_location' => 'below-post', + 'wpsp_include_edit_link' => false, + 'wpsp_edit_link_location' => 'below-post', + 'wpsp_include_comments' => false, + 'wpsp_comments_location' => 'below-post', + 'wpsp_inner_wrapper' => 'article', + 'wpsp_inner_wrapper_class' => '', + 'wpsp_inner_wrapper_style' => '', + 'wpsp_itemtype' => 'CreativeWork', + 'wpsp_meta_key' => '', + 'wpsp_meta_value' => '', + 'wpsp_offset' => 0, + 'wpsp_order' => 'DESC', + 'wpsp_orderby' => 'date', + 'wpsp_pagination' => false, + 'wpsp_post_meta_bottom_style' => 'stack', + 'wpsp_post_meta_top_style' => 'inline', + 'wpsp_post_status' => 'publish', + 'wpsp_post_type' => 'post', + 'wpsp_posts_per_page' => 10, + 'wpsp_read_more_text' => '', + 'wpsp_in_text_link' => '', + 'wpsp_tax_operator' => 'IN', + 'wpsp_tax_term' => '', + 'wpsp_taxonomy' => 'category', + 'wpsp_terms_location' => 'below-post', + 'wpsp_wrapper' => 'section', + 'wpsp_wrapper_class' => '', + 'wpsp_wrapper_id' => false, + 'wpsp_wrapper_style' => '', + 'wpsp_no_results' => __( 'Sorry, no posts were found.','wp-show-posts' ) + ); - return apply_filters( 'wpsp_defaults', $defaults ); - } + return apply_filters( 'wpsp_defaults', $defaults ); + } } diff --git a/inc/functions.php b/inc/functions.php index 71e8f74..59ba9cc 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -37,6 +37,21 @@ function wpsp_excerpt() { } } +if ( ! function_exists( 'wpsp_get_the_excerpt' ) ) { + /** + * Build our excerpt + * @since 0.9 + */ + function wpsp_get_the_excerpt() { + add_filter( 'excerpt_length', 'wpsp_excerpt_length', 999 ); + add_filter( 'excerpt_more', 'wpsp_excerpt_more', 999 ); + $excerpt = get_the_excerpt(); + remove_filter( 'excerpt_length', 'wpsp_excerpt_length', 999 ); + remove_filter( 'excerpt_more', 'wpsp_excerpt_more', 999 ); + return $excerpt; + } +} + if ( ! function_exists( 'wpsp_meta' ) ) { /** * Build our post meta. @@ -52,10 +67,21 @@ function wpsp_meta( $location, $settings ) { $post_meta_style = $settings[ 'post_meta_top_style' ]; } - if ( ( $settings[ 'include_author' ] && $location == $settings[ 'author_location' ] ) || ( $settings[ 'include_date' ] && $location == $settings[ 'date_location' ] ) || ( $settings[ 'include_terms' ] && $location == $settings[ 'terms_location' ] ) || ( $settings[ 'include_comments' ] && $location == $settings[ 'comments_location' ] ) ) { + if ( ( $settings[ 'include_author' ] && $location == $settings[ 'author_location' ] ) + || ( $settings[ 'include_date' ] && $location == $settings[ 'date_location' ] ) + || ( $settings[ 'include_terms' ] && $location == $settings[ 'terms_location' ] ) + || ( $settings[ 'include_comments' ] && $location == $settings[ 'comments_location' ] ) + || ( $settings[ 'include_edit_link'] && $location == $settings[ 'edit_link_location' ] ) + ) { echo '
'; } + // If edit link is enabled and user is admin, show it + if ( $settings[ 'include_edit_link' ] && $location == $settings[ 'edit_link_location' ] && current_user_can( 'edit_post' , get_the_ID() ) ) { + $edit_url = get_edit_post_link(); + $output[] = "Edit"; + } + // If our author is enabled, show it if ( $settings[ 'include_author' ] && $location == $settings[ 'author_location' ] ) { $output[] = apply_filters( 'wpsp_author_output', sprintf( @@ -129,7 +155,12 @@ function wpsp_meta( $location, $settings ) { if ( ! function_exists( 'wpsp_add_post_meta_after_title' ) ) { add_action( 'wpsp_after_title','wpsp_add_post_meta_after_title' ); function wpsp_add_post_meta_after_title( $settings ) { - if ( ( $settings[ 'include_author' ] && 'below-title' == $settings[ 'author_location' ] ) || ( $settings[ 'include_date' ] && 'below-title' == $settings[ 'date_location' ] ) || ( $settings[ 'include_terms' ] && 'below-title' == $settings[ 'terms_location' ] ) || ( $settings[ 'include_comments' ] && 'below-title' == $settings[ 'comments_location' ] ) ) { + if ( ( $settings[ 'include_author' ] && 'below-title' == $settings[ 'author_location' ] ) + || ( $settings[ 'include_date' ] && 'below-title' == $settings[ 'date_location' ] ) + || ( $settings[ 'include_terms' ] && 'below-title' == $settings[ 'terms_location' ] ) + || ( $settings[ 'include_comments' ] && 'below-title' == $settings[ 'comments_location' ] ) + || ( $settings[ 'include_edit_link' ] && 'below-title' == $settings[ 'edit_link_location' ] ) + ) { wpsp_meta( 'below-title', $settings ); } @@ -139,7 +170,12 @@ function wpsp_add_post_meta_after_title( $settings ) { if ( ! function_exists( 'wpsp_add_post_meta_after_content' ) ) { add_action( 'wpsp_after_content','wpsp_add_post_meta_after_content', 10 ); function wpsp_add_post_meta_after_content( $settings ) { - if ( ( $settings[ 'include_author' ] && 'below-post' == $settings[ 'author_location' ] ) || ( $settings[ 'include_date' ] && 'below-post' == $settings[ 'date_location' ] ) || ( $settings[ 'include_terms' ] && 'below-post' == $settings[ 'terms_location' ] ) || ( $settings[ 'include_comments' ] && 'below-post' == $settings[ 'comments_location' ] ) ) { + if ( ( $settings[ 'include_author' ] && 'below-post' == $settings[ 'author_location' ] ) + || ( $settings[ 'include_date' ] && 'below-post' == $settings[ 'date_location' ] ) + || ( $settings[ 'include_terms' ] && 'below-post' == $settings[ 'terms_location' ] ) + || ( $settings[ 'include_comments' ] && 'below-post' == $settings[ 'comments_location' ] ) + || ( $settings[ 'include_edit_link' ] && 'below-post' == $settings[ 'edit_link_location' ] ) + ) { wpsp_meta( 'below-post', $settings ); } } diff --git a/inc/styling.php b/inc/styling.php index 8796064..898a4ab 100644 --- a/inc/styling.php +++ b/inc/styling.php @@ -3,57 +3,41 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } - add_action( 'wpsp_before_wrapper', 'wpsp_basic_styling' ); function wpsp_basic_styling( $settings ) { // Start the magic $visual_css = array ( - '.wp-show-posts-columns#wpsp-' . $settings[ 'list_id' ] => array( 'margin-left' => ( '' !== $settings[ 'columns_gutter' ] && '12' !== $settings[ 'columns' ] ) ? '-' . $settings[ 'columns_gutter' ] : null ), - '.wp-show-posts-columns#wpsp-' . $settings[ 'list_id' ] . ' .wp-show-posts-inner' => array( 'margin' => ( '' !== $settings[ 'columns_gutter' ] && '12' !== $settings[ 'columns' ] ) ? '0 0 ' . $settings[ 'columns_gutter' ] . ' ' . $settings[ 'columns_gutter' ] : null, ), - ); - // Output the above CSS $output = ''; foreach( $visual_css as $k => $properties ) { - if ( !count( $properties ) ) { continue; } - $temporary_output = $k . ' {'; $elements_added = 0; - foreach( $properties as $p => $v ) { - if ( empty( $v ) ) { continue; } - $elements_added++; $temporary_output .= $p . ': ' . $v . '; '; - } - $temporary_output .= "}"; - if ( $elements_added > 0 ) { $output .= $temporary_output; } - } - $output = str_replace(array("\r", "\n"), '', $output); - if ( '' !== $output ) { echo ''; } -} \ No newline at end of file +} diff --git a/readme.txt b/readme.txt index 6a59955..3962577 100644 --- a/readme.txt +++ b/readme.txt @@ -46,9 +46,11 @@ Here are the features in the free version: = Content = * Content type (excerpt or full post) +* List type (ordered, unordered or none) * Excerpt length * Include title * Read more text +* In-text link to post = Meta = @@ -58,6 +60,10 @@ Here are the features in the free version: * Date location * Include terms * Terms location +* Include edit link (if logged user has permission) +* Edit link location +* Include comments link +* Comments link location = More settings = diff --git a/wp-show-posts.php b/wp-show-posts.php index a9a937f..2ebc79a 100644 --- a/wp-show-posts.php +++ b/wp-show-posts.php @@ -13,7 +13,7 @@ // No direct access, please if ( ! defined( 'ABSPATH' ) ) { - exit; + exit; } // Define the current version @@ -21,7 +21,7 @@ // Add resizer script if ( ! class_exists( 'WPSP_Resize' ) ) { - require_once plugin_dir_path( __FILE__ ) . 'inc/image-resizer.php'; + require_once plugin_dir_path( __FILE__ ) . 'inc/image-resizer.php'; } require_once trailingslashit( plugin_dir_path( __FILE__ ) ) . 'inc/defaults.php'; @@ -42,7 +42,7 @@ * @since 0.5 */ function wpsp_load_textdomain() { - load_plugin_textdomain( 'wp-show-posts' ); + load_plugin_textdomain( 'wp-show-posts' ); } add_action( 'wp_enqueue_scripts', 'wpsp_enqueue_scripts' ); @@ -52,8 +52,8 @@ function wpsp_load_textdomain() { * @since 0.1 */ function wpsp_enqueue_scripts() { - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '-min'; - wp_enqueue_style( 'wp-show-posts', plugins_url( "css/wp-show-posts{$suffix}.css", __FILE__ ), array(), WPSP_VERSION ); + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '-min'; + wp_enqueue_style( 'wp-show-posts', plugins_url( "css/wp-show-posts{$suffix}.css", __FILE__ ), array(), WPSP_VERSION ); } /* @@ -66,16 +66,16 @@ function wpsp_enqueue_scripts() { * @return mixed The value of our key. */ function wpsp_get_setting( $id, $key ) { - // Get our defaults - $defaults = wpsp_get_defaults(); + // Get our defaults + $defaults = wpsp_get_defaults(); - // Bail if our default isn't set - if ( ! isset( $defaults[ $key ] ) ) { - return false; - } + // Bail if our default isn't set + if ( ! isset( $defaults[ $key ] ) ) { + return false; + } - // If we have a default, let's return a value - return get_post_meta( $id, $key ) ? get_post_meta( $id, $key, true ) : $defaults[ $key ]; + // If we have a default, let's return a value + return get_post_meta( $id, $key ) ? get_post_meta( $id, $key, true ) : $defaults[ $key ]; } /* @@ -88,447 +88,496 @@ function wpsp_get_setting( $id, $key ) { * @param string|array $custom_settings Custom settings we can pass to our list. */ function wpsp_display( $id, $custom_settings = false ) { - // Set the global ID of our object - global $wpsp_id; - $wpsp_id = $id; - - // Build our setting variables - $settings = apply_filters( 'wpsp_settings', array( - 'list_id' => absint( $id ), - 'author' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_author' ) ), - 'columns' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_columns' ) ), - 'columns_gutter' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_columns_gutter' ) ), - 'content_type' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_content_type' ) ), - 'exclude_current' => wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_exclude_current' ) ), - 'excerpt_length' => absint( wpsp_get_setting( $id, 'wpsp_excerpt_length' ) ), - 'post_id' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_post_id' ) ), - 'exclude_post_id' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_exclude_post_id' ) ), - 'ignore_sticky_posts' => wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_ignore_sticky_posts' ) ), - 'include_title' => wp_validate_boolean( get_post_meta( $id, 'wpsp_include_title', true ) ), - 'title_element' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_title_element' ) ), - 'image' => sanitize_text_field( get_post_meta( $id, 'wpsp_image', true ), FILTER_VALIDATE_BOOLEAN ), - 'image_location' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_image_location' ) ), - 'image_alignment' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_image_alignment' ) ), - 'image_height' => absint( wpsp_get_setting( $id, 'wpsp_image_height' ) ), - 'image_width' => absint( wpsp_get_setting( $id, 'wpsp_image_width' ) ), - 'include_author' => wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_include_author' ) ), - 'author_location' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_author_location' ) ), - 'include_terms' => wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_include_terms' ) ), - 'terms_location' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_terms_location' ) ), - 'include_date' => wp_validate_boolean( get_post_meta( $id, 'wpsp_include_date', true ) ), - 'date_location' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_date_location' ) ), - 'include_comments' => wp_validate_boolean( get_post_meta( $id, 'wpsp_include_comments', true ) ), - 'comments_location' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_comments_location' ) ), - 'inner_wrapper' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_inner_wrapper' ) ), - 'inner_wrapper_class' => array_map( 'sanitize_html_class', ( explode( ' ', wpsp_get_setting( $id, 'wpsp_inner_wrapper_class' ) ) ) ), - 'inner_wrapper_style' => explode( ' ', esc_attr( wpsp_get_setting( $id, 'wpsp_inner_wrapper_style' ) ) ), - 'itemtype' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_itemtype' ) ), - 'meta_key' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_meta_key' ) ), - 'meta_value' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_meta_value' ) ), - 'offset' => absint( wpsp_get_setting( $id, 'wpsp_offset' ) ), - 'order' => sanitize_key( wpsp_get_setting( $id, 'wpsp_order' ) ), - 'orderby' => sanitize_key( wpsp_get_setting( $id, 'wpsp_orderby' ) ), - 'pagination' => wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_pagination' ) ), - 'post_type' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_post_type' ) ), - 'post_status' => wpsp_get_setting( $id, 'wpsp_post_status' ), // Validated later - 'posts_per_page' => intval( wpsp_get_setting( $id, 'wpsp_posts_per_page' ) ), - 'tax_operator' => wpsp_get_setting( $id, 'wpsp_tax_operator' ), // Validated later - 'tax_term' => wpsp_get_setting( $id, 'wpsp_tax_term' ), - 'taxonomy' => sanitize_key( wpsp_get_setting( $id, 'wpsp_taxonomy' ) ), - 'read_more_text' => wp_kses_post( wpsp_get_setting( $id, 'wpsp_read_more_text' ) ), - 'wrapper' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_wrapper' ) ), - 'wrapper_class' => array_map( 'sanitize_html_class', ( explode( ' ', wpsp_get_setting( $id, 'wpsp_wrapper_class' ) ) ) ), - 'wrapper_style' => explode( ' ', esc_attr( wpsp_get_setting( $id, 'wpsp_wrapper_style' ) ) ), - 'no_results' => wp_kses_post( wpsp_get_setting( $id, 'wpsp_no_results' ) ), - 'post_meta_bottom_style' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_post_meta_bottom_style' ) ), - 'post_meta_top_style' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_post_meta_top_style' ) ), - ) ); - - // Replace args with any custom args. - if ( ! empty( $custom_settings ) ) { - if ( is_array( $custom_settings ) ) { - $settings = array_merge( $settings, $custom_settings ); - } - - if ( ! is_array( $custom_settings ) ) { - $settings_string = parse_str( $custom_settings, $custom_settings ); - $settings = array_merge( $settings, $custom_settings ); - } - } - - // Grab initiate args for query - $args = array(); - - if ( '' !== $settings[ 'order' ] ) { - $args[ 'order' ] = $settings[ 'order' ]; - } - - if ( '' !== $settings[ 'orderby' ] ) { - $args[ 'orderby' ] = $settings[ 'orderby' ]; - } - - if ( 'rand' == $settings[ 'orderby' ] && $settings[ 'pagination' ] ) { - $args[ 'orderby' ] = 'rand(' . $id . ')'; - } - - if ( '' !== $settings[ 'post_type' ] ) { - $args[ 'post_type' ] = $settings[ 'post_type' ]; - } - - if ( '' !== $settings[ 'posts_per_page' ] ) { - $args[ 'posts_per_page' ] = $settings[ 'posts_per_page' ]; - } - - if ( $settings[ 'ignore_sticky_posts' ] ) { - $args[ 'ignore_sticky_posts' ] = $settings[ 'ignore_sticky_posts' ]; - } - - if ( '' !== $settings[ 'meta_key' ] ) { - $args[ 'meta_key' ] = $settings[ 'meta_key' ]; - } - - if ( '' !== $settings[ 'meta_value' ] ) { - $args[ 'meta_value' ] = $settings[ 'meta_value' ]; - } - - if ( $settings[ 'offset' ] > 0 ) { - $args[ 'offset' ] = $settings[ 'offset' ]; - } - - if ( '' !== $settings[ 'author' ] ) { - $args[ 'author' ] = $settings[ 'author' ]; - } - - if ( $settings[ 'pagination' ] && ! is_single() ) { - $paged_query = is_front_page() ? 'page' : 'paged'; - $args[ 'paged' ] = get_query_var( $paged_query ); - } - - // Post Status - $settings[ 'post_status' ] = explode( ', ', $settings[ 'post_status' ] ); - $validated = array(); - $available = array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash', 'any' ); - - foreach ( $settings[ 'post_status' ] as $unvalidated ) { - if ( in_array( $unvalidated, $available ) ) { - $validated[] = $unvalidated; - } - } - - if ( ! empty( $validated ) ) { - $args['post_status'] = $validated; - } - - // If taxonomy attributes, create a taxonomy query - if ( ! empty( $settings[ 'taxonomy' ] ) && ! empty( $settings[ 'tax_term' ] ) ) { - - if ( is_array( $settings[ 'tax_term' ] ) ) { - $settings[ 'tax_term' ] = implode( ', ', $settings[ 'tax_term' ] ); - } - - if ( 'current' == $settings[ 'tax_term' ] ) { - global $post; - $terms = wp_get_post_terms(get_the_ID(), $settings[ 'taxonomy' ]); - $settings[ 'tax_term' ] = array(); - foreach ($terms as $term) { - $settings[ 'tax_term' ][] = $term->slug; - } - } else { - // Term string to array - $settings[ 'tax_term' ] = explode( ', ', $settings[ 'tax_term' ] ); - } - - // Validate operator - if ( ! in_array( $settings[ 'tax_operator' ], array( 'IN', 'NOT IN', 'AND' ) ) ) { - $settings[ 'tax_operator' ] = 'IN'; - } - - $tax_args = array( - 'tax_query' => array( - array( - 'taxonomy' => $settings[ 'taxonomy' ], - 'field' => 'slug', - 'terms' => $settings[ 'tax_term' ], - 'operator' => $settings[ 'tax_operator' ] - ) - ) - ); - - $args = array_merge( $args, $tax_args ); - - } - - // If Post IDs - if ( $settings[ 'post_id' ] ) { - $posts_in = array_map( 'intval', explode( ',', $settings[ 'post_id' ] ) ); - $args['post__in'] = $posts_in; - } - - // If Exclude Post IDs - if ( $settings[ 'exclude_post_id' ] ) { - $posts_not_in = array_map( 'intval', explode( ',', $settings[ 'exclude_post_id' ] ) ); - $args['post__not_in'] = $posts_not_in; - } - - // If Exclude Current - if ( ( is_singular() && $settings[ 'exclude_current' ] ) || is_single() ) { - $args['post__not_in'] = array( get_the_ID() ); - } - - // Border - if ( defined( 'WPSP_PRO_VERSION' ) && version_compare( WPSP_PRO_VERSION, '0.6', '<' ) ) { - $border = wpsp_sanitize_hex_color( wpsp_get_setting( $settings['list_id'], 'wpsp_border' ) ); - if ( '' !== $border ) { - $settings['wrapper_class'][] = 'include-border'; - if ( ! function_exists( 'wpsp_styling' ) ) { - $border = 'border-color: ' . $border . ';'; - } - } - } - - // Padding - if ( defined( 'WPSP_PRO_VERSION' ) && version_compare( WPSP_PRO_VERSION, '0.6', '<' ) ) { - $padding = sanitize_text_field( wpsp_get_setting( $settings['list_id'], 'wpsp_padding' ) ); - if ( '' !== $padding ) { - $settings['wrapper_class'][] = 'include-padding'; - $padding = 'padding:' . $padding . ';'; - } - } - - // Columns - if ( 'col-12' !== $settings[ 'columns' ] ) { - wp_enqueue_script( 'wpsp-matchHeight', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'js/jquery.matchHeight.js', array( 'jquery' ), WPSP_VERSION, true ); - $settings[ 'wrapper_class' ][] = 'wp-show-posts-columns'; - } - - // Featured post class - $featured_post = wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_featured_post' ) ); - - $current_post = ''; - if ( 'col-12' !== $settings[ 'columns' ] && $featured_post ) { - if ( $settings[ 'columns' ] == 'col-6' ) { - $current_post = 'wpsp-col-12'; - } - - if ( $settings[ 'columns' ] == 'col-4' ) { - $current_post = 'wpsp-col-8'; - } - - if ( $settings[ 'columns' ] == 'col-3' ) { - $current_post = 'wpsp-col-6'; - } - - if ( $settings[ 'columns' ] == 'col-20' ) { - $current_post = 'wpsp-col-6'; - } - } - - // Masonry - $masonry = wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_masonry' ) ); - - if ( $masonry ) { - $settings[ 'wrapper_class' ][] = 'wp-show-posts-masonry'; - $settings[ 'inner_wrapper_class' ][] = ' wp-show-posts-masonry-' . $settings[ 'columns' ]; - $settings[ 'inner_wrapper_class' ][] = ' wp-show-posts-masonry-block'; - - wp_enqueue_script( 'wpsp-imagesloaded' ); - wp_enqueue_script( 'jquery-masonry' ); - wp_add_inline_script( 'jquery-masonry', 'jQuery(function($){var $container = $(".wp-show-posts-masonry");$container.imagesLoaded( function(){$container.fadeIn( 1000 ).masonry({itemSelector : ".wp-show-posts-masonry-block",columnWidth: ".grid-sizer"}).css("opacity","1");});});' ); - } - - // Add the default inner wrapper class - // We don't create the class element up here like below, as we need to add classes inside the loop below as well - $settings[ 'inner_wrapper_class' ][] = 'wp-show-posts-single'; - - if ( 'col-12' == $settings[ 'columns' ] ) { - $settings[ 'inner_wrapper_class' ][] = 'wpsp-clearfix'; - } - - // Add the default wrapper class - $settings[ 'wrapper_class' ][] = 'wp-show-posts'; - - // Get the wrapper class - if ( ! empty( $settings[ 'wrapper_class' ] ) ) { - $settings[ 'wrapper_class' ] = ' class="' . implode( ' ', $settings[ 'wrapper_class' ] ) . '"'; - } - - // Get the wrapper style - if ( ! empty( $settings[ 'wrapper_style' ] ) ) { - $settings[ 'wrapper_style' ] = ' style="' . implode( ' ', $settings[ 'wrapper_style' ] ) . '"'; - } - - // Get the inner wrapper class - if ( ! empty( $settings[ 'inner_wrapper_style' ] ) ) { - $settings[ 'inner_wrapper_style' ] = ' style="' . implode( ' ', $settings[ 'inner_wrapper_style' ] ) . '"'; - } - - // Get the wrapper ID - $wrapper_id = ' id="wpsp-' . $id . '"'; - - $wrapper_atts = apply_filters( 'wpsp_wrapper_atts', '' ); - - do_action( 'wpsp_before_wrapper', $settings ); - - // Start the wrapper - echo '<' . $settings[ 'wrapper' ] . $wrapper_id . $settings[ 'wrapper_class' ] . $settings[ 'wrapper_style' ] . $wrapper_atts . '>'; - - do_action( 'wpsp_inside_wrapper', $settings ); - - if ( $masonry ) { - echo '
'; - } - - // Start the query - $query = new WP_Query( apply_filters( 'wp_show_posts_shortcode_args', $args ) ); - // Start the loop - if ( $query->have_posts() ) { - while ( $query->have_posts() ) { - $query->the_post(); - - // Get page - $paged_query = is_front_page() ? 'page' : 'paged'; - $paged = ( get_query_var( $paged_query ) ) ? get_query_var( $paged_query ) : 1; - - $featured = ''; - $column_class = ''; - - // Featured post - if ( $settings[ 'columns' ] !== 'col-12' && $featured_post ) { - if ( $query->current_post == 0 && $paged == 1 ) { - $featured = ' featured-column ' . $current_post; - } else { - $featured = ' wpsp-' . $settings[ 'columns' ]; - } - } elseif ( $settings[ 'columns' ] !== 'col-12' ) { - $column_class .= ' wpsp-' . $settings[ 'columns' ]; - } - - // Merge our classes with the post classes. - remove_filter( 'post_class', 'generate_blog_post_classes' ); // Remove GPP classes. - $settings['inner_wrapper_class'] = array_merge( $settings['inner_wrapper_class'], get_post_class() ); - add_filter( 'post_class', 'generate_blog_post_classes' ); // Re-add them. - - // Start inner container - printf( '<%1$s class="%2$s" itemtype="http://schema.org/%3$s" itemscope>', - $settings[ 'inner_wrapper' ], - implode( ' ', $settings[ 'inner_wrapper_class' ] ) . $column_class . $featured, - $settings[ 'itemtype' ] - ); - - echo '
'; - - do_action( 'wpsp_before_header', $settings ); - - // The title - if ( $settings[ 'include_title' ] || ( $settings[ 'include_author' ] && 'below-title' == $settings[ 'author_location' ] ) || ( $settings[ 'include_date' ] && 'below-title' == $settings[ 'date_location' ] ) || ( $settings[ 'include_terms' ] && 'below-title' == $settings[ 'terms_location' ] ) ) : ?> -
- ', - $settings[ 'title_element' ], - esc_url( get_permalink() ) - ); - - $after_title = ''; - - if ( apply_filters( 'wpsp_disable_title_link', false, $settings ) ) { - $before_title = '<' . $settings[ 'title_element' ] . ' class="wp-show-posts-entry-title" itemprop="headline">'; - $after_title = ''; - } - - if ( $settings[ 'include_title' ] ) { - the_title( $before_title, $after_title ); - } - - do_action( 'wpsp_after_title', $settings ); - ?> -
- post_content, '' ) ); - - // The excerpt or full content - if ( 'excerpt' == $settings[ 'content_type' ] && $settings[ 'excerpt_length' ] && ! $more_tag && 'none' !== $settings[ 'content_type' ] ) : ?> -
- -
- -
- -
- '; - - if ( 'col-12' == $settings[ 'columns' ] ) { - echo '
'; - } - - // End inner container - echo ''; - } - } else { - // no posts found - echo $settings[ 'columns' ] !== 'col-12' ? '
' : ''; - echo wpautop( $settings[ 'no_results' ] ); - echo $settings[ 'columns' ] !== 'col-12' ? '
' : ''; - } - - if ( $settings[ 'columns' ] !== 'col-12' ) { - echo '
'; - } - - echo ''; - - do_action( 'wpsp_after_wrapper', $settings ); - - // Pagination - if ( $settings[ 'pagination' ] && $query->have_posts() && ! is_single() ) { - $ajax_pagination = wp_validate_boolean( wpsp_get_setting( $settings['list_id'], 'wpsp_ajax_pagination' ) ); - - if ( $ajax_pagination && function_exists( 'wpsp_ajax_pagination' ) ) { - - $max_page = $query->max_num_pages; - $nextpage = intval( $paged ) + 1; - - if ( $nextpage <= $max_page ) { - $next_page_url = next_posts( $max_page, false ); - } - - wpsp_ajax_pagination( $next_page_url, $paged, $max_page ); - wp_enqueue_script( 'wpsp-imagesloaded' ); - wp_enqueue_script( 'wpsp-ajax-pagination' ); - } else { - wpsp_pagination( $query->max_num_pages ); - } - } - - if ( defined( 'WPSP_PRO_VERSION' ) && version_compare( WPSP_PRO_VERSION, '0.6', '<' ) ) { - // Lightbox and gallery - $image_lightbox = sanitize_text_field( wpsp_get_setting( $settings['list_id'], 'wpsp_image_lightbox' ) ); - if ( $image_lightbox ) { - wp_enqueue_script( 'wpsp-featherlight' ); - wp_enqueue_style( 'wpsp-featherlight' ); - - $image_gallery = sanitize_text_field( wpsp_get_setting( $settings['list_id'], 'wpsp_image_gallery' ) ); - if ( $image_gallery ) { - wp_enqueue_script( 'wpsp-featherlight-gallery' ); - wp_enqueue_style( 'wpsp-featherlight-gallery' ); - } - } - } - - // Restore original Post Data - wp_reset_postdata(); + // Set the global ID of our object + global $wpsp_id; + $wpsp_id = $id; + + // Build our setting variables + $settings = apply_filters( 'wpsp_settings', array( + 'list_id' => absint( $id ), + 'author' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_author' ) ), + 'columns' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_columns' ) ), + 'columns_gutter' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_columns_gutter' ) ), + 'content_type' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_content_type' ) ), + 'list_type' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_list_type' ) ), + 'exclude_current' => wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_exclude_current' ) ), + 'excerpt_length' => absint( wpsp_get_setting( $id, 'wpsp_excerpt_length' ) ), + 'post_id' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_post_id' ) ), + 'exclude_post_id' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_exclude_post_id' ) ), + 'ignore_sticky_posts' => wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_ignore_sticky_posts' ) ), + 'include_title' => wp_validate_boolean( get_post_meta( $id, 'wpsp_include_title', true ) ), + 'title_element' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_title_element' ) ), + 'image' => sanitize_text_field( get_post_meta( $id, 'wpsp_image', true ), FILTER_VALIDATE_BOOLEAN ), + 'image_location' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_image_location' ) ), + 'image_alignment' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_image_alignment' ) ), + 'image_height' => absint( wpsp_get_setting( $id, 'wpsp_image_height' ) ), + 'image_width' => absint( wpsp_get_setting( $id, 'wpsp_image_width' ) ), + 'include_author' => wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_include_author' ) ), + 'author_location' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_author_location' ) ), + 'include_terms' => wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_include_terms' ) ), + 'terms_location' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_terms_location' ) ), + 'include_date' => wp_validate_boolean( get_post_meta( $id, 'wpsp_include_date', true ) ), + 'date_location' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_date_location' ) ), + 'include_edit_link' => wp_validate_boolean( get_post_meta( $id, 'wpsp_include_edit_link', true ) ), + 'edit_link_location' => sanitize_text_field( get_post_meta( $id, 'wpsp_edit_link_location', true ) ), + 'include_add_item' => wp_validate_boolean( get_post_meta( $id, 'wpsp_include_add_item', true ) ), + 'add_item_location' => sanitize_text_field( get_post_meta( $id, 'wpsp_add_item_location', true ) ), + 'include_comments' => wp_validate_boolean( get_post_meta( $id, 'wpsp_include_comments', true ) ), + 'comments_location' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_comments_location' ) ), + 'inner_wrapper' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_inner_wrapper' ) ), + 'inner_wrapper_class' => array_map( 'sanitize_html_class', ( explode( ' ', wpsp_get_setting( $id, 'wpsp_inner_wrapper_class' ) ) ) ), + 'inner_wrapper_style' => explode( ' ', esc_attr( wpsp_get_setting( $id, 'wpsp_inner_wrapper_style' ) ) ), + 'itemtype' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_itemtype' ) ), + 'meta_key' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_meta_key' ) ), + 'meta_value' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_meta_value' ) ), + 'offset' => absint( wpsp_get_setting( $id, 'wpsp_offset' ) ), + 'order' => sanitize_key( wpsp_get_setting( $id, 'wpsp_order' ) ), + 'orderby' => sanitize_key( wpsp_get_setting( $id, 'wpsp_orderby' ) ), + 'pagination' => wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_pagination' ) ), + 'post_type' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_post_type' ) ), + 'post_status' => wpsp_get_setting( $id, 'wpsp_post_status' ), // Validated later + 'posts_per_page' => intval( wpsp_get_setting( $id, 'wpsp_posts_per_page' ) ), + 'tax_operator' => wpsp_get_setting( $id, 'wpsp_tax_operator' ), // Validated later + 'tax_term' => wpsp_get_setting( $id, 'wpsp_tax_term' ), + 'taxonomy' => sanitize_key( wpsp_get_setting( $id, 'wpsp_taxonomy' ) ), + 'read_more_text' => wp_kses_post( wpsp_get_setting( $id, 'wpsp_read_more_text' ) ), + 'in_text_link' => wp_kses_post( wpsp_get_setting( $id, 'wpsp_in_text_link' ) ), + 'wrapper' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_wrapper' ) ), + 'wrapper_class' => array_map( 'sanitize_html_class', ( explode( ' ', wpsp_get_setting( $id, 'wpsp_wrapper_class' ) ) ) ), + 'wrapper_style' => explode( ' ', esc_attr( wpsp_get_setting( $id, 'wpsp_wrapper_style' ) ) ), + 'no_results' => wp_kses_post( wpsp_get_setting( $id, 'wpsp_no_results' ) ), + 'post_meta_bottom_style' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_post_meta_bottom_style' ) ), + 'post_meta_top_style' => sanitize_text_field( wpsp_get_setting( $id, 'wpsp_post_meta_top_style' ) ), + ) ); + + // Replace args with any custom args. + if ( ! empty( $custom_settings ) ) { + if ( is_array( $custom_settings ) ) { + $settings = array_merge( $settings, $custom_settings ); + } + + if ( ! is_array( $custom_settings ) ) { + $settings_string = parse_str( $custom_settings, $custom_settings ); + $settings = array_merge( $settings, $custom_settings ); + } + } + + // Grab initiate args for query + $args = array(); + + if ( '' !== $settings[ 'order' ] ) { + $args[ 'order' ] = $settings[ 'order' ]; + } + + if ( '' !== $settings[ 'orderby' ] ) { + $args[ 'orderby' ] = $settings[ 'orderby' ]; + } + + if ( 'rand' == $settings[ 'orderby' ] && $settings[ 'pagination' ] ) { + $args[ 'orderby' ] = 'rand(' . $id . ')'; + } + + if ( '' !== $settings[ 'post_type' ] ) { + $args[ 'post_type' ] = $settings[ 'post_type' ]; + } + + if ( '' !== $settings[ 'posts_per_page' ] ) { + $args[ 'posts_per_page' ] = $settings[ 'posts_per_page' ]; + } + + if ( $settings[ 'ignore_sticky_posts' ] ) { + $args[ 'ignore_sticky_posts' ] = $settings[ 'ignore_sticky_posts' ]; + } + + if ( '' !== $settings[ 'meta_key' ] ) { + $args[ 'meta_key' ] = $settings[ 'meta_key' ]; + } + + if ( '' !== $settings[ 'meta_value' ] ) { + $args[ 'meta_value' ] = $settings[ 'meta_value' ]; + } + + if ( $settings[ 'offset' ] > 0 ) { + $args[ 'offset' ] = $settings[ 'offset' ]; + } + + if ( '' !== $settings[ 'author' ] ) { + $args[ 'author' ] = $settings[ 'author' ]; + } + + if ( $settings[ 'pagination' ] && ! is_single() ) { + $paged_query = is_front_page() ? 'page' : 'paged'; + $args[ 'paged' ] = get_query_var( $paged_query ); + } + + // Post Status + $settings[ 'post_status' ] = explode( ', ', $settings[ 'post_status' ] ); + $validated = array(); + $available = array( 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash', 'any' ); + + foreach ( $settings[ 'post_status' ] as $unvalidated ) { + if ( in_array( $unvalidated, $available ) ) { + $validated[] = $unvalidated; + } + } + + if ( ! empty( $validated ) ) { + $args['post_status'] = $validated; + } + + // If taxonomy attributes, create a taxonomy query + if ( ! empty( $settings[ 'taxonomy' ] ) && ! empty( $settings[ 'tax_term' ] ) ) { + + if ( is_array( $settings[ 'tax_term' ] ) ) { + $settings[ 'tax_term' ] = implode( ', ', $settings[ 'tax_term' ] ); + } + + if ( 'current' == $settings[ 'tax_term' ] ) { + global $post; + $terms = wp_get_post_terms(get_the_ID(), $settings[ 'taxonomy' ]); + $settings[ 'tax_term' ] = array(); + foreach ($terms as $term) { + $settings[ 'tax_term' ][] = $term->slug; + } + } else { + // Term string to array + $settings[ 'tax_term' ] = explode( ', ', $settings[ 'tax_term' ] ); + } + + // Validate operator + if ( ! in_array( $settings[ 'tax_operator' ], array( 'IN', 'NOT IN', 'AND' ) ) ) { + $settings[ 'tax_operator' ] = 'IN'; + } + + $tax_args = array( + 'tax_query' => array( + array( + 'taxonomy' => $settings[ 'taxonomy' ], + 'field' => 'slug', + 'terms' => $settings[ 'tax_term' ], + 'operator' => $settings[ 'tax_operator' ] + ) + ) + ); + + $args = array_merge( $args, $tax_args ); + + } + + // If Post IDs + if ( $settings[ 'post_id' ] ) { + $posts_in = array_map( 'intval', explode( ',', $settings[ 'post_id' ] ) ); + $args['post__in'] = $posts_in; + } + + // If Exclude Post IDs + if ( $settings[ 'exclude_post_id' ] ) { + $posts_not_in = array_map( 'intval', explode( ',', $settings[ 'exclude_post_id' ] ) ); + $args['post__not_in'] = $posts_not_in; + } + + // If Exclude Current + if ( ( is_singular() && $settings[ 'exclude_current' ] ) || is_single() ) { + $args['post__not_in'] = array( get_the_ID() ); + } + + // Border + if ( defined( 'WPSP_PRO_VERSION' ) && version_compare( WPSP_PRO_VERSION, '0.6', '<' ) ) { + $border = wpsp_sanitize_hex_color( wpsp_get_setting( $settings['list_id'], 'wpsp_border' ) ); + if ( '' !== $border ) { + $settings['wrapper_class'][] = 'include-border'; + if ( ! function_exists( 'wpsp_styling' ) ) { + $border = 'border-color: ' . $border . ';'; + } + } + } + + // Padding + if ( defined( 'WPSP_PRO_VERSION' ) && version_compare( WPSP_PRO_VERSION, '0.6', '<' ) ) { + $padding = sanitize_text_field( wpsp_get_setting( $settings['list_id'], 'wpsp_padding' ) ); + if ( '' !== $padding ) { + $settings['wrapper_class'][] = 'include-padding'; + $padding = 'padding:' . $padding . ';'; + } + } + + // Columns + if ( 'col-12' !== $settings[ 'columns' ] ) { + wp_enqueue_script( 'wpsp-matchHeight', trailingslashit( plugin_dir_url( __FILE__ ) ) . 'js/jquery.matchHeight.js', array( 'jquery' ), WPSP_VERSION, true ); + $settings[ 'wrapper_class' ][] = 'wp-show-posts-columns'; + } + + // Featured post class + $featured_post = wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_featured_post' ) ); + + $current_post = ''; + if ( 'col-12' !== $settings[ 'columns' ] && $featured_post ) { + if ( $settings[ 'columns' ] == 'col-6' ) { + $current_post = 'wpsp-col-12'; + } + + if ( $settings[ 'columns' ] == 'col-4' ) { + $current_post = 'wpsp-col-8'; + } + + if ( $settings[ 'columns' ] == 'col-3' ) { + $current_post = 'wpsp-col-6'; + } + + if ( $settings[ 'columns' ] == 'col-20' ) { + $current_post = 'wpsp-col-6'; + } + } + + // Masonry + $masonry = wp_validate_boolean( wpsp_get_setting( $id, 'wpsp_masonry' ) ); + + if ( $masonry ) { + $settings[ 'wrapper_class' ][] = 'wp-show-posts-masonry'; + $settings[ 'inner_wrapper_class' ][] = ' wp-show-posts-masonry-' . $settings[ 'columns' ]; + $settings[ 'inner_wrapper_class' ][] = ' wp-show-posts-masonry-block'; + + wp_enqueue_script( 'wpsp-imagesloaded' ); + wp_enqueue_script( 'jquery-masonry' ); + wp_add_inline_script( 'jquery-masonry', 'jQuery(function($){var $container = $(".wp-show-posts-masonry");$container.imagesLoaded( function(){$container.fadeIn( 1000 ).masonry({itemSelector : ".wp-show-posts-masonry-block",columnWidth: ".grid-sizer"}).css("opacity","1");});});' ); + } + + // Add the default inner wrapper class + // We don't create the class element up here like below, as we need to add classes inside the loop below as well + $settings[ 'inner_wrapper_class' ][] = 'wp-show-posts-single'; + + if ( 'col-12' == $settings[ 'columns' ] ) { + $settings[ 'inner_wrapper_class' ][] = 'wpsp-clearfix'; + } + + // Add the default wrapper class + $settings[ 'wrapper_class' ][] = 'wp-show-posts'; + + // Get the wrapper class + if ( ! empty( $settings[ 'wrapper_class' ] ) ) { + $settings[ 'wrapper_class' ] = ' class="' . implode( ' ', $settings[ 'wrapper_class' ] ) . '"'; + } + + // Get the wrapper style + if ( ! empty( $settings[ 'wrapper_style' ] ) ) { + $settings[ 'wrapper_style' ] = ' style="' . implode( ' ', $settings[ 'wrapper_style' ] ) . '"'; + } + + // Get the inner wrapper class + if ( ! empty( $settings[ 'inner_wrapper_style' ] ) ) { + $settings[ 'inner_wrapper_style' ] = ' style="' . implode( ' ', $settings[ 'inner_wrapper_style' ] ) . '"'; + } + + // Get the wrapper ID + $wrapper_id = ' id="wpsp-' . $id . '"'; + + $wrapper_atts = apply_filters( 'wpsp_wrapper_atts', '' ); + + do_action( 'wpsp_before_wrapper', $settings ); + + // Start the wrapper + echo '<' . $settings[ 'wrapper' ] . $wrapper_id . $settings[ 'wrapper_class' ] . $settings[ 'wrapper_style' ] . $wrapper_atts . '>'; + + do_action( 'wpsp_inside_wrapper', $settings ); + + if ( $masonry ) { + echo '
'; + } + + $add_capability = 'edit_' . $settings[ 'post_type' ] . 's'; + + if ($settings[ 'include_add_item' ] && current_user_can($add_capability)) { + $add_item_text = get_post_type_object( $settings[ 'post_type' ] )->labels->add_new_item; + $add_item_link = '/wp-admin/post-new.php?post_type=' . $settings[ 'post_type' ]; + $text_align = 'text-align:' . $settings['add_item_location'] . ';'; + echo "
"; + echo "$add_item_text"; // Style it as you want + echo '
'; + } + + // Start the query + $query = new WP_Query( apply_filters( 'wp_show_posts_shortcode_args', $args ) ); + + if ( $settings['list_type'] == 'ordered' ): + echo "
    "; + elseif ( $settings['list_type'] == 'unordered' ): + echo "
      "; + endif; + + // Start the loop + if ( $query->have_posts() ) { + while ( $query->have_posts() ) { + echo $settings['list_type'] != 'none' ? "
    • " : ""; + + $query->the_post(); + + // Get page + $paged_query = is_front_page() ? 'page' : 'paged'; + $paged = ( get_query_var( $paged_query ) ) ? get_query_var( $paged_query ) : 1; + + $featured = ''; + $column_class = ''; + + // Featured post + if ( $settings[ 'columns' ] !== 'col-12' && $featured_post ) { + if ( $query->current_post == 0 && $paged == 1 ) { + $featured = ' featured-column ' . $current_post; + } else { + $featured = ' wpsp-' . $settings[ 'columns' ]; + } + } elseif ( $settings[ 'columns' ] !== 'col-12' ) { + $column_class .= ' wpsp-' . $settings[ 'columns' ]; + } + + // Merge our classes with the post classes. + remove_filter( 'post_class', 'generate_blog_post_classes' ); // Remove GPP classes. + $settings['inner_wrapper_class'] = array_merge( $settings['inner_wrapper_class'], get_post_class() ); + add_filter( 'post_class', 'generate_blog_post_classes' ); // Re-add them. + + // Start inner container + printf( '<%1$s class="%2$s" itemtype="http://schema.org/%3$s" itemscope>', + $settings[ 'inner_wrapper' ], + implode( ' ', $settings[ 'inner_wrapper_class' ] ) . $column_class . $featured, + $settings[ 'itemtype' ] + ); + + echo '
      '; + + do_action( 'wpsp_before_header', $settings ); + + // The title + if ( $settings[ 'include_title' ] || ( $settings[ 'include_author' ] && 'below-title' == $settings[ 'author_location' ] ) || ( $settings[ 'include_date' ] && 'below-title' == $settings[ 'date_location' ] ) || ( $settings[ 'include_terms' ] && 'below-title' == $settings[ 'terms_location' ] ) ) : ?> +
      + ', + $settings[ 'title_element' ], + esc_url( get_permalink() ) + ); + + $after_title = ''; + + if ( apply_filters( 'wpsp_disable_title_link', false, $settings ) ) { + $before_title = '<' . $settings[ 'title_element' ] . ' class="wp-show-posts-entry-title" itemprop="headline">'; + $after_title = ''; + } + + if ( $settings[ 'include_title' ] ) { + the_title( $before_title, $after_title ); + } + + do_action( 'wpsp_after_title', $settings ); + ?> +
      + post_content, '' ) ); + + // Compose text output + if (!empty($settings[ 'in_text_link' ])) { + $permalink = get_permalink(); + if ('excerpt' == $settings['content_type']) { + $output = wpsp_get_the_excerpt() . " " . $settings['in_text_link'] . ""; + } elseif ('full' == $settings['content_type']) { + $output = apply_filters( 'the_content', get_the_content() ) . " " . $settings['in_text_link'] . ""; + } + } else { + if ('excerpt' == $settings['content_type']) { + $output = wpsp_get_the_excerpt(); + } elseif ('full' == $settings['content_type']) { + $output = apply_filters( 'the_content', get_the_content() ); + } + } + + // The excerpt or full content + if ( 'excerpt' == $settings[ 'content_type' ] && $settings[ 'excerpt_length' ] && ! $more_tag && 'none' !== $settings[ 'content_type' ] ) : ?> +
      + +
      + +
      + +
      + '; + + if ( 'col-12' == $settings[ 'columns' ] ) { + echo '
      '; + } + + // End inner container + echo ''; + echo $settings['list_type'] != 'none' ? "
    • " : ""; + } + } else { + // no posts found + echo $settings[ 'columns' ] !== 'col-12' ? '
      ' : ''; + echo wpautop( $settings[ 'no_results' ] ); + echo $settings[ 'columns' ] !== 'col-12' ? '
      ' : ''; + } + + if ( $settings['list_type'] == 'ordered' ): + echo "
"; + elseif ( $settings['list_type'] == 'unordered' ): + echo ""; + endif; + + if ( $settings[ 'columns' ] !== 'col-12' ) { + echo '
'; + } + + echo ''; + + do_action( 'wpsp_after_wrapper', $settings ); + + // Pagination + if ( $settings[ 'pagination' ] && $query->have_posts() && ! is_single() ) { + $ajax_pagination = wp_validate_boolean( wpsp_get_setting( $settings['list_id'], 'wpsp_ajax_pagination' ) ); + + if ( $ajax_pagination && function_exists( 'wpsp_ajax_pagination' ) ) { + + $max_page = $query->max_num_pages; + $nextpage = intval( $paged ) + 1; + + if ( $nextpage <= $max_page ) { + $next_page_url = next_posts( $max_page, false ); + } + + wpsp_ajax_pagination( $next_page_url, $paged, $max_page ); + wp_enqueue_script( 'wpsp-imagesloaded' ); + wp_enqueue_script( 'wpsp-ajax-pagination' ); + } else { + wpsp_pagination( $query->max_num_pages ); + } + } + + if ( defined( 'WPSP_PRO_VERSION' ) && version_compare( WPSP_PRO_VERSION, '0.6', '<' ) ) { + // Lightbox and gallery + $image_lightbox = sanitize_text_field( wpsp_get_setting( $settings['list_id'], 'wpsp_image_lightbox' ) ); + if ( $image_lightbox ) { + wp_enqueue_script( 'wpsp-featherlight' ); + wp_enqueue_style( 'wpsp-featherlight' ); + + $image_gallery = sanitize_text_field( wpsp_get_setting( $settings['list_id'], 'wpsp_image_gallery' ) ); + if ( $image_gallery ) { + wp_enqueue_script( 'wpsp-featherlight-gallery' ); + wp_enqueue_style( 'wpsp-featherlight-gallery' ); + } + } + } + + // Restore original Post Data + wp_reset_postdata(); } add_shortcode( 'wp_show_posts', 'wpsp_shortcode_function' ); @@ -540,25 +589,25 @@ function wpsp_display( $id, $custom_settings = false ) { * @param array $atts The shortcode attributes. */ function wpsp_shortcode_function( $atts ) { - $atts = shortcode_atts( - array( - 'id' => '', - 'name' => '', - 'settings' => '' - ), $atts, 'wp_show_posts' - ); - - ob_start(); - - // Get the ID from the list name if it's provided. - if ( ! empty( $atts['name'] ) ) { - $list = get_page_by_title( $atts['name'], 'OBJECT', 'wp_show_posts' ); - $atts['id'] = $list->ID; - } - - if ( $atts['id'] ) { - wpsp_display( $atts['id'], $atts['settings'] ); - } - - return ob_get_clean(); + $atts = shortcode_atts( + array( + 'id' => '', + 'name' => '', + 'settings' => '' + ), $atts, 'wp_show_posts' + ); + + ob_start(); + + // Get the ID from the list name if it's provided. + if ( ! empty( $atts['name'] ) ) { + $list = get_page_by_title( $atts['name'], 'OBJECT', 'wp_show_posts' ); + $atts['id'] = $list->ID; + } + + if ( $atts['id'] ) { + wpsp_display( $atts['id'], $atts['settings'] ); + } + + return ob_get_clean(); }