File: /var/www/html/insiders/wp-load/wp-content/plugins/breadly/block-library/author-socials.php
<?php
/**
* Renders the `gtm/author-socials` 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 featured image for the current post.
*/
function gtm_render_block_author_socials( $attr, $content, $block ) {
if ( ! isset( $block->context['postId'] ) ) {
return '';
}
$wrapper_attributes = get_block_wrapper_attributes( ['class' => ''] );
$inner_html = '';
$post_ID = $block->context['postId'];
$author_id = get_post_field( 'post_author', $post_ID );
$inner_html .= gtm_author_social_networks( $author_id );
if ( $inner_html ) {
return sprintf(
'<div %1$s>%2$s</div>',
$wrapper_attributes,
$inner_html
);
}
}
function gtm_author_social_networks( $author_id ) {
$inner_html = '';
$socials = get_the_author_meta( GTM_USER_SOCIAL_NETWORKS_KEY, $author_id );
if ( ! empty( $socials ) ) {
foreach ( $socials as $social ) {
$link = empty( $social['link'] ) ? "#" : $social['link'];
$class = 'gtm-author-social-network--type-' . sanitize_title( $social['title'] );
$tooltip = sprintf( esc_html__( "Visit %s", 'gutenmate' ), $social['title'] );
$inner_html .= sprintf( '<a class="gtm-author-social-network %1$s" href="%2$s" data-tippy-content="%3$s" aria-label="%3$s">', esc_attr( $class ), esc_url( $link ), esc_attr( $tooltip ) );
if ( ! empty( $social['icon'] ) ) {
$inner_html .= '<span class="gtm-author-social-network__icon">';
$inner_html .= sprintf( '<i class="gtm-icon %1$s"></i>', esc_attr( $social['icon'] ) );
$inner_html .= '</span>';
}
$inner_html .= '<span class="gtm-author-social-network__title">';
$inner_html .= esc_html( $social['title'] );
$inner_html .= '</span>';
$inner_html .= '</a>';
}
}
return $inner_html;
}
/**
* Registers the `gtm/author-socials` block on the server.
*/
function gtm_register_block_author_socials() {
gtm_register_block_type( 'author-socials', [
'render_callback' => 'gtm_render_block_author_socials',
] );
}
add_action( 'init', 'gtm_register_block_author_socials', 20 );
add_filter( 'gtm.BlockStyleCompiler.gtm/author-socials', 'gtm_compile_block_css_author_socials', 10, 3 );
function gtm_compile_block_css_author_socials( $output, $attributes, $blockName ) {
$block_style = ['classes' => [], 'style' => []];
$block_style['classes'][] = 'gtm-block';
$block_style['classes'][] = "gtm-has-social-display-{$attributes['socialDisplay']}";
/* Social */
gtm_css_compileCssVar( $block_style, "author-socials-link-spacing", gtm_css_parseSpacingValue( $attributes['socialLinkSpacing'] ) );
if ( $attributes['socialDisplay'] === 'icon' ) {
gtm_css_compileCssVar( $block_style, "author-socials-link-size", $attributes['socialLinkSize'] );
} else {
gtm_css_compileCssVar( $block_style, "author-socials-link-padding", gtm_css_parseResponsiveBoxProps( $attributes['socialLinkPadding'] ) );
}
gtm_css_compileCssVar( $block_style, "author-socials-link-radius", gtm_css_parseBorderRadiusValue( $attributes['socialLinkRadius'] ) );
gtm_css_compileCssVar( $block_style, "author-socials-link-color", gtm_css_parseColorValue( $attributes['socialLinkColor'] ) );
gtm_css_compileCssVar( $block_style, "author-socials-link-bg", gtm_css_parseColorValue( $attributes['socialLinkBg'] ) );
gtm_css_compileCssVar( $block_style, "author-socials-link-hover-color", gtm_css_parseColorValue( $attributes['socialLinkHoverColor'] ) );
gtm_css_compileCssVar( $block_style, "author-socials-link-hover-bg", gtm_css_parseColorValue( $attributes['socialLinkHoverBg'] ) );
// 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'] ),
];
}