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
getwid / includes / blocks / template-parts / post-categories.php

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

106 lines 2.7 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\TemplateParts;
4
5 class PostCategories extends \Getwid\Blocks\AbstractBlock {
6
7 protected static $assets_handle = 'getwid/template-parts';
8
9 public function __construct() {
10
11 parent::__construct( 'getwid/template-post-categories' );
12
13 register_block_type(
14 getwid_get_plugin_path( 'assets/blocks/template-parts/post-categories' ),
15 array(
16 'render_callback' => array( $this, 'render_callback' ),
17 )
18 );
19 }
20
21 public function get_label() {
22 return __( 'Categories', 'getwid' );
23 }
24
25 public function can_be_disabled() {
26 return false;
27 }
28
29 public function render_callback( $attributes, $content ) {
30
31 if ( ( get_post_type() === getwid()->postTemplatePart()->postType ) || ( get_post_type() === 'revision' ) ) {
32 return $content;
33 }
34
35 $block_name = 'wp-block-getwid-template-post-categories';
36 $wrapper_class = $block_name;
37 $wrapper_style = '';
38
39 if ( isset( $attributes['className'] ) ) {
40 $wrapper_class .= ' ' . esc_attr( $attributes['className'] );
41 }
42
43 if ( isset( $attributes['divider'] ) && '' !== $attributes['divider'] ) {
44 $wrapper_class .= ' has-divider';
45 }
46
47 if ( isset( $attributes['textAlignment'] ) ) {
48 $wrapper_style .= 'text-align: ' . esc_attr( $attributes['textAlignment'] ) . ';';
49 }
50
51 if ( isset( $attributes['customFontSize'] ) ) {
52 $font_size = is_numeric( $attributes['customFontSize'] ) ? $attributes['customFontSize'] . 'px' : $attributes['customFontSize'];
53 $wrapper_style .= 'font-size: ' . esc_attr( $font_size ) . ';';
54 }
55
56 if ( isset( $attributes['fontSize'] ) ) {
57 $wrapper_class .= ' has-' . esc_attr( $attributes['fontSize'] ) . '-font-size';
58 }
59
60 $divider = isset( $attributes['divider'] ) && '' !== $attributes['divider'] ? $attributes['divider'] : '';
61
62 $is_back_end = getwid_is_block_editor();
63
64 getwid_custom_color_style_and_class( $wrapper_style, $wrapper_class, $attributes, 'color', $is_back_end );
65
66 $categories_list = get_the_category_list( $divider . ' ' );
67 $icon_class = '';
68 $icon_style = '';
69
70 getwid_custom_color_style_and_class(
71 $icon_style,
72 $icon_class,
73 $attributes,
74 'color',
75 $is_back_end,
76 array(
77 'color' => 'iconColor',
78 'custom' => 'customIconColor',
79 )
80 );
81
82 $result = '';
83 $extra_attr = array(
84 'wrapper_class' => $wrapper_class,
85 'wrapper_style' => $wrapper_style,
86 'categories_list' => $categories_list,
87 'icon_class' => $icon_class,
88 'icon_style' => $icon_style,
89 );
90
91 if ( $categories_list ) {
92 ob_start();
93
94 getwid_get_template_part( 'template-parts/post-categories', $attributes, false, $extra_attr );
95
96 $result = ob_get_clean();
97 }
98
99 return $result;
100 }
101 }
102
103 getwid()->blocksManager()->addBlock(
104 new PostCategories()
105 );
106