PluginProbe
Getwid – Gutenberg Blocks / 2.0.10
Getwid – Gutenberg Blocks v2.0.10
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
getwid / includes / blocks / template-parts / post-categories.php

post-categories.php in Getwid – Gutenberg Blocks 2.0.10, at includes/blocks/template-parts/post-categories.php

169 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Getwid\Blocks;
4
5 class PostCategories extends \Getwid\Blocks\AbstractBlock {
6
7 protected static $blockName = 'getwid/template-post-categories';
8 protected static $assetsHandle = 'getwid/template-parts';
9
10 public function __construct() {
11
12 parent::__construct( self::$blockName );
13
14 register_block_type(
15 self::$blockName,
16 array(
17 'attributes' => array(
18 'blockDivider' => array(
19 'type' => 'string'
20 ),
21
22 //Colors
23 'textColor' => array(
24 'type' => 'string'
25 ),
26 'customTextColor' => array(
27 'type' => 'string'
28 ),
29 'backgroundColor' => array(
30 'type' => 'string'
31 ),
32 'customBackgroundColor' => array(
33 'type' => 'string'
34 ),
35
36 //Colors
37 'icon' => array(
38 'type' => 'string',
39 'default' => 'fas fa-folder-open'
40 ),
41 'iconColor' => array(
42 'type' => 'string'
43 ),
44 'customIconColor' => array(
45 'type' => 'string'
46 ),
47 'fontSize' => array(
48 'type' => 'string'
49 ),
50 'customFontSize' => array(
51 'type' => 'string'
52 ),
53 'divider' => array(
54 'type' => 'string',
55 'default' => ','
56 ),
57 'textAlignment' => array(
58 'type' => 'string'
59 ),
60
61 'className' => array(
62 'type' => 'string'
63 )
64 ),
65 'render_callback' => [ $this, 'render_callback' ]
66 )
67 );
68 }
69
70 public function block_frontend_assets() {
71
72 if ( is_admin() ) {
73 return;
74 }
75
76 if ( FALSE == getwid()->assetsOptimization()->load_assets_on_demand() ) {
77 return;
78 }
79
80 add_filter( 'getwid/optimize/assets',
81 function ( $assets ) {
82 $assets[] = self::$assetsHandle;
83
84 return $assets;
85 }
86 );
87
88 $rtl = is_rtl() ? '.rtl' : '';
89
90 wp_enqueue_style(
91 self::$assetsHandle,
92 getwid_get_plugin_url( 'assets/blocks/template-parts/style' . $rtl . '.css' ),
93 [],
94 getwid()->settings()->getVersion()
95 );
96 }
97
98 public function render_callback( $attributes, $content ) {
99
100 //Not BackEnd render if we view from template page
101 if ( ( get_post_type() == getwid()->postTemplatePart()->postType ) || ( get_post_type() == 'revision' ) ) {
102 return $content;
103 }
104
105 $block_name = 'wp-block-getwid-template-post-categories';
106 $wrapper_class = $block_name;
107
108 if ( isset( $attributes[ 'className' ] ) ) {
109 $wrapper_class .= ' '.esc_attr( $attributes[ 'className' ] );
110 }
111
112 if ( isset( $attributes[ 'divider' ] ) && $attributes[ 'divider' ] != '' ) {
113 $wrapper_class .= ' has-divider';
114 }
115
116 $wrapper_style = '';
117 //Classes
118 if ( isset( $attributes[ 'textAlignment' ] ) ) {
119 $wrapper_style .= 'text-align: ' . esc_attr( $attributes[ 'textAlignment' ] ) . ';';
120 }
121
122 if ( isset( $attributes[ 'customFontSize' ] ) ) {
123 $font_size = is_numeric( $attributes['customFontSize'] ) ? $attributes['customFontSize'] . 'px' : $attributes['customFontSize'];
124 $wrapper_style .= 'font-size: ' . esc_attr( $font_size ) . ';';
125 }
126
127 if ( isset( $attributes[ 'fontSize' ] ) ) {
128 $wrapper_class .= ' has-' . esc_attr( $attributes[ 'fontSize' ] ) . '-font-size';
129 }
130
131 $divider = isset( $attributes[ 'divider' ] ) && $attributes[ 'divider' ] != '' ? $attributes[ 'divider' ] : '';
132
133 $is_back_end = getwid_is_block_editor();
134
135 getwid_custom_color_style_and_class( $wrapper_style, $wrapper_class, $attributes, 'color', $is_back_end );
136
137 $categories_list = get_the_category_list( $divider . ' ' );
138
139 $icon_class = '';
140 $icon_style = '';
141 getwid_custom_color_style_and_class( $icon_style, $icon_class, $attributes, 'color', $is_back_end, [ 'color' => 'iconColor', 'custom' => 'customIconColor' ] );
142
143 $result = '';
144
145 $extra_attr = array(
146 'wrapper_class' => $wrapper_class,
147 'wrapper_style' => $wrapper_style,
148 'categories_list' => $categories_list,
149
150 'icon_class' => $icon_class,
151 'icon_style' => $icon_style
152 );
153
154 if ( $categories_list ) {
155 ob_start();
156
157 getwid_get_template_part( 'template-parts/post-categories', $attributes, false, $extra_attr );
158
159 $result = ob_get_clean();
160 }
161
162 $this->block_frontend_assets();
163
164 return $result;
165 }
166 }
167
168 new \Getwid\Blocks\PostCategories();
169