PluginProbe
Getwid – Gutenberg Blocks / 2.0.9
Getwid – Gutenberg Blocks v2.0.9
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-author.php

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

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