PluginProbe
Powerkit – Supercharge your WordPress Site / 2.4.4
Powerkit – Supercharge your WordPress Site v2.4.4
3.1.1 3.1.0 3.0.9 3.0.8 trunk 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 All 87 releases
powerkit / modules / inline-posts / public / class-powerkit-inline-posts-shortcode.php

class-powerkit-inline-posts-shortcode.php in Powerkit – Supercharge your WordPress Site 2.4.4, at modules/inline-posts/public/class-powerkit-inline-posts-shortcode.php

246 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Shortcode
4 *
5 * @link https://codesupply.co
6 * @since 1.0.0
7 *
8 * @package Powerkit
9 * @subpackage Powerkit/shortcodes
10 */
11
12 /**
13 * Template handler
14 *
15 * @param string $name Specific template.
16 * @param array $posts Array of posts.
17 * @param array $settings Array of settings.
18 */
19 function powerkit_inline_posts_template_handler( $name, $posts, $settings ) {
20 $templates = apply_filters( 'powerkit_inline_posts_templates', array() );
21
22 if ( isset( $templates[ $name ] ) && function_exists( $templates[ $name ]['func'] ) ) {
23 call_user_func( $templates[ $name ]['func'], $posts, $settings );
24 } else {
25 call_user_func( 'powerkit_inline_posts_default_template', $posts, $settings );
26 }
27 }
28
29 /**
30 * Shortcode
31 *
32 * @param array $atts User defined attributes in shortcode tag.
33 * @param string $content Shorcode tag content.
34 * @return string Shortcode result HTML.
35 */
36 function powerkit_inline_posts_shortcode( $atts, $content = '' ) {
37
38 if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
39 return;
40 }
41
42 global $post;
43
44 ob_start();
45
46 global $powerkit_inline_posts;
47
48 // Attributes.
49 $atts = powerkit_shortcode_atts( shortcode_atts( array(
50 'title' => '',
51 'count' => 1,
52 'offset' => 0,
53 'ids' => null,
54 'category' => null,
55 'tag' => null,
56 'time_frame' => null,
57 'orderby' => 'date',
58 'order' => 'DESC',
59 'template' => 'list',
60 'image_size' => 'pk-thumbnail',
61 'exclude_posts' => $powerkit_inline_posts,
62 ), $atts ) );
63
64 $posts = powerkit_get_inline_posts( $atts );
65
66 $columns = 1;
67 $template = $atts['template'];
68
69 // Check grid template.
70 switch ( $atts['template'] ) {
71 case 'grid-2':
72 $template = 'grid';
73 $columns = 2;
74 break;
75 case 'grid-3':
76 $template = 'grid';
77 $columns = 3;
78 break;
79 case 'grid-4':
80 $template = 'grid';
81 $columns = 4;
82 break;
83 }
84
85 if ( $posts ) {
86 ?>
87 <div class="pk-inline-posts">
88 <?php
89 $tag = apply_filters( 'powerkit_section_title_tag', 'h5' );
90
91 if ( $atts['title'] ) {
92 ?>
93 <<?php echo esc_html( $tag ); ?> class="pk-inline-posts-title pk-title pk-font-block">
94 <?php echo esc_html( $atts['title'] ); ?>
95 </<?php echo esc_html( $tag ); ?>>
96 <?php } ?>
97
98 <div class="pk-inline-posts-container pk-inline-posts-template-<?php echo esc_attr( $template ); ?>"
99 data-columns="<?php echo esc_attr( $columns ); ?>">
100 <?php
101 foreach ( $posts as $post ) {
102
103 setup_postdata( $post );
104 // Exclude current post ID.
105 $powerkit_inline_posts[] = $post->ID;
106
107 // Output template.
108 powerkit_inline_posts_template_handler( $atts['template'], $posts, $atts );
109 }
110 ?>
111 </div>
112 </div>
113 <?php
114 }
115
116 wp_reset_postdata();
117
118 return ob_get_clean();
119 }
120 add_shortcode( 'powerkit_posts', 'powerkit_inline_posts_shortcode' );
121
122 /**
123 * Map Social Links Shortcode into the Basic Shortcodes Plugin
124 */
125 if ( function_exists( 'powerkit_basic_shortcodes_register' ) ) :
126
127 add_action( 'init', function() {
128
129 $shortcode_map = array(
130 'name' => 'inline_posts',
131 'title' => esc_html__( 'Inline Posts', 'powerkit' ),
132 'priority' => 200,
133 'base' => 'powerkit_posts',
134 'autoregister' => false,
135 'fields' => array(
136 array(
137 'type' => 'input',
138 'name' => 'title',
139 'label' => esc_html__( 'Title', 'powerkit' ),
140 'default' => '',
141 ),
142 array(
143 'type' => 'input',
144 'name' => 'count',
145 'label' => esc_html__( 'Count', 'powerkit' ),
146 'default' => 1,
147 ),
148 array(
149 'type' => 'input',
150 'name' => 'offset',
151 'label' => esc_html__( 'Offset', 'powerkit' ),
152 'default' => 0,
153 ),
154 array(
155 'type' => 'input',
156 'name' => 'image_size',
157 'label' => esc_html__( 'Image size', 'powerkit' ),
158 'default' => 'pk-thumbnail',
159 ),
160 array(
161 'type' => 'input',
162 'name' => 'category',
163 'label' => esc_html__( 'Filter by categories', 'powerkit' ),
164 'desc' => esc_html__( 'Add comma-separated list of category slugs. For example: &laquo;travel, lifestyle, food&raquo;. Leave empty for all categories.', 'powerkit' ),
165 'default' => '',
166 ),
167 array(
168 'type' => 'input',
169 'name' => 'tag',
170 'label' => esc_html__( 'Filter by tags', 'powerkit' ),
171 'desc' => esc_html__( 'Add comma-separated list of tag slugs. For example: &laquo;worth-reading, top-5, playlists&raquo;. Leave empty for all tags.', 'powerkit' ),
172 'default' => '',
173 ),
174 array(
175 'type' => 'input',
176 'name' => 'ids',
177 'label' => esc_html__( 'Filter by posts', 'powerkit' ),
178 'desc' => esc_html__( 'Add comma-separated list of post IDs. For example: 12, 34, 145. Leave empty for all posts.', 'powerkit' ),
179 'default' => '',
180 ),
181 ),
182 );
183
184 // Add fields order and time frame.
185 if ( powerkit_post_views_enabled() ) {
186 $shortcode_map['fields'][] = array(
187 'type' => 'radio',
188 'name' => 'orderby',
189 'label' => esc_html__( 'Order posts by', 'powerkit' ),
190 'style' => 'vertical',
191 'default' => 'date',
192 'options' => array(
193 'date' => esc_html__( 'Date', 'powerkit' ),
194 'post_views' => esc_html__( 'Views', 'powerkit' ),
195 ),
196 );
197
198 $shortcode_map['fields'][] = array(
199 'type' => 'radio',
200 'name' => 'order',
201 'label' => esc_html__( 'Order', 'powerkit' ),
202 'style' => 'vertical',
203 'default' => 'DESC',
204 'options' => array(
205 'DESC' => esc_html__( 'DESC', 'powerkit' ),
206 'ASC' => esc_html__( 'ASC', 'powerkit' ),
207 ),
208 );
209
210 $shortcode_map['fields'][] = array(
211 'type' => 'input',
212 'name' => 'time_frame',
213 'label' => esc_html__( 'Filter by time frame', 'powerkit' ),
214 'desc' => esc_html__( 'Work only if Order by Views', 'powerkit' ) . '<br>' .
215 esc_html__( 'Add period of posts in English. For example: &laquo;2 months&raquo;, &laquo;14 days&raquo; or even &laquo;1 year&raquo;', 'powerkit' ),
216 'default' => '',
217 );
218 }
219
220 // Add field template.
221 $templates = apply_filters( 'powerkit_inline_posts_templates', array() );
222
223 if ( count( (array) $templates ) > 1 ) {
224 $options = array();
225
226 foreach ( $templates as $key => $item ) {
227 if ( isset( $item['name'] ) ) {
228 $options[ $key ] = $item['name'];
229 }
230 }
231
232 $shortcode_map['fields'][] = array(
233 'type' => 'select',
234 'name' => 'template',
235 'label' => esc_html__( 'Template', 'powerkit' ),
236 'default' => 'list',
237 'options' => $options,
238 );
239 }
240
241 powerkit_basic_shortcodes_register( $shortcode_map );
242
243 });
244
245 endif;
246