File: /var/www/html/insiders/wp-load/wp-content/plugins/gutenmate/block-library/about-author.php
<?php
/**
* Renders the `gtm/about-author` 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_about_author( $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 );
if ( ! empty( $attr['enableAvatar'] ) ) {
$avatar_alt = sprintf( esc_attr__( "Avatar of %s", 'gutenmate' ), get_the_author_meta( 'display_name', $author_id ) );
$inner_html .= '<div class="wp-block-gtm-about-author__avatar-container">';
$inner_html .= get_avatar( $author_id, $attr['avatarSize'], '', $avatar_alt );
$inner_html .= '</div>';
}
$inner_html .= '<div class="wp-block-gtm-about-author__info-container">';
if ( ! empty( $attr['tagline'] ) ) {
$inner_html .= '<div class="wp-block-gtm-about-author__tagline"><span>';
$inner_html .= wp_kses_post( $attr['tagline'] );
$inner_html .= '</span></div>';
}
$inner_html .= '<div class="wp-block-gtm-about-author__name"><span>';
$inner_html .= wp_kses_post( get_the_author_meta( 'display_name', $author_id ) );
$inner_html .= '</span></div>';
if ( ! empty( $attr['enableBio'] ) ) {
$inner_html .= '<div class="wp-block-gtm-about-author__bio">';
$inner_html .= wp_kses_post( get_the_author_meta( 'description', $author_id ) );
$inner_html .= '</div>';
}
if ( ! empty( $attr['enableSocial'] ) ) {
$inner_html .= gtm_author_social_networks( $author_id, ['class' => 'wp-block-gtm-about-author__social-networks'] ); // WPCS: XSS ok.
}
$inner_html .= '</div>';
return sprintf(
'<div %1$s>%2$s</div>',
$wrapper_attributes,
$inner_html
);
}
function gtm_author_social_networks( $author_id, $options = [] ) {
$options = wp_parse_args( $options, [
"class" => "",
] );
$wrapper_class = trim( 'gtm-author-social-networks ' . $options['class'] );
$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 sprintf(
'<div class="%1$s">%2$s</div>',
esc_attr( $wrapper_class ),
$inner_html
);
}
/**
* Registers the `gtm/about-author` block on the server.
*/
function gtm_register_block_about_author() {
gtm_register_block_type( 'about-author', [
'render_callback' => 'gtm_render_block_about_author',
] );
}
add_action( 'init', 'gtm_register_block_about_author', 20 );
add_filter( 'gtm.BlockStyleCompiler.gtm/about-author', 'gtm_compile_block_css_about_author', 10, 3 );
function gtm_compile_block_css_about_author( $output, $attributes, $blockName ) {
$block_style = ['classes' => [], 'style' => []];
$block_style['classes'][] = 'gtm-block';
$block_style['classes'][] = "gtm-has-stacked-layout-{$attributes['layoutStacked']}";
$block_style['classes'][] = "gtm-has-social-display-{$attributes['socialDisplay']}";
/* Avatar */
gtm_css_compileCssVar( $block_style, "about-author-avatar-radius", gtm_css_parseBorderRadiusValue( $attributes['avatarRadius'] ) );
gtm_css_compileCssVar( $block_style, "about-author-avatar-shadow", gtm_css_parseShadowValue( $attributes['avatarShadow'] ) );
gtm_css_compileCssVar( $block_style, "about-author-avatar-spacing", gtm_css_parseSpacingValue( $attributes['avatarSpacing'] ) );
/* Tagline */
gtm_css_compileCssVar( $block_style, "about-author-tagline-typography", gtm_css_parseTypographyProps( $attributes['taglineTypography'] ) );
gtm_css_compileCssVar( $block_style, "about-author-tagline-spacing", gtm_css_parseSpacingValue( $attributes['taglineSpacing'] ) );
gtm_css_compileCssVar( $block_style, "about-author-tagline-color", gtm_css_parseColorValue( $attributes['taglineColor'] ) );
/* Author name */
gtm_css_compileCssVar( $block_style, "about-author-name-typography", gtm_css_parseTypographyProps( $attributes['nameTypography'] ) );
gtm_css_compileCssVar( $block_style, "about-author-name-color", gtm_css_parseColorValue( $attributes['nameColor'] ) );
/* Bio */
if ( $attributes['enableBio'] ) {
gtm_css_compileCssVar( $block_style, "about-author-bio-typography", gtm_css_parseTypographyProps( $attributes['bioTypography'] ) );
gtm_css_compileCssVar( $block_style, "about-author-bio-spacing", gtm_css_parseSpacingValue( $attributes['bioSpacing'] ) );
gtm_css_compileCssVar( $block_style, "about-author-bio-color", gtm_css_parseColorValue( $attributes['bioColor'] ) );
}
/* Social */
if ( $attributes['enableSocial'] ) {
gtm_css_compileCssVar( $block_style, "about-author-social-spacing", gtm_css_parseSpacingValue( $attributes['socialSpacing'] ) );
gtm_css_compileCssVar( $block_style, "about-author-social-link-spacing", gtm_css_parseSpacingValue( $attributes['socialLinkSpacing'] ) );
if ( $attributes['socialDisplay'] === 'icon' ) {
gtm_css_compileCssVar( $block_style, "about-author-social-link-size", $attributes['socialLinkSize'] );
} else {
gtm_css_compileCssVar( $block_style, "about-author-social-link-padding", gtm_css_parseResponsiveBoxProps( $attributes['socialLinkPadding'] ) );
}
gtm_css_compileCssVar( $block_style, "about-author-social-link-radius", gtm_css_parseBorderRadiusValue( $attributes['socialLinkRadius'] ) );
gtm_css_compileCssVar( $block_style, "about-author-social-link-typography", gtm_css_parseTypographyProps( $attributes['socialLinkTypography'] ) );
gtm_css_compileCssVar( $block_style, "about-author-social-link-color", gtm_css_parseColorValue( $attributes['socialLinkColor'] ) );
gtm_css_compileCssVar( $block_style, "about-author-social-link-bg", gtm_css_parseColorValue( $attributes['socialLinkBg'] ) );
gtm_css_compileCssVar( $block_style, "about-author-social-link-hover-color", gtm_css_parseColorValue( $attributes['socialLinkHoverColor'] ) );
gtm_css_compileCssVar( $block_style, "about-author-social-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'] ),
];
}