File: /var/www/html/insiders/wp-load/wp-content/plugins/breadly/block-library/post-date-box.php
<?php
/**
* Renders the `gtm/post-date-box` block on the server.
*
* @param array $attributes Block attributes.
* @param string $content Block default content.
* @param WP_Block $block Block instance.
* @return string Returns the post date for the current post.
*/
function gtm_render_block_post_date_box( $attr, $content, $block ) {
if ( ! isset( $block->context['postId'] ) ) {
return '';
}
$post_ID = $block->context['postId'];
$wrapper_attributes = get_block_wrapper_attributes( ['class' => ''] );
$inner_html = '';
$the_date = ( $attr['dateType'] ?? '' ) == 'modified' ? get_the_modified_date( 'U' ) : get_the_date( 'U' );
if ( ! empty( $attr['enableLine1'] ) ) {
$date = wp_date( $attr['line1format'], $the_date );
$inner_html .= '<div class="wp-block-gtm-post-date-box__line-1" >';
$inner_html .= $date;
$inner_html .= '</div>';
}
$date = wp_date( $attr['line2format'], $the_date );
$inner_html .= '<div class="wp-block-gtm-post-date-box__line-2" >';
$inner_html .= $date;
$inner_html .= '</div>';
if ( ! empty( $attr['enableLine3'] ) ) {
$date = wp_date( $attr['line3format'], $the_date );
$inner_html .= '<div class="wp-block-gtm-post-date-box__line-3" >';
$inner_html .= $date;
$inner_html .= '</div>';
}
return sprintf(
'<div %1$s>%2$s</div>',
$wrapper_attributes,
$inner_html
);
}
/**
* Registers the `gtm/post-date` block on the server.
*/
function gtm_register_block_post_date_box() {
gtm_register_block_type( 'post-date-box', [
'render_callback' => 'gtm_render_block_post_date_box',
] );
}
add_action( 'init', 'gtm_register_block_post_date_box', 20 );
add_filter( 'gtm.BlockStyleCompiler.gtm/post-date-box', 'gtm_compile_block_css_post_date_box', 10, 3 );
function gtm_compile_block_css_post_date_box( $output, $attributes, $blockName ) {
$block_style = ['classes' => [], 'style' => []];
$block_style['classes'][] = 'gtm-block';
if ( ! empty( $attributes['enableLine1'] ) ) {
gtm_css_compileCssVar( $block_style, "post-date-box-line-1-typography", gtm_css_parseTypographyProps( $attributes['line1typography'] ) );
gtm_css_compileCssVar( $block_style, "post-date-box-line-1-padding", gtm_css_parseResponsiveBoxProps( $attributes['line1padding'] ) );
gtm_css_compileCssVar( $block_style, "post-date-box-line-1-spacing", gtm_css_parseSpacingValue( $attributes['line1spacing'] ) );
gtm_css_compileCssVar( $block_style, "post-date-box-line-1-radius", gtm_css_parseBorderRadiusValue( $attributes['line1radius'] ) );
gtm_css_compileCssVar( $block_style, "post-date-box-line-1-color", gtm_css_parseColorValue( $attributes['line1color'] ) );
gtm_css_compileCssVar( $block_style, "post-date-box-line-1-bg", gtm_css_parseColorValue( $attributes['line1bg'] ) );
}
gtm_css_compileCssVar( $block_style, "post-date-box-line-2-typography", gtm_css_parseTypographyProps( $attributes['line2typography'] ) );
gtm_css_compileCssVar( $block_style, "post-date-box-line-2-padding", gtm_css_parseResponsiveBoxProps( $attributes['line2padding'] ) );
gtm_css_compileCssVar( $block_style, "post-date-box-line-2-radius", gtm_css_parseBorderRadiusValue( $attributes['line2radius'] ) );
gtm_css_compileCssVar( $block_style, "post-date-box-line-2-color", gtm_css_parseColorValue( $attributes['line2color'] ) );
gtm_css_compileCssVar( $block_style, "post-date-box-line-2-bg", gtm_css_parseColorValue( $attributes['line2bg'] ) );
if ( ! empty( $attributes['enableLine3'] ) ) {
gtm_css_compileCssVar( $block_style, "post-date-box-line-3-typography", gtm_css_parseTypographyProps( $attributes['line3typography'] ) );
gtm_css_compileCssVar( $block_style, "post-date-box-line-3-padding", gtm_css_parseResponsiveBoxProps( $attributes['line3padding'] ) );
gtm_css_compileCssVar( $block_style, "post-date-box-line-3-spacing", gtm_css_parseSpacingValue( $attributes['line3spacing'] ) );
gtm_css_compileCssVar( $block_style, "post-date-box-line-3-radius", gtm_css_parseBorderRadiusValue( $attributes['line3radius'] ) );
gtm_css_compileCssVar( $block_style, "post-date-box-line-3-color", gtm_css_parseColorValue( $attributes['line3color'] ) );
gtm_css_compileCssVar( $block_style, "post-date-box-line-3-bg", gtm_css_parseColorValue( $attributes['line3bg'] ) );
}
// Apply to output
$block_style['style'] = ['{{BLOCK}}' => $block_style['style']];
return [
'classes' => array_merge( $output['classes'], $block_style['classes'] ),
'style' => array_replace_recursive( $output['style'], $block_style['style'] ),
];
}