Skip to content

Commit

Permalink
Social icons: only render label container when there's a label (#60060)
Browse files Browse the repository at this point in the history
* Use the default label in the `wp-block-social-link-label` span if there is no label content.
* Setting label attribute to `undefined` not empty string, as it will pass `isset` PHP checks.
* Removed unnecessary parentheses


Co-authored-by: ramonjd <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: afercia <[email protected]>
  • Loading branch information
4 people authored Mar 21, 2024
1 parent 74a06c7 commit f940341
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/block-library/src/social-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const SocialLinkEdit = ( {
) }
value={ label || '' }
onChange={ ( value ) =>
setAttributes( { label: value } )
setAttributes( { label: value || undefined } )
}
/>
</PanelRow>
Expand Down
13 changes: 6 additions & 7 deletions packages/block-library/src/social-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
function render_block_core_social_link( $attributes, $content, $block ) {
$open_in_new_tab = isset( $block->context['openInNewTab'] ) ? $block->context['openInNewTab'] : false;

$service = ( isset( $attributes['service'] ) ) ? $attributes['service'] : 'Icon';
$url = ( isset( $attributes['url'] ) ) ? $attributes['url'] : false;
$label = ( isset( $attributes['label'] ) ) ? $attributes['label'] : block_core_social_link_get_name( $service );
$rel = ( isset( $attributes['rel'] ) ) ? $attributes['rel'] : '';
$service = isset( $attributes['service'] ) ? $attributes['service'] : 'Icon';
$url = isset( $attributes['url'] ) ? $attributes['url'] : false;
$label = ! empty( $attributes['label'] ) ? $attributes['label'] : block_core_social_link_get_name( $service );
$rel = isset( $attributes['rel'] ) ? $attributes['rel'] : '';
$show_labels = array_key_exists( 'showLabels', $block->context ) ? $block->context['showLabels'] : false;

// Don't render a link if there is no URL set.
Expand Down Expand Up @@ -57,9 +57,8 @@ function render_block_core_social_link( $attributes, $content, $block ) {
$link = '<li ' . $wrapper_attributes . '>';
$link .= '<a href="' . esc_url( $url ) . '" class="wp-block-social-link-anchor">';
$link .= $icon;
$link .= '<span class="wp-block-social-link-label' . ( $show_labels ? '' : ' screen-reader-text' ) . '">';
$link .= esc_html( $label );
$link .= '</span></a></li>';
$link .= '<span class="wp-block-social-link-label' . ( $show_labels ? '' : ' screen-reader-text' ) . '">' . esc_html( $label ) . '</span>';
$link .= '</a></li>';

$processor = new WP_HTML_Tag_Processor( $link );
$processor->next_tag( 'a' );
Expand Down

0 comments on commit f940341

Please sign in to comment.