PluginProbe
Getwid – Gutenberg Blocks / 2.0.6
Getwid – Gutenberg Blocks v2.0.6
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-comments.php

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

157 lines 4.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;
4
5 class PostComments extends \Getwid\Blocks\AbstractBlock {
6
7 protected static $blockName = 'getwid/template-post-comments';
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-comments'
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 'textAlignment' => array(
54 'type' => 'string'
55 ),
56
57 'className' => array(
58 'type' => 'string'
59 )
60 ),
61 'render_callback' => [ $this, 'render_callback' ]
62 )
63 );
64 }
65
66 public function block_frontend_assets() {
67
68 if ( is_admin() ) {
69 return;
70 }
71
72 if ( FALSE == getwid()->assetsOptimization()->load_assets_on_demand() ) {
73 return;
74 }
75
76 add_filter( 'getwid/optimize/assets',
77 function ( $assets ) {
78 $assets[] = self::$assetsHandle;
79
80 return $assets;
81 }
82 );
83
84 $rtl = is_rtl() ? '.rtl' : '';
85
86 wp_enqueue_style(
87 self::$assetsHandle,
88 getwid_get_plugin_url( 'assets/blocks/template-parts/style' . $rtl . '.css' ),
89 [],
90 getwid()->settings()->getVersion()
91 );
92 }
93
94 public function render_callback( $attributes, $content ) {
95
96 //Not BackEnd render if we view from template page
97 if ( ( get_post_type() == getwid()->postTemplatePart()->postType ) || ( get_post_type() == 'revision' ) ) {
98 return $content;
99 }
100
101 $block_name = 'wp-block-getwid-template-post-comments';
102 $wrapper_class = $block_name;
103
104 if ( isset( $attributes[ 'className' ] ) ) {
105 $wrapper_class .= ' ' . esc_attr( $attributes[ 'className' ] );
106 }
107
108 $wrapper_style = '';
109 //Classes
110 if ( isset( $attributes[ 'textAlignment' ] ) ) {
111 $wrapper_style .= 'text-align: '.esc_attr( $attributes[ 'textAlignment' ] ) . ';';
112 }
113
114 if ( isset( $attributes[ 'customFontSize' ] ) ) {
115 $font_size = is_numeric( $attributes['customFontSize'] ) ? $attributes['customFontSize'] . 'px' : $attributes['customFontSize'];
116 $wrapper_style .= 'font-size: ' . esc_attr( $font_size ) . ';';
117 }
118
119 if (isset($attributes[ 'fontSize' ] ) ) {
120 $wrapper_class .= ' has-' . esc_attr( $attributes[ 'fontSize' ] ) . '-font-size';
121 }
122
123 $is_back_end = getwid_is_block_editor();
124
125 //Link style & class
126 getwid_custom_color_style_and_class( $wrapper_style, $wrapper_class, $attributes, 'color', $is_back_end );
127
128 $icon_class = '';
129 $icon_style = '';
130 getwid_custom_color_style_and_class( $icon_style, $icon_class, $attributes, 'color', $is_back_end, [ 'color' => 'iconColor', 'custom' => 'customIconColor' ] );
131
132 $result = '';
133
134 $extra_attr = array(
135 'wrapper_class' => $wrapper_class,
136 'wrapper_style' => $wrapper_style,
137
138 'icon_class' => $icon_class,
139 'icon_style' => $icon_style
140 );
141
142 if ( comments_open() || get_comments_number() ) {
143 ob_start();
144
145 getwid_get_template_part( 'template-parts/post-comments', $attributes, false, $extra_attr );
146
147 $result = ob_get_clean();
148 }
149
150 $this->block_frontend_assets();
151
152 return $result;
153 }
154 }
155
156 new \Getwid\Blocks\PostComments();
157