# gutenify/1.0.3/src/blocks/section-title/index.php

Gutenify – Visual Site Builder Blocks &amp; Starter Templates, version 1.0.3. 107 lines.

- Page: https://pluginprobe.com/plugins/gutenify/1.0.3/code/src/blocks/section-title/index.php
- Raw: https://pluginprobe.com/plugins/gutenify/1.0.3/raw/src/blocks/section-title/index.php
- Modified: 2022-04-05T14:40:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/gutenify/1.0.3/code/src/blocks/section-title/index.php#L10-L20`.

```php
<?php
/**
 * Server-side rendering of the `gutenify/section-title` block.
 *
 * @package WordPress
 */

/**
 * Renders the `gutenify/section-title` block on the server.
 *
 * @param array $attributes Block attributes.
 *
 * @return string Returns the filtered post title for the current post wrapped inside "h1" tags.
 */
function gutenify_render_block_section_title( $attributes ) {
	$align_class_name = empty( $attributes['textAlignment'] ) ? '' : "has-text-align-{$attributes['textAlignment']}";

	$prefix_level = ! empty( $attributes['prefixTag'] ) ? $attributes['prefixTag'] : 'h4';

	$wrapper_attributes = '';
	if ( ! empty( $attributes['prefixColor'] ) ) {
		$wrapper_attributes = 'style="color:' . $attributes['prefixColor'] . '"';
	}
	$wrapper_attributes .= 'class="gutenify-section-title-prefix"';
	$prefix_content = ! empty( $attributes['prefixContent'] ) ? $attributes['prefixContent'] : '';

	$prefix = sprintf(
		'<%1$s %2$s>%3$s</%1$s>',
		$prefix_level,
		$wrapper_attributes,
		$prefix_content
	);

	// Heading.
	$title_level = ! empty( $attributes['titleTag'] ) ? $attributes['titleTag'] : 'h2';

	$wrapper_attributes = '';
	if ( ! empty( $attributes['titleColor'] ) ) {
		$wrapper_attributes = 'style="color:' . $attributes['titleColor'] . '"';
	}
	$wrapper_attributes .= 'class="gutenify-section-title-main"';
	$title_content = ! empty( $attributes['titleContent'] ) ? $attributes['titleContent'] : '';

	$title = sprintf(
		'<%1$s %2$s>%3$s</%1$s>',
		$title_level,
		$wrapper_attributes,
		$title_content
	);

	// Suffix.
	$suffix_level = ! empty( $attributes['suffixTag'] ) ? $attributes['suffixTag'] : 'p';

	$wrapper_attributes = '';
	if ( ! empty( $attributes['suffixColor'] ) ) {
		$wrapper_attributes = 'style="color:' . $attributes['suffixColor'] . '"';
	}
	$wrapper_attributes .= 'class="gutenify-section-title-suffix"';
	$suffix_content = ! empty( $attributes['suffixContent'] ) ? $attributes['suffixContent'] : '';

	$suffix          = sprintf(
		'<%1$s %2$s>%3$s</%1$s>',
		$suffix_level,
		$wrapper_attributes,
		$suffix_content
	);
	$block_client_id = ! empty( $attributes['blockClientId'] ) ? $attributes['blockClientId'] : 1;
	$output          = '<div class="wp-block-gutenify-section-title ' . $align_class_name . ' gutenify-section-' . $attributes['blockClientId']. '">';
	$output         .= '<div id="gutenify-section-' . $block_client_id . '" class="gutenify-section-title-section ">';
	if ( ! empty( $attributes['displayPrefix'] ) ) {
		$output .= $prefix;
	}
	$output .= $title;
	if ( ! empty( $attributes['displaySuffix'] ) ) {
		$output .= $suffix;
	}
	$output .= '</div>';
	$output .= '</div>';
	return $output;
}

/**
 * Registers the `gutenify/section-title` block on the server.
 */
function gutenify_register_block_section_title() {
	// Return early if this function does not exist.
	if ( ! function_exists( 'register_block_type' ) ) {
		return;
	}

	// Load attributes from block.json.
	ob_start();
	include GUTENIFY_PLUGIN_DIR . 'src/blocks/section-title/block.json';
	$metadata = json_decode( ob_get_clean(), true );
	register_block_type(
		'gutenify/section-title',
		array(
			'render_callback' => 'gutenify_render_block_section_title',
			'editor_script'   => 'gutenify-editor',
			'editor_style'    => 'gutenify-editor',
			'style'           => 'gutenify-frontend',
			'attributes'      => $metadata['attributes'],
		)
	);
}
add_action( 'init', 'gutenify_register_block_section_title' );

```
