PluginProbe
Getwid – Gutenberg Blocks / 2.2.0
Getwid – Gutenberg Blocks v2.2.0
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-meta.php

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

129 lines 3.5 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 PostMeta extends \Getwid\Blocks\AbstractBlock {
6
7 protected static $blockName = 'getwid/template-post-meta';
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
30 //Colors
31 'direction' => array(
32 'type' => 'string',
33 'default' => 'row'
34 ),
35 'textAlignment' => array(
36 'type' => 'string'
37 ),
38
39 'className' => array(
40 'type' => 'string'
41 )
42 ),
43 'render_callback' => [ $this, 'render_callback' ]
44 )
45 );
46 }
47
48 public function block_frontend_assets() {
49
50 if ( is_admin() ) {
51 return;
52 }
53
54 if ( FALSE == getwid()->assetsOptimization()->load_assets_on_demand() ) {
55 return;
56 }
57
58 add_filter( 'getwid/optimize/assets',
59 function ( $assets ) {
60 $assets[] = self::$assetsHandle;
61
62 return $assets;
63 }
64 );
65
66 $rtl = is_rtl() ? '.rtl' : '';
67
68 wp_enqueue_style(
69 self::$assetsHandle,
70 getwid_get_plugin_url( 'assets/blocks/template-parts/style' . $rtl . '.css' ),
71 [],
72 getwid()->settings()->getVersion()
73 );
74 }
75
76 public function render_callback( $attributes, $content ) {
77 //Not BackEnd render if we view from template page
78 if ( ( get_post_type() == getwid()->postTemplatePart()->postType ) || ( get_post_type() == 'revision' ) ) {
79 return $content;
80 }
81
82 $block_name = 'wp-block-getwid-template-post-meta';
83 $wrapper_class = $block_name;
84
85 $wrapper_style = '';
86 //Classes
87 if ( isset( $attributes[ 'className' ] ) ) {
88 $wrapper_class .= ' '.esc_attr( $attributes[ 'className' ] );
89 }
90
91 if ( isset( $attributes[ 'direction' ] ) ) {
92 $wrapper_class .= ' has-direction-' . esc_attr( $attributes[ 'direction' ] );
93 }
94 if ( isset( $attributes[ 'textAlignment' ] ) ) {
95 if ( $attributes[ 'direction' ] == 'row' ) {
96 $wrapper_class .= ' has-alignment-' . esc_attr( $attributes[ 'textAlignment' ] );
97 } else {
98 $wrapper_style .= 'text-align: ' . esc_attr( $attributes[ 'textAlignment' ] ) . ';';
99 }
100 }
101
102 $is_back_end = getwid_is_block_editor();
103
104 getwid_custom_color_style_and_class( $wrapper_style, $wrapper_class, $attributes, 'color', $is_back_end );
105
106 $result = '';
107
108 $extra_attr = array(
109 'wrapper_class' => $wrapper_class,
110 'wrapper_style' => $wrapper_style,
111 'content' => $content
112 );
113
114 if ( strlen( $content ) ) {
115 ob_start();
116
117 getwid_get_template_part( 'template-parts/post-meta', $attributes, false, $extra_attr );
118
119 $result = ob_get_clean();
120 }
121
122 $this->block_frontend_assets();
123
124 return $result;
125 }
126 }
127
128 new \Getwid\Blocks\PostMeta();
129