PluginProbe
Getwid – Gutenberg Blocks / 1.8.7
Getwid – Gutenberg Blocks v1.8.7
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-title.php

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

159 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 PostTitle extends \Getwid\Blocks\AbstractBlock {
6
7 protected static $blockName = 'getwid/template-post-title';
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 //Colors
19 'textColor' => array(
20 'type' => 'string'
21 ),
22 'customTextColor' => array(
23 'type' => 'string'
24 ),
25
26 //Colors
27 'linkTo' => array(
28 'type' => 'string',
29 'default' => 'none'
30 ),
31 'fontSize' => array(
32 'type' => 'string'
33 ),
34 'customFontSize' => array(
35 'type' => 'string'
36 ),
37 'bold' => array(
38 'type' => 'boolean'
39 ),
40 'italic' => array(
41 'type' => 'boolean',
42 'default' => false
43 ),
44 'textAlignment' => array(
45 'type' => 'string'
46 ),
47 'headerTag' => array(
48 'type' => 'string',
49 'default' => 'h2'
50 ),
51
52 'className' => array(
53 'type' => 'string'
54 )
55 ),
56 'render_callback' => [ $this, 'render_callback' ]
57 )
58 );
59 }
60
61 public function block_frontend_assets() {
62
63 if ( is_admin() ) {
64 return;
65 }
66
67 if ( FALSE == getwid()->assetsOptimization()->load_assets_on_demand() ) {
68 return;
69 }
70
71 add_filter( 'getwid/optimize/assets',
72 function ( $assets ) {
73 $assets[] = self::$assetsHandle;
74
75 return $assets;
76 }
77 );
78
79 $rtl = is_rtl() ? '.rtl' : '';
80
81 wp_enqueue_style(
82 self::$assetsHandle,
83 getwid_get_plugin_url( 'assets/blocks/template-parts/style' . $rtl . '.css' ),
84 [],
85 getwid()->settings()->getVersion()
86 );
87 }
88
89 public function render_callback( $attributes, $content ) {
90
91 //Not BackEnd render if we view from template page
92 if ( ( get_post_type() == getwid()->postTemplatePart()->postType ) || ( get_post_type() == 'revision' ) ) {
93 return $content;
94 }
95
96 $block_name = 'wp-block-getwid-template-post-title';
97 //Link style & class
98 $title_style = '';
99 $title_class = $block_name;
100
101 //Classes
102 if ( isset( $attributes[ 'className' ] ) ) {
103 $title_class .= ' '.esc_attr( $attributes[ 'className' ] );
104 }
105
106 if ( isset( $attributes[ 'textAlignment' ] ) ) {
107 $title_style .= 'text-align: ' . esc_attr( $attributes[ 'textAlignment' ] ) . ';';
108 }
109
110 $is_back_end = getwid_is_block_editor();
111
112
113 $link_class = esc_attr( $block_name ) . '__link';
114
115 if ( isset( $attributes[ 'bold' ] ) && $attributes[ 'bold' ] ) {
116 $title_style .= 'font-weight: bold;';
117 }
118
119 if ( isset( $attributes[ 'italic' ] ) && $attributes[ 'italic' ] ) {
120 $title_style .= 'font-style: italic;';
121 }
122
123 if ( isset( $attributes[ 'customFontSize' ] ) ) {
124 $font_size = is_numeric( $attributes['customFontSize'] ) ? $attributes['customFontSize'] . 'px' : $attributes['customFontSize'];
125 $title_style .= 'font-size: ' . esc_attr( $font_size ) . ';';
126 }
127
128 if ( isset( $attributes[ 'fontSize' ] ) ) {
129 $title_class .= ' has-'.esc_attr( $attributes[ 'fontSize' ] ) . '-font-size';
130 }
131
132 getwid_custom_color_style_and_class( $title_style, $title_class, $attributes, 'color', $is_back_end );
133
134 $result = '';
135 $headerTag = $attributes[ 'headerTag' ];
136
137 $extra_attr = array(
138 'headerTag' => $headerTag,
139 'title_style' => $title_style,
140 'title_class' => $title_class,
141 'link_class' => $link_class
142 );
143
144 if ( get_the_title() ) {
145 ob_start();
146
147 getwid_get_template_part( 'template-parts/post-title', $attributes, false, $extra_attr );
148
149 $result = ob_get_clean();
150 }
151
152 $this->block_frontend_assets();
153
154 return $result;
155 }
156 }
157
158 new \Getwid\Blocks\PostTitle();
159