PluginProbe
WP Ultimate Post Grid / 2.4.0
WP Ultimate Post Grid v2.4.0
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
← All changes | helpers/shortcodes/grid_shortcode.php +57 -5 1.52.4.0 View file →
@@ -12,30 +12,78 @@
12 12 public function shortcode( $options )
13 13 {
14 14 $output = '';
15 15
16 - $options = shortcode_atts( array(
17 - 'id' => false
18 - ), $options );
19 -
20 16 $slug = strtolower( trim( $options['id'] ) );
21 17
22 18 if( $slug ) {
19 + unset( $options['id'] );
23 20 $post = get_page_by_path( $slug, OBJECT, WPUPG_POST_TYPE );
24 21
25 22 if( !is_null( $post ) ) {
26 23 $grid = new WPUPG_Grid( $post );
27 24
25 + // Check if we need to filter the grid dynamically
26 + $dynamic_rules = array();
27 + if( count( $options ) > 0 && WPUltimatePostGrid::is_premium_active() ) {
28 +
29 + if( isset( $options['post_id'] ) ) {
30 + $post_ids = str_replace( ',', ';', $options['post_id'] );
31 + $post_ids = str_replace( 'current_post', get_the_ID(), $post_ids );
32 +
33 + $dynamic_rules[] = array(
34 + 'post_type' => 'wpupg_general',
35 + 'taxonomy' => 'id',
36 + 'values' => explode( ';', $post_ids ),
37 + 'type' => 'restrict',
38 + );
39 + unset( $options['post_id'] );
40 + }
41 +
42 + if( isset( $options['exclude_post_id'] ) ) {
43 + $post_ids = str_replace( ',', ';', $options['exclude_post_id'] );
44 + $post_ids = str_replace( 'current_post', get_the_ID(), $post_ids );
45 +
46 + $dynamic_rules[] = array(
47 + 'post_type' => 'wpupg_general',
48 + 'taxonomy' => 'id',
49 + 'values' => explode( ';', $post_ids ),
50 + 'type' => 'exclude',
51 + );
52 + unset( $options['exclude_post_id'] );
53 + }
54 +
55 + foreach( $options as $taxonomy => $terms ) {
56 + if( taxonomy_exists( $taxonomy ) ) {
57 + $dynamic_rules[] = array(
58 + 'post_type' => 'wpupg_dynamic',
59 + 'taxonomy' => $taxonomy,
60 + 'values' => explode( ';', str_replace( ',', ';', $terms ) ),
61 + 'type' => 'restrict',
62 + );
63 + }
64 + }
65 + }
66 + if( count( $dynamic_rules ) > 0 ) {
67 + $grid->set_dynamic_rules( $dynamic_rules );
68 + }
69 +
28 70 $link_type = $grid->link_type();
71 + $link_target = $grid->link_target();
29 72 $layout_mode = $grid->layout_mode();
30 73 $centered = $grid->centered() ? 'true' : 'false';
31 74
32 - $posts = '<div id="wpupg-grid-' . esc_attr( $slug ) . '" class="wpupg-grid" data-grid="' . esc_attr( $slug ) . '" data-link-type="' . $link_type . '" data-layout-mode="' . $layout_mode . '" data-centered="' . $centered . '">';
75 + $posts = '<div id="wpupg-grid-' . esc_attr( $slug ) . '" class="wpupg-grid" data-grid="' . esc_attr( $slug ) . '" data-grid-id="' . $grid->ID() . '" data-link-type="' . $link_type . '" data-link-target="' . $link_target . '" data-layout-mode="' . $layout_mode . '" data-centered="' . $centered . '">';
33 76 $posts .= $grid->draw_posts();
34 77 $posts .= '</div>';
35 78
36 79 $output = apply_filters( 'wpupg_posts_shortcode', $posts, $grid );
37 80
81 + // Message when no items match filter
82 + if( $grid->empty_message() ) {
83 + $output .= '<div id="wpupg-grid-' . esc_attr( $slug ) . '-empty" class="wpupg-grid-empty">' . $grid->empty_message() . '</div>';
84 + }
85 +
38 86 $pagination = '';
39 87 if( $grid->pagination_type() == 'pages' ) {
40 88 $pagination_type = $grid->pagination_type();
41 89 $pagination_style = $grid->pagination_style();
@@ -63,8 +111,12 @@
63 111 $pagination .= '</div>';
64 112 }
65 113
66 114 $output .= apply_filters( 'wpupg_pagination_shortcode', $pagination, $grid );
115 +
116 + wp_localize_script( 'wpupg_grid', 'wpupg_grid_' . $grid->ID(), array(
117 + 'posts' => $grid->posts(),
118 + ));
67 119 }
68 120 }
69 121
70 122 return $output;