PluginProbe
Gutenify – Visual Site Builder Blocks & Starter Templates / 1.0.2
Gutenify – Visual Site Builder Blocks & Starter Templates v1.0.2
1.9.0 1.8.0 1.7.0 1.6.6 1.6.5 1.6.4 trunk 0.0.1 0.0.2 0.0.3 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 All 74 releases
gutenify / src / blocks / section-title / index.php

index.php in Gutenify – Visual Site Builder Blocks & Starter Templates 1.0.2, at src/blocks/section-title/index.php

107 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Server-side rendering of the `gutenify/section-title` block.
4 *
5 * @package WordPress
6 */
7
8 /**
9 * Renders the `gutenify/section-title` block on the server.
10 *
11 * @param array $attributes Block attributes.
12 *
13 * @return string Returns the filtered post title for the current post wrapped inside "h1" tags.
14 */
15 function gutenify_render_block_section_title( $attributes ) {
16 $align_class_name = empty( $attributes['textAlignment'] ) ? '' : "has-text-align-{$attributes['textAlignment']}";
17
18 $prefix_level = ! empty( $attributes['prefixTag'] ) ? $attributes['prefixTag'] : 'h4';
19
20 $wrapper_attributes = '';
21 if ( ! empty( $attributes['prefixColor'] ) ) {
22 $wrapper_attributes = 'style="color:' . $attributes['prefixColor'] . '"';
23 }
24 $wrapper_attributes .= 'class="gutenify-section-title-prefix"';
25 $prefix_content = ! empty( $attributes['prefixContent'] ) ? $attributes['prefixContent'] : '';
26
27 $prefix = sprintf(
28 '<%1$s %2$s>%3$s</%1$s>',
29 $prefix_level,
30 $wrapper_attributes,
31 $prefix_content
32 );
33
34 // Heading.
35 $title_level = ! empty( $attributes['titleTag'] ) ? $attributes['titleTag'] : 'h2';
36
37 $wrapper_attributes = '';
38 if ( ! empty( $attributes['titleColor'] ) ) {
39 $wrapper_attributes = 'style="color:' . $attributes['titleColor'] . '"';
40 }
41 $wrapper_attributes .= 'class="gutenify-section-title-main"';
42 $title_content = ! empty( $attributes['titleContent'] ) ? $attributes['titleContent'] : '';
43
44 $title = sprintf(
45 '<%1$s %2$s>%3$s</%1$s>',
46 $title_level,
47 $wrapper_attributes,
48 $title_content
49 );
50
51 // Suffix.
52 $suffix_level = ! empty( $attributes['suffixTag'] ) ? $attributes['suffixTag'] : 'p';
53
54 $wrapper_attributes = '';
55 if ( ! empty( $attributes['suffixColor'] ) ) {
56 $wrapper_attributes = 'style="color:' . $attributes['suffixColor'] . '"';
57 }
58 $wrapper_attributes .= 'class="gutenify-section-title-suffix"';
59 $suffix_content = ! empty( $attributes['suffixContent'] ) ? $attributes['suffixContent'] : '';
60
61 $suffix = sprintf(
62 '<%1$s %2$s>%3$s</%1$s>',
63 $suffix_level,
64 $wrapper_attributes,
65 $suffix_content
66 );
67 $block_client_id = ! empty( $attributes['blockClientId'] ) ? $attributes['blockClientId'] : 1;
68 $output = '<div class="wp-block-gutenify-section-title ' . $align_class_name . '">';
69 $output .= '<div id="gutenify-section-' . $block_client_id . '" class="gutenify-section-title-section gutenify-section-' . $attributes['blockClientId']. '">';
70 if ( ! empty( $attributes['displayPrefix'] ) ) {
71 $output .= $prefix;
72 }
73 $output .= $title;
74 if ( ! empty( $attributes['displaySuffix'] ) ) {
75 $output .= $suffix;
76 }
77 $output .= '</div>';
78 $output .= '</div>';
79 return $output;
80 }
81
82 /**
83 * Registers the `gutenify/section-title` block on the server.
84 */
85 function gutenify_register_block_section_title() {
86 // Return early if this function does not exist.
87 if ( ! function_exists( 'register_block_type' ) ) {
88 return;
89 }
90
91 // Load attributes from block.json.
92 ob_start();
93 include GUTENIFY_PLUGIN_DIR . 'src/blocks/section-title/block.json';
94 $metadata = json_decode( ob_get_clean(), true );
95 register_block_type(
96 'gutenify/section-title',
97 array(
98 'render_callback' => 'gutenify_render_block_section_title',
99 'editor_script' => 'gutenify-editor',
100 'editor_style' => 'gutenify-editor',
101 'style' => 'gutenify-frontend',
102 'attributes' => $metadata['attributes'],
103 )
104 );
105 }
106 add_action( 'init', 'gutenify_register_block_section_title' );
107