File: /var/www/html/insiders/wp-load/wp-content/plugins/breadly/block-library/post-date.php
<?php
/**
* Renders the `gtm/post-date` 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( $attr, $content, $block ) {
if ( ! isset( $block->context['postId'] ) ) {
return '';
}
$post_ID = $block->context['postId'];
$the_date = ( $attr['dateType'] ?? '' ) == 'modified' ? get_the_modified_date( 'U' ) : get_the_date( 'U' );
$date = '';
if ( $attr['format'] == 'time_ago' ) {
$date = sprintf( esc_html__( '%s ago', 'gutenmate' ), human_time_diff( $the_date, current_time( 'U' ) ) );
} else {
$date = wp_date( ! empty( $attr['format'] ) ? $attr['format'] : get_option( 'date_format' ), $the_date );
}
$formatted_date = sprintf( '<time datetime="%2$s">%1$s</time>', $date, wp_date( 'c', $the_date ) );
$wrapper_attributes = get_block_wrapper_attributes( ['class' => ''] );
$inner_html = '';
if ( $attr['display'] == 'icon' ) {
$inner_html .= gtm_icon( ! empty( $attr['icon'] ) ? $attr['icon'] : 'date' );
}
if ( ! empty( $attr['label'] ) ) {
$inner_html .= '<span class="wp-block-gtm-post-date__label">' . $attr['label'] . '</span>';
}
if ( empty( $attr['enableLink'] ) ) {
$inner_html .= '<span class="wp-block-gtm-post-date__date wp-block-gtm-post-date__content">' . $formatted_date . '</span>';
} else {
$inner_html .= sprintf( '<a class="wp-block-gtm-post-date__date wp-block-gtm-post-date__content" href="%1$s">%2$s</a>', esc_url( get_the_permalink() ), $formatted_date );
}
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() {
gtm_register_block_type( 'post-date', [
'render_callback' => 'gtm_render_block_post_date',
] );
}
add_action( 'init', 'gtm_register_block_post_date', 20 );
add_filter( 'gtm.BlockStyleCompiler.gtm/post-date', 'gtm_compile_block_css_post_date', 10, 3 );
function gtm_compile_block_css_post_date( $output, $attributes, $blockName ) {
$block_style = ['classes' => [], 'style' => []];
$block_style['classes'][] = 'gtm-block';
if ( $attributes['enableLink'] && $attributes['enableLinkUnderline'] ) {
$block_style['classes'][] = 'gtm-has-post-date-link-underline';
}
if ( $attributes['enableLink'] && $attributes['enableLinkHoverUnderline'] ) {
$block_style['classes'][] = 'gtm-has-post-date-link-hover-underline';
}
//Label
gtm_css_compileCssVar( $block_style, "post-date-label-typography", gtm_css_parseTypographyProps( $attributes['labelTypography'] ) );
gtm_css_compileCssVar( $block_style, "post-date-label-spacing", gtm_css_parseSpacingValue( $attributes['labelSpacing'] ) );
gtm_css_compileCssVar( $block_style, "post-date-label-color", gtm_css_parseColorValue( $attributes['labelColor'] ) );
if ( $attributes['enableLink'] ) {
gtm_css_compileCssVar( $block_style, "post-date-link-color", gtm_css_parseColorValue( $attributes['linkColor'] ) );
gtm_css_compileCssVar( $block_style, "post-date-link-hover-color", gtm_css_parseColorValue( $attributes['linkHoverColor'] ) );
}
if ( $attributes['display'] !== 'name' ) {
gtm_css_compileCssVar( $block_style, "post-date-icon-spacing", gtm_css_parseSpacingValue( $attributes['iconSpacing'] ) );
gtm_css_compileCssVar( $block_style, "post-date-icon-size", $attributes['iconSize'] );
gtm_css_compileCssVar( $block_style, "post-date-icon-width", $attributes['iconWidth'] );
gtm_css_compileCssVar( $block_style, 'post-date-icon-radius', gtm_css_parseBorderRadiusValue( $attributes['iconRadius'] ) );
gtm_css_compileCssVar( $block_style, "post-date-icon-color", gtm_css_parseColorValue( $attributes['iconColor'] ) );
gtm_css_compileCssVar( $block_style, "post-date-icon-bg", gtm_css_parseColorValue( $attributes['iconBg'] ) );
gtm_css_compileCssVar( $block_style, "post-date-icon-hover-color", gtm_css_parseColorValue( $attributes['iconHoverColor'] ) );
gtm_css_compileCssVar( $block_style, "post-date-icon-hover-bg", gtm_css_parseColorValue( $attributes['iconHoverBg'] ) );
}
// 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'] ),
];
}