PluginProbe
WP Ultimate Post Grid / 2.0
WP Ultimate Post Grid v2.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 +26 -127 2.8.22.0 View file →
@@ -16,144 +16,52 @@
16 16 $slug = strtolower( trim( $options['id'] ) );
17 17
18 18 if( $slug ) {
19 19 unset( $options['id'] );
20 - $no_output_mode = isset( $options['wpupg_no_output'] ) && $options['wpupg_no_output'] ? true : false;
21 - unset( $options['wpupg_no_output'] );
22 -
23 20 $post = get_page_by_path( $slug, OBJECT, WPUPG_POST_TYPE );
24 21
25 22 if( !is_null( $post ) ) {
26 - $grid = WPUPG_Grid_Manager::get( $post );
23 + $grid = new WPUPG_Grid( $post );
27 24
28 25 // Check if we need to filter the grid dynamically
29 26 $dynamic_rules = array();
30 27 if( count( $options ) > 0 && WPUltimatePostGrid::is_premium_active() ) {
31 28
32 - // Term Grid.
33 - if ( $grid->type() == 'terms' ) {
34 - if( isset( $options['term_id'] ) ) {
35 - $term_ids = str_replace( ',', ';', $options['term_id'] );
36 - $term_ids = str_replace( 'current_term', get_queried_object_id(), $term_ids );
29 + if( isset( $options['post_id'] ) ) {
30 + $dynamic_rules[] = array(
31 + 'post_type' => 'wpupg_general',
32 + 'taxonomy' => 'id',
33 + 'values' => explode( ';', str_replace( ',', ';', $options['post_id'] ) ),
34 + 'type' => 'restrict',
35 + );
36 + unset( $options['post_id'] );
37 + }
37 38
38 - $dynamic_rules = array(
39 - 'values' => explode( ';', $term_ids ),
40 - 'type' => 'restrict',
41 - );
42 - unset( $options['term_id'] );
43 - }
39 + if( isset( $options['exclude_post_id'] ) ) {
40 + $dynamic_rules[] = array(
41 + 'post_type' => 'wpupg_general',
42 + 'taxonomy' => 'id',
43 + 'values' => explode( ';', str_replace( ',', ';', $options['exclude_post_id'] ) ),
44 + 'type' => 'exclude',
45 + );
46 + unset( $options['exclude_post_id'] );
47 + }
44 48
45 - if( isset( $options['exclude_term_id'] ) ) {
46 - $term_ids = str_replace( ',', ';', $options['exclude_term_id'] );
47 - $term_ids = str_replace( 'current_term', get_queried_object_id(), $term_ids );
48 -
49 - $dynamic_rules = array(
50 - 'values' => explode( ';', $term_ids ),
51 - 'type' => 'exclude',
52 - );
53 - unset( $options['exclude_term_id'] );
54 - }
55 - } else {
56 - // Post Grid.
57 - if( isset( $options['post_id'] ) ) {
58 - $post_ids = str_replace( ',', ';', $options['post_id'] );
59 - $post_ids = str_replace( 'current_post', get_the_ID(), $post_ids );
60 -
49 + foreach( $options as $taxonomy => $terms ) {
50 + if( taxonomy_exists( $taxonomy ) ) {
61 51 $dynamic_rules[] = array(
62 - 'post_type' => 'wpupg_general',
63 - 'taxonomy' => 'id',
64 - 'values' => explode( ';', $post_ids ),
52 + 'post_type' => 'wpupg_dynamic',
53 + 'taxonomy' => $taxonomy,
54 + 'values' => explode( ';', str_replace( ',', ';', $terms ) ),
65 55 'type' => 'restrict',
66 56 );
67 - unset( $options['post_id'] );
68 57 }
69 -
70 - if( isset( $options['exclude_post_id'] ) ) {
71 - $post_ids = str_replace( ',', ';', $options['exclude_post_id'] );
72 - $post_ids = str_replace( 'current_post', get_the_ID(), $post_ids );
73 -
74 - $dynamic_rules[] = array(
75 - 'post_type' => 'wpupg_general',
76 - 'taxonomy' => 'id',
77 - 'values' => explode( ';', $post_ids ),
78 - 'type' => 'exclude',
79 - );
80 - unset( $options['exclude_post_id'] );
81 - }
82 -
83 - if( isset( $options['author'] ) ) {
84 - $author_ids = str_replace( ',', ';', $options['author'] );
85 - $author_ids = str_replace( 'current_user', get_current_user_id(), $author_ids );
86 -
87 - $dynamic_rules[] = array(
88 - 'post_type' => 'wpupg_general',
89 - 'taxonomy' => 'author',
90 - 'values' => explode( ';', $author_ids ),
91 - 'type' => 'restrict',
92 - );
93 - unset( $options['author'] );
94 - }
95 -
96 - if( isset( $options['exclude_author'] ) ) {
97 - $author_ids = str_replace( ',', ';', $options['exclude_author'] );
98 - $author_ids = str_replace( 'current_user', get_current_user_id(), $author_ids );
99 -
100 - $dynamic_rules[] = array(
101 - 'post_type' => 'wpupg_general',
102 - 'taxonomy' => 'author',
103 - 'values' => explode( ';', $author_ids ),
104 - 'type' => 'exclude',
105 - );
106 - unset( $options['exclude_author'] );
107 - }
108 -
109 - if( isset( $options['date'] ) ) {
110 - $date_condition = str_replace( '_today', '', $options['date'] );
111 - $date_condition = in_array( $date_condition, array( 'before', 'after' ) ) ? $date_condition : 'is';
112 -
113 - $dynamic_rules[] = array(
114 - 'post_type' => 'wpupg_general',
115 - 'taxonomy' => 'date',
116 - 'values' => array( $date_condition, date( 'Y-m-d' ) ),
117 - 'type' => 'restrict',
118 - );
119 - unset( $options['date'] );
120 - }
121 -
122 - foreach( $options as $taxonomy => $terms ) {
123 - if( taxonomy_exists( $taxonomy ) ) {
124 - $dynamic_rules[] = array(
125 - 'post_type' => 'wpupg_dynamic',
126 - 'taxonomy' => $taxonomy,
127 - 'values' => explode( ';', str_replace( ',', ';', $terms ) ),
128 - 'type' => 'restrict',
129 - );
130 - } elseif( 'exclude_' === substr( $taxonomy, 0, 8 ) ) {
131 - $dynamic_rules[] = array(
132 - 'post_type' => 'wpupg_dynamic',
133 - 'taxonomy' => substr( $taxonomy, 8 ),
134 - 'values' => explode( ';', str_replace( ',', ';', $terms ) ),
135 - 'type' => 'exclude',
136 - );
137 - }
138 - }
139 58 }
140 59 }
141 - if( count( $dynamic_rules ) > 0 || 'rand' === $grid->order_by() ) {
60 + if( count( $dynamic_rules ) > 0 ) {
142 61 $grid->set_dynamic_rules( $dynamic_rules );
143 - } else if ( WPUltimatePostGrid::option( 'cache_reset_front_end', '1' ) == '1' ) {
144 - // Make sure latest version of grid is shown.
145 - $grid_ids = get_option( 'wpupg_regenerate_grids_check', false );
146 -
147 - if( $grid_ids && in_array( $grid->ID(), $grid_ids ) ) {
148 - WPUltimatePostGrid::get()->helper( 'grid_cache' )->generate( $grid->ID() );
149 - }
150 62 }
151 63
152 - if ( $no_output_mode ) {
153 - return '';
154 - }
155 -
156 64 $link_type = $grid->link_type();
157 65 $link_target = $grid->link_target();
158 66 $layout_mode = $grid->layout_mode();
159 67 $centered = $grid->centered() ? 'true' : 'false';
@@ -163,13 +71,8 @@
163 71 $posts .= '</div>';
164 72
165 73 $output = apply_filters( 'wpupg_posts_shortcode', $posts, $grid );
166 74
167 - // Message when no items match filter
168 - if( $grid->empty_message() ) {
169 - $output .= '<div id="wpupg-grid-' . esc_attr( $slug ) . '-empty" class="wpupg-grid-empty">' . $grid->empty_message() . '</div>';
170 - }
171 -
172 75 $pagination = '';
173 76 if( $grid->pagination_type() == 'pages' ) {
174 77 $pagination_type = $grid->pagination_type();
175 78 $pagination_style = $grid->pagination_style();
@@ -198,13 +101,9 @@
198 101 }
199 102
200 103 $output .= apply_filters( 'wpupg_pagination_shortcode', $pagination, $grid );
201 104
202 - wp_enqueue_script( 'wpupg_public' );
203 - if( WPUltimatePostGrid::is_premium_active() ) {
204 - wp_enqueue_script( 'wpupg_public_premium' );
205 - }
206 - wp_localize_script( 'wpupg_public', 'wpupg_grid_' . $grid->ID(), array(
105 + wp_localize_script( 'wpupg_grid', 'wpupg_grid_' . $grid->ID(), array(
207 106 'posts' => $grid->posts(),
208 107 ));
209 108 }
210 109 }