PluginProbe
Getwid – Gutenberg Blocks / 3.0.2
Getwid – Gutenberg Blocks v3.0.2
3.0.2 3.0.1 3.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.2.0 trunk 1.8.7 1.9.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9
← All changes | includes/blocks/recent-posts.php +31 -138 2.1.13.0.2 View file →
@@ -1,139 +1,34 @@
1 1 <?php
2 2
3 3 namespace Getwid\Blocks;
4 4
5 -class RecentPosts extends \Getwid\Blocks\AbstractBlock {
5 +class RecentPosts extends AbstractBlock {
6 6
7 - protected static $blockName = 'getwid/recent-posts';
7 + public function __construct() {
8 8
9 - public function __construct() {
9 + parent::__construct( 'getwid/recent-posts' );
10 10
11 - parent::__construct( self::$blockName );
12 -
13 - register_block_type(
14 - 'getwid/recent-posts',
15 - array(
16 - 'attributes' => array(
17 - 'titleTag' => array(
18 - 'type' => 'string',
19 - 'default' => 'h3',
20 - ),
21 - 'imageSize' => array(
22 - 'type' => 'string',
23 - 'default' => 'large',
24 - ),
25 - 'cropImages' => array(
26 - 'type' => 'boolean',
27 - 'default' => true,
28 - ),
29 - 'categories' => array(
30 - 'type' => 'string',
31 - ),
32 - 'postsToShow' => array(
33 - 'type' => 'number',
34 - 'default' => 5,
35 - ),
36 - 'showTitle' => array(
37 - 'type' => 'boolean',
38 - 'default' => true,
39 - ),
40 - 'showDate' => array(
41 - 'type' => 'boolean',
42 - 'default' => false,
43 - ),
44 - 'showCategories' => array(
45 - 'type' => 'boolean',
46 - 'default' => false,
47 - ),
48 - 'showCommentsCount' => array(
49 - 'type' => 'boolean',
50 - 'default' => false,
51 - ),
52 - 'showContent' => array(
53 - 'type' => 'boolean',
54 - 'default' => false,
55 - ),
56 - 'contentLength' => array(
57 - 'type' => 'number',
58 - 'default' => apply_filters('excerpt_length', 55),
59 - ),
60 - 'showFeaturedImage' => array(
61 - 'type' => 'boolean',
62 - 'default' => false,
63 - ),
64 - 'postLayout' => array(
65 - 'type' => 'string',
66 - 'default' => 'list',
67 - ),
68 - 'columns' => array(
69 - 'type' => 'number',
70 - 'default' => 3,
71 - ),
72 - 'align' => array(
73 - 'type' => 'string',
74 - ),
75 - 'order' => array(
76 - 'type' => 'string',
77 - 'default' => 'desc',
78 - ),
79 - 'orderBy' => array(
80 - 'type' => 'string',
81 - 'default' => 'date',
82 - ),
83 -
84 - 'className' => array(
85 - 'type' => 'string',
86 - ),
87 - ),
88 - 'render_callback' => [ $this, 'render_callback' ]
89 - )
90 - );
91 - }
92 -
93 - public function getLabel() {
94 - return __('Recent Posts', 'getwid');
11 + register_block_type(
12 + getwid_get_plugin_path( 'assets/blocks/recent-posts' ),
13 + array(
14 + 'render_callback' => array( $this, 'render_callback' ),
15 + )
16 + );
95 17 }
96 18
97 - public function block_frontend_assets() {
98 -
99 - if ( is_admin() ) {
100 - return;
101 - }
102 -
103 - if ( FALSE == getwid()->assetsOptimization()->load_assets_on_demand() ) {
104 - return;
105 - }
106 -
107 - add_filter( 'getwid/optimize/assets',
108 - function ( $assets ) {
109 - $assets[] = getwid()->settings()->getPrefix() . '-blocks-common';
110 -
111 - return $assets;
112 - }
113 - );
114 -
115 - add_filter( 'getwid/optimize/should_load_common_css', '__return_true' );
116 -
117 - $rtl = is_rtl() ? '.rtl' : '';
118 -
119 - wp_enqueue_style(
120 - self::$blockName,
121 - getwid_get_plugin_url( 'assets/blocks/recent-posts/style' . $rtl . '.css' ),
122 - [],
123 - getwid()->settings()->getVersion()
124 - );
125 -
19 + public function get_label() {
20 + return __( 'Recent Posts', 'getwid' );
126 21 }
127 22
128 - public function render_callback( $attributes, $content ) {
23 + public function render_callback( $attributes, $content ) {
129 24
130 25 $query_args = array(
131 - 'posts_per_page' => $attributes['postsToShow'],
26 + 'posts_per_page' => $attributes['postsToShow'],
132 27 'ignore_sticky_posts' => 1,
133 - 'post_status' => 'publish',
134 - 'order' => $attributes['order'],
135 - 'orderby' => $attributes['orderBy'],
28 + 'post_status' => 'publish',
29 + 'order' => $attributes['order'],
30 + 'orderby' => $attributes['orderBy'],
136 31 );
137 32
138 33 if ( isset( $attributes['categories'] ) ) {
139 34 $query_args['tax_query'] = array(
@@ -138,11 +33,11 @@
138 33 if ( isset( $attributes['categories'] ) ) {
139 34 $query_args['tax_query'] = array(
140 35 array(
141 36 'taxonomy' => 'category',
142 - 'field' => 'id',
143 - 'terms' => $attributes['categories']
144 - )
37 + 'field' => 'id',
38 + 'terms' => $attributes['categories'],
39 + ),
145 40 );
146 41 }
147 42
148 43 $block_name = 'wp-block-getwid-recent-posts';
@@ -147,9 +42,9 @@
147 42
148 43 $block_name = 'wp-block-getwid-recent-posts';
149 44
150 45 $extra_attr = array(
151 - 'block_name' => $block_name
46 + 'block_name' => $block_name,
152 47 );
153 48
154 49 $class = $block_name;
155 50
@@ -164,19 +59,19 @@
164 59 }
165 60 if ( isset( $attributes['className'] ) ) {
166 61 $class .= ' ' . $attributes['className'];
167 62 }
168 - if( isset( $attributes['cropImages'] ) && $attributes['cropImages'] === true ){
63 + if ( isset( $attributes['cropImages'] ) && true === $attributes['cropImages'] ) {
169 64 $class .= ' has-cropped-images';
170 65 }
171 66
172 67 $wrapper_class = $block_name . '__wrapper';
173 68
174 - if ( isset( $attributes['columns'] ) && $attributes['postLayout'] === 'grid' ) {
69 + if ( isset( $attributes['columns'] ) && 'grid' === $attributes['postLayout'] ) {
175 70 $wrapper_class .= ' getwid-columns getwid-columns-' . $attributes['columns'];
176 71 }
177 72
178 - $attributes['titleTag'] = $this->validateHeadingHTMLTag( $attributes['titleTag'] );
73 + $attributes['titleTag'] = $this->validate_heading_html_tag( $attributes['titleTag'] );
179 74
180 75 $q = new \WP_Query( $query_args );
181 76 ob_start();
182 77 ?>
@@ -181,23 +76,23 @@
181 76 ob_start();
182 77 ?>
183 78
184 79 <div class="<?php echo esc_attr( $class ); ?>">
185 - <div class="<?php echo esc_attr( $wrapper_class );?>">
80 + <div class="<?php echo esc_attr( $wrapper_class ); ?>">
186 81 <?php
187 - if ( $q->have_posts() ):
82 + if ( $q->have_posts() ) :
188 83 ob_start();
189 84
190 - while( $q->have_posts() ):
85 + while ( $q->have_posts() ) :
191 86 $q->the_post();
192 - getwid_get_template_part('recent-posts/post', $attributes, false, $extra_attr);
87 + getwid_get_template_part( 'recent-posts/post', $attributes, false, $extra_attr );
193 88 endwhile;
194 89
195 90 wp_reset_postdata();
196 91 ob_end_flush();
197 - else:
92 + else :
198 93 do_action( 'getwid/blocks/recent-posts/no-items', $attributes, $content );
199 - endif;
94 + endif;
200 95 ?>
201 96 </div>
202 97 </div>
203 98 <?php
@@ -203,13 +98,11 @@
203 98 <?php
204 99
205 100 $result = ob_get_clean();
206 101
207 - $this->block_frontend_assets();
208 -
209 102 return $result;
210 - }
103 + }
211 104 }
212 105
213 106 getwid()->blocksManager()->addBlock(
214 - new \Getwid\Blocks\RecentPosts()
107 + new RecentPosts()
215 108 );