Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple blocks: Add missing has-link-color class to the front #47357

Merged
merged 12 commits into from
Jan 25, 2023
4 changes: 3 additions & 1 deletion packages/block-library/src/calendar/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ function render_block_core_calendar( $attributes ) {
$styles = gutenberg_style_engine_get_styles( array( 'color' => $color_block_styles ), array( 'convert_vars_to_classnames' => true ) );
$inline_styles = empty( $styles['css'] ) ? '' : sprintf( ' style="%s"', esc_attr( $styles['css'] ) );
$classnames = empty( $styles['classnames'] ) ? '' : ' ' . esc_attr( $styles['classnames'] );

if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classnames .= ' has-link-color';
}
// Apply color classes and styles to the calendar.
$calendar = str_replace( '<table', '<table' . $inline_styles, get_calendar( true, false ) );
$calendar = str_replace( 'class="wp-calendar-table', 'class="wp-calendar-table' . $classnames, $calendar );
Expand Down
9 changes: 6 additions & 3 deletions packages/block-library/src/comment-author-name/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ function render_block_core_comment_author_name( $attributes, $content, $block )
return '';
}

$classes = '';
$classes = array();
if ( isset( $attributes['textAlign'] ) ) {
$classes .= 'has-text-align-' . $attributes['textAlign'];
$classes[] = 'has-text-align-' . $attributes['textAlign'];
}
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classes[] = 'has-link-color';
}

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
$comment_author = get_comment_author( $comment );
$link = get_comment_author_url( $comment );

Expand Down
9 changes: 6 additions & 3 deletions packages/block-library/src/comment-content/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ function render_block_core_comment_content( $attributes, $content, $block ) {
}
}

$classes = '';
$classes = array();
if ( isset( $attributes['textAlign'] ) ) {
$classes .= 'has-text-align-' . $attributes['textAlign'];
$classes[] = 'has-text-align-' . $attributes['textAlign'];
}
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classes[] = 'has-link-color';
}

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );

return sprintf(
'<div %1$s>%2$s%3$s</div>',
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/comment-date/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function render_block_core_comment_date( $attributes, $content, $block ) {
return '';
}

$classes = '';
$classes = ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) ? 'has-link-color' : '';

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
$formatted_date = get_comment_date(
Expand Down
9 changes: 6 additions & 3 deletions packages/block-library/src/comment-edit-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ function render_block_core_comment_edit_link( $attributes, $content, $block ) {
$link_atts .= sprintf( 'target="%s"', esc_attr( $attributes['linkTarget'] ) );
}

$classes = '';
$classes = array();
if ( isset( $attributes['textAlign'] ) ) {
$classes .= 'has-text-align-' . $attributes['textAlign'];
$classes[] = 'has-text-align-' . $attributes['textAlign'];
}
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classes[] = 'has-link-color';
}

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );

return sprintf(
'<div %1$s><a href="%2$s" %3$s>%4$s</a></div>',
Expand Down
9 changes: 6 additions & 3 deletions packages/block-library/src/comment-reply-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ function render_block_core_comment_reply_link( $attributes, $content, $block ) {
return;
}

$classes = '';
$classes = array();
if ( isset( $attributes['textAlign'] ) ) {
$classes .= 'has-text-align-' . $attributes['textAlign'];
$classes[] = 'has-text-align-' . $attributes['textAlign'];
}
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classes[] = 'has-link-color';
}

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );

return sprintf(
'<div %1$s>%2$s</div>',
Expand Down
5 changes: 4 additions & 1 deletion packages/block-library/src/comments-pagination/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ function render_block_core_comments_pagination( $attributes, $content ) {
return;
}

$classes = ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) ? 'has-link-color' : '';
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );

return sprintf(
'<div %1$s>%2$s</div>',
get_block_wrapper_attributes(),
$wrapper_attributes,
$content
);
}
Expand Down
19 changes: 9 additions & 10 deletions packages/block-library/src/latest-posts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,25 +173,24 @@ function render_block_core_latest_posts( $attributes ) {

remove_filter( 'excerpt_length', 'block_core_latest_posts_get_excerpt_length', 20 );

$class = 'wp-block-latest-posts__list';

$classes = array( 'wp-block-latest-posts__list' );
if ( isset( $attributes['postLayout'] ) && 'grid' === $attributes['postLayout'] ) {
$class .= ' is-grid';
$classes[] = 'is-grid';
}

if ( isset( $attributes['columns'] ) && 'grid' === $attributes['postLayout'] ) {
$class .= ' columns-' . $attributes['columns'];
$classes[] = 'columns-' . $attributes['columns'];
}

if ( isset( $attributes['displayPostDate'] ) && $attributes['displayPostDate'] ) {
$class .= ' has-dates';
$classes[] = 'has-dates';
}

if ( isset( $attributes['displayAuthor'] ) && $attributes['displayAuthor'] ) {
$class .= ' has-author';
$classes[] = 'has-author';
}
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classes[] = 'has-link-color';
}

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $class ) );
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );

return sprintf(
'<ul %1$s>%2$s</ul>',
Expand Down
13 changes: 9 additions & 4 deletions packages/block-library/src/post-author-name/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ function render_block_core_post_author_name( $attributes, $content, $block ) {
return '';
}

$author_name = get_the_author_meta( 'display_name', $author_id );
$align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";

$author_name = get_the_author_meta( 'display_name', $author_id );
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
$author_name = sprintf( '<a href="%1$s" target="%2$s" class="wp-block-post-author-name__link">%3$s</a>', get_author_posts_url( $author_id ), esc_attr( $attributes['linkTarget'] ), $author_name );
}

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );
$classes = array();
if ( isset( $attributes['textAlign'] ) ) {
$classes[] = 'has-text-align-' . $attributes['textAlign'];
}
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classes[] = 'has-link-color';
}
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );

return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $author_name );
}
Expand Down
14 changes: 10 additions & 4 deletions packages/block-library/src/post-author/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ function render_block_core_post_author( $attributes, $content, $block ) {
}

$byline = ! empty( $attributes['byline'] ) ? $attributes['byline'] : false;
$classes = array_merge(
isset( $attributes['itemsJustification'] ) ? array( 'items-justified-' . $attributes['itemsJustification'] ) : array(),
isset( $attributes['textAlign'] ) ? array( 'has-text-align-' . $attributes['textAlign'] ) : array()
);
$classes = array();
if ( isset( $attributes['itemsJustification'] ) ) {
$classes[] = 'items-justified-' . $attributes['itemsJustification'];
}
if ( isset( $attributes['textAlign'] ) ) {
$classes[] = 'has-text-align-' . $attributes['textAlign'];
}
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classes[] = 'has-link-color';
}

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );

Expand Down
10 changes: 6 additions & 4 deletions packages/block-library/src/post-comments-form/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ function render_block_core_post_comments_form( $attributes, $content, $block ) {
return;
}

$classes = 'comment-respond'; // See comment further below.
$classes = array( 'comment-respond' ); // See comment further below.
if ( isset( $attributes['textAlign'] ) ) {
$classes .= ' has-text-align-' . $attributes['textAlign'];
$classes[] = 'has-text-align-' . $attributes['textAlign'];
}

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classes[] = 'has-link-color';
}
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );

add_filter( 'comment_form_defaults', 'post_comments_form_block_form_defaults' );

Expand Down
10 changes: 8 additions & 2 deletions packages/block-library/src/post-comments-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ function render_block_core_post_comments_link( $attributes, $content, $block ) {
return '';
}

$align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );
$classes = array();
if ( isset( $attributes['textAlign'] ) ) {
$classes[] = 'has-text-align-' . $attributes['textAlign'];
}
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classes[] = 'has-link-color';
}
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
$comments_number = (int) get_comments_number( $block->context['postId'] );
$comments_link = get_comments_link( $block->context['postId'] );
$post_title = get_the_title( $block->context['postId'] );
Expand Down
13 changes: 10 additions & 3 deletions packages/block-library/src/post-date/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ function render_block_core_post_date( $attributes, $content, $block ) {
return '';
}

$post_ID = $block->context['postId'];
$align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );
$post_ID = $block->context['postId'];

$classes = array();
if ( isset( $attributes['textAlign'] ) ) {
$classes[] = 'has-text-align-' . $attributes['textAlign'];
}
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classes[] = 'has-link-color';
}
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );

if ( isset( $attributes['displayType'] ) && 'modified' === $attributes['displayType'] ) {
$formatted_date = get_the_modified_date( empty( $attributes['format'] ) ? '' : $attributes['format'], $post_ID );
Expand Down
9 changes: 6 additions & 3 deletions packages/block-library/src/post-excerpt/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ function render_block_core_post_excerpt( $attributes, $content, $block ) {
* result in showing only one `read more` link at a time.
*/
add_filter( 'excerpt_more', $filter_excerpt_more );
$classes = '';
$classes = array();
if ( isset( $attributes['textAlign'] ) ) {
$classes .= "has-text-align-{$attributes['textAlign']}";
$classes[] = 'has-text-align-' . $attributes['textAlign'];
}
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classes[] = 'has-link-color';
}
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );

$content = '<p class="wp-block-post-excerpt__excerpt">' . $excerpt;
$show_more_on_new_line = ! isset( $attributes['showMoreOnNewLine'] ) || $attributes['showMoreOnNewLine'];
Expand Down
5 changes: 4 additions & 1 deletion packages/block-library/src/post-template/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ function render_block_core_post_template( $attributes, $content, $block ) {
$classnames = "is-flex-container columns-{$block->context['displayLayout']['columns']}";
}
}
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classnames .= ' has-link-color';
}

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classnames ) );
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => trim( $classnames ) ) );

$content = '';
while ( $query->have_posts() ) {
Expand Down
9 changes: 6 additions & 3 deletions packages/block-library/src/post-terms/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ function render_block_core_post_terms( $attributes, $content, $block ) {
return '';
}

$classes = 'taxonomy-' . $attributes['term'];
$classes = array( 'taxonomy-' . $attributes['term'] );
if ( isset( $attributes['textAlign'] ) ) {
$classes .= ' has-text-align-' . $attributes['textAlign'];
$classes[] = 'has-text-align-' . $attributes['textAlign'];
}
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classes[] = 'has-link-color';
}

$separator = empty( $attributes['separator'] ) ? ' ' : $attributes['separator'];

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );

$prefix = "<div $wrapper_attributes>";
if ( isset( $attributes['prefix'] ) && $attributes['prefix'] ) {
Expand Down
14 changes: 10 additions & 4 deletions packages/block-library/src/post-title/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ function render_block_core_post_title( $attributes, $content, $block ) {
return '';
}

$tag_name = 'h2';
$align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";

$tag_name = 'h2';
if ( isset( $attributes['level'] ) ) {
$tag_name = 0 === $attributes['level'] ? 'p' : 'h' . $attributes['level'];
}
Expand All @@ -37,7 +35,15 @@ function render_block_core_post_title( $attributes, $content, $block ) {
$rel = ! empty( $attributes['rel'] ) ? 'rel="' . esc_attr( $attributes['rel'] ) . '"' : '';
$title = sprintf( '<a href="%1$s" target="%2$s" %3$s>%4$s</a>', get_the_permalink( $post_ID ), esc_attr( $attributes['linkTarget'] ), $rel, $title );
}
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );

$classes = array();
if ( isset( $attributes['textAlign'] ) ) {
$classes[] = 'has-text-align-' . $attributes['textAlign'];
}
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classes[] = 'has-link-color';
}
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );

return sprintf(
'<%1$s %2$s>%3$s</%1$s>',
Expand Down
4 changes: 3 additions & 1 deletion packages/block-library/src/query-no-results/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ function render_block_core_query_no_results( $attributes, $content, $block ) {
wp_reset_postdata();
}

$classes = ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) ? 'has-link-color' : '';
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
return sprintf(
'<div %1$s>%2$s</div>',
get_block_wrapper_attributes(),
$wrapper_attributes,
$content
);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/block-library/src/query-pagination/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ function render_block_core_query_pagination( $attributes, $content ) {
return '';
}

$classes = ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) ? 'has-link-color' : '';
$wrapper_attributes = get_block_wrapper_attributes(
array(
'aria-label' => __( 'Pagination' ),
'class' => $classes,
)
);

Expand Down
9 changes: 6 additions & 3 deletions packages/block-library/src/site-title/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ function render_block_core_site_title( $attributes ) {
return;
}

$tag_name = 'h1';
$align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
$tag_name = 'h1';
$classes = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classes .= ' has-link-color';
}

if ( isset( $attributes['level'] ) ) {
$tag_name = 0 === $attributes['level'] ? 'p' : 'h' . (int) $attributes['level'];
Expand All @@ -37,7 +40,7 @@ function render_block_core_site_title( $attributes ) {
esc_html( $site_title )
);
}
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => trim( $classes ) ) );

return sprintf(
'<%1$s %2$s>%3$s</%1$s>',
Expand Down
12 changes: 8 additions & 4 deletions packages/block-library/src/term-description/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ function render_block_core_term_description( $attributes ) {
return '';
}

$extra_attributes = ( isset( $attributes['textAlign'] ) )
? array( 'class' => 'has-text-align-' . $attributes['textAlign'] )
: array();
$wrapper_attributes = get_block_wrapper_attributes( $extra_attributes );
$classes = array();
if ( isset( $attributes['textAlign'] ) ) {
$classes[] = 'has-text-align-' . $attributes['textAlign'];
}
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
$classes[] = 'has-link-color';
}
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );

return '<div ' . $wrapper_attributes . '>' . $term_description . '</div>';
}
Expand Down