File: /var/www/html/insiders/wp-load/wp-content/plugins/breadly/block-library/post-navigation-link.php
<?php
function gtm_render_block_post_navigation_link( $attr, $content, $block ) {
if ( $attr['type'] == 'next' ) {
$post = get_next_post();
$default_icon = 'gtm-basic-icon-chevron-right';
} else {
$post = get_previous_post();
$default_icon = 'gtm-basic-icon-chevron-left';
}
$block_content = '';
if ( ! empty( $post ) ) {
// Set post context for inner blocks
setup_postdata( $GLOBALS['post'] = &$post ); //phpcs:ignore
if ( ! empty( $attr['enableIcon'] ) ) {
if ( ! empty( $attr['enableIconLink'] ) ) {
$open_tag = sprintf( '<a class="wp-block-gtm-post-navigation-link__icon" href="%1$s" href="%1$s">', esc_url( get_permalink( $post->ID ) ) );
$close_tag = '</a>';
} else {
$open_tag = '<span class="wp-block-gtm-post-navigation-link__icon">';
$close_tag = '</span>';
}
$block_content .= $open_tag;
$block_content .= '<i class="gtm-icon ' . ( ! empty( $attr['icon'] ) ? $attr['icon'] : $default_icon ) . '"></i>';
$block_content .= $close_tag;
}
$block_content .= '<div class="wp-block-gtm-post-navigation-link__post">';
if ( ! empty( $block->parsed_block['innerBlocks'] ) ) {
foreach ( $block->parsed_block['innerBlocks'] as $inner_block ) {
$block_content .= (
new WP_Block(
$inner_block,
[
'postType' => $post->post_type,
'postId' => $post->ID,
]
)
)->render( ['dynamic' => true] );
}
}
$block_content .= '</div>';
$wrapper_attributes = get_block_wrapper_attributes( ['class' => ''] );
// Revert to the current post context
wp_reset_postdata();
return sprintf(
'<div %1$s>%2$s</div>',
$wrapper_attributes,
$block_content
);
}
}
/**
* Registers the `gtm/post-navigation-link` block on the server.
*/
function gtm_register_block_post_navigation_link() {
gtm_register_block_type( 'post-navigation-link', [
'render_callback' => 'gtm_render_block_post_navigation_link',
'skip_inner_blocks' => true,
] );
}
add_action( 'init', 'gtm_register_block_post_navigation_link', 20 );
add_filter( 'gtm.BlockStyleCompiler.gtm/post-navigation-link', 'gtm_compile_block_css_post_navigation_link', 10, 3 );
function gtm_compile_block_css_post_navigation_link( $output, $attributes, $blockName ) {
$block_style = ['classes' => [], 'style' => []];
$block_style['classes'][] = 'gtm-block';
$block_style['classes'][] = "gtm-is-post-navigation-link-type-{$attributes['type']}";
$block_style['classes'][] = "gtm-has-post-navigation-position-{$attributes['iconPosition']}";
if ( $attributes['enableRtlIcon'] ) {
$block_style['classes'][] = 'gtm-is-post-navigation-link-rtl';
}
if ( $attributes['enableIcon'] ) {
gtm_css_compileCssVar( $block_style, "post-navigation-link-icon-padding", gtm_css_parseResponsiveBoxProps( $attributes['iconPadding'] ) );
gtm_css_compileCssVar( $block_style, "post-navigation-link-icon-size", $attributes['iconSize'] );
gtm_css_compileCssVar( $block_style, "post-navigation-link-icon-spacing", gtm_css_parseSpacingValue( $attributes['iconSpacing'] ) );
gtm_css_compileCssVar( $block_style, "post-navigation-link-icon-radius", gtm_css_parseBorderRadiusValue( $attributes['iconRadius'] ) );
gtm_css_compileCssVar( $block_style, "post-navigation-link-icon-color", gtm_css_parseColorValue( $attributes['iconColor'] ) );
gtm_css_compileCssVar( $block_style, "post-navigation-link-icon-bg", gtm_css_parseColorValue( $attributes['iconBg'] ) );
}
// 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'] ),
];
}