', esc_attr( $classes ) ) . '
' . get_the_excerpt( $block->context['postId'] );
diff --git a/packages/block-library/src/post-tags/index.php b/packages/block-library/src/post-tags/index.php
index f6ff4b075ae21c..6558eded3dad0d 100644
--- a/packages/block-library/src/post-tags/index.php
+++ b/packages/block-library/src/post-tags/index.php
@@ -20,9 +20,9 @@ function render_block_core_post_tags( $attributes, $content, $block ) {
$post_tags = get_the_tags( $block->context['postId'] );
if ( ! empty( $post_tags ) ) {
- $classes = 'wp-block-post-tags';
+ $classes = '';
if ( isset( $attributes['textAlign'] ) ) {
- $classes .= ' has-text-align-' . $attributes['textAlign'];
+ $classes .= 'has-text-align-' . $attributes['textAlign'];
}
$output = sprintf( '
', esc_attr( $classes ) );
diff --git a/packages/block-library/src/post-title/index.php b/packages/block-library/src/post-title/index.php
index 2f5b7535c91c6e..66f8161e24c3fa 100644
--- a/packages/block-library/src/post-title/index.php
+++ b/packages/block-library/src/post-title/index.php
@@ -20,7 +20,7 @@ function render_block_core_post_title( $attributes, $content, $block ) {
}
$tag_name = 'h2';
- $align_class_name = empty( $attributes['textAlign'] ) ? '' : ' ' . "has-text-align-{$attributes['textAlign']}";
+ $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
if ( isset( $attributes['level'] ) ) {
$tag_name = 0 === $attributes['level'] ? 'p' : 'h' . $attributes['level'];
@@ -29,7 +29,7 @@ function render_block_core_post_title( $attributes, $content, $block ) {
return sprintf(
'<%1$s class="%2$s">%3$s%1$s>',
$tag_name,
- 'wp-block-post-title' . esc_attr( $align_class_name ),
+ esc_attr( $align_class_name ),
get_the_title( $block->context['postId'] )
);
}
diff --git a/packages/block-library/src/rss/index.php b/packages/block-library/src/rss/index.php
index 6c8792aa448d66..a3dbd0d431d02f 100644
--- a/packages/block-library/src/rss/index.php
+++ b/packages/block-library/src/rss/index.php
@@ -79,16 +79,16 @@ function render_block_core_rss( $attributes ) {
$list_items .= "";
}
- $class = 'wp-block-rss';
+ $classnames = array();
if ( isset( $attributes['blockLayout'] ) && 'grid' === $attributes['blockLayout'] ) {
- $class .= ' is-grid';
+ $classnames[] = 'is-grid';
}
if ( isset( $attributes['columns'] ) && 'grid' === $attributes['blockLayout'] ) {
- $class .= ' columns-' . $attributes['columns'];
+ $classnames[] = 'columns-' . $attributes['columns'];
}
- return sprintf( '
', esc_attr( $class ), $list_items );
+ return sprintf( '
', esc_attr( implode( ' ', $classnames ) ), $list_items );
}
/**
diff --git a/packages/block-library/src/search/index.php b/packages/block-library/src/search/index.php
index 7a224fa2eed3da..d1f7e84d2d915d 100644
--- a/packages/block-library/src/search/index.php
+++ b/packages/block-library/src/search/index.php
@@ -59,11 +59,8 @@ function render_block_core_search( $attributes ) {
);
}
- $class = 'wp-block-search';
-
return sprintf(
- '
',
- esc_attr( $class ),
+ '
',
esc_url( home_url( '/' ) ),
$label_markup . $input_markup . $button_markup
);
diff --git a/packages/block-library/src/site-logo/index.php b/packages/block-library/src/site-logo/index.php
index 66b3a84023af20..d0d8e7b4be2c31 100644
--- a/packages/block-library/src/site-logo/index.php
+++ b/packages/block-library/src/site-logo/index.php
@@ -23,16 +23,17 @@ function render_block_core_site_logo( $attributes ) {
add_filter( 'wp_get_attachment_image_src', $adjust_width_height_filter );
$custom_logo = get_custom_logo();
- $class_name = 'wp-block-site-logo';
+ $classnames = array();
if ( ! empty( $attributes['className'] ) ) {
- $class_name .= " {$attributes['className']}";
+ $classnames[] = $attributes['className'];
}
if ( ! empty( $attributes['align'] ) && in_array( $attributes['align'], array( 'center', 'left', 'right' ), true ) ) {
- $class_name .= " align{$attributes['align']}";
+ $classnames[] = "align{$attributes['align']}";
}
- $html = sprintf( '
', $class_name, $custom_logo );
+ $class_name = implode( ' ', $classnames );
+ $html = sprintf( '
', $class_name, $custom_logo );
remove_filter( 'wp_get_attachment_image_src', $adjust_width_height_filter );
return $html;
}
diff --git a/packages/block-library/src/site-tagline/index.php b/packages/block-library/src/site-tagline/index.php
index b450c1626adde8..39df38bec38501 100644
--- a/packages/block-library/src/site-tagline/index.php
+++ b/packages/block-library/src/site-tagline/index.php
@@ -13,11 +13,11 @@
* @return string The render.
*/
function render_block_core_site_tagline( $attributes ) {
- $align_class_name = empty( $attributes['textAlign'] ) ? '' : ' ' . "has-text-align-{$attributes['textAlign']}";
+ $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
return sprintf(
'
%2$s
',
- 'wp-block-site-tagline' . esc_attr( $align_class_name ),
+ esc_attr( $align_class_name ),
get_bloginfo( 'description' )
);
}
diff --git a/packages/block-library/src/site-title/index.php b/packages/block-library/src/site-title/index.php
index 67baf2bc64dfd6..6f0ef7cd3d57f2 100644
--- a/packages/block-library/src/site-title/index.php
+++ b/packages/block-library/src/site-title/index.php
@@ -14,7 +14,7 @@
*/
function render_block_core_site_title( $attributes ) {
$tag_name = 'h1';
- $align_class_name = empty( $attributes['textAlign'] ) ? '' : ' ' . "has-text-align-{$attributes['textAlign']}";
+ $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
if ( isset( $attributes['level'] ) ) {
$tag_name = 0 === $attributes['level'] ? 'p' : 'h' . $attributes['level'];
@@ -23,7 +23,7 @@ function render_block_core_site_title( $attributes ) {
return sprintf(
'<%1$s class="%2$s">%3$s%1$s>',
$tag_name,
- 'wp-block-site-title' . esc_attr( $align_class_name ),
+ esc_attr( $align_class_name ),
get_bloginfo( 'name' )
);
}
diff --git a/packages/block-library/src/tag-cloud/index.php b/packages/block-library/src/tag-cloud/index.php
index 667c09a325651f..f417b786c45941 100644
--- a/packages/block-library/src/tag-cloud/index.php
+++ b/packages/block-library/src/tag-cloud/index.php
@@ -13,13 +13,11 @@
* @return string Returns the tag cloud for selected taxonomy.
*/
function render_block_core_tag_cloud( $attributes ) {
- $class = 'wp-block-tag-cloud';
- $args = array(
+ $args = array(
'echo' => false,
'taxonomy' => $attributes['taxonomy'],
'show_count' => $attributes['showTagCounts'],
);
-
$tag_cloud = wp_tag_cloud( $args );
if ( ! $tag_cloud ) {
@@ -34,8 +32,7 @@ function render_block_core_tag_cloud( $attributes ) {
}
return sprintf(
- '
%2$s
',
- esc_attr( $class ),
+ '
%1$s
',
$tag_cloud
);
}
diff --git a/packages/block-library/src/template-part/index.php b/packages/block-library/src/template-part/index.php
index 82ba837fc4594e..27a08594eaca41 100644
--- a/packages/block-library/src/template-part/index.php
+++ b/packages/block-library/src/template-part/index.php
@@ -63,7 +63,7 @@ function render_block_core_template_part( $attributes ) {
}
$content = do_shortcode( $content );
- return '
' . str_replace( ']]>', ']]>', $content ) . '
';
+ return '
' . str_replace( ']]>', ']]>', $content ) . '
';
}
/**
diff --git a/phpunit/class-block-supported-styles-test.php b/phpunit/class-block-supported-styles-test.php
index 80dfd61b0c93db..77c1225074c37f 100644
--- a/phpunit/class-block-supported-styles-test.php
+++ b/phpunit/class-block-supported-styles-test.php
@@ -124,7 +124,7 @@ private function assert_content_and_styles_and_classes_match( $block, $expected_
*
* @var string
*/
- const BLOCK_MARKUP = '
' . self::BLOCK_CONTENT . '
';
+ const BLOCK_MARKUP = '
' . self::BLOCK_CONTENT . '
';
/**
* Tests color support for named color support for named colors.
@@ -152,7 +152,7 @@ function test_named_color_support() {
'innerHTML' => array(),
);
- $expected_classes = 'wp-block-example foo-bar-class has-text-color has-red-color has-background has-black-background-color';
+ $expected_classes = 'foo-bar-class wp-block-example has-text-color has-red-color has-background has-black-background-color';
$expected_styles = 'test: style;';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
@@ -190,7 +190,7 @@ function test_custom_color_support() {
);
$expected_styles = 'test: style; color: #000; background-color: #fff;';
- $expected_classes = 'wp-block-example foo-bar-class has-text-color has-background';
+ $expected_classes = 'foo-bar-class wp-block-example has-text-color has-background';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
}
@@ -220,7 +220,7 @@ function test_named_link_color_support() {
'innerHTML' => array(),
);
- $expected_classes = 'wp-block-example foo-bar-class has-link-color';
+ $expected_classes = 'foo-bar-class wp-block-example has-link-color';
$expected_styles = 'test: style; --wp--style--color--link: var(--wp--preset--color--red);';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
@@ -251,7 +251,7 @@ function test_custom_link_color_support() {
'innerHTML' => array(),
);
- $expected_classes = 'wp-block-example foo-bar-class has-link-color';
+ $expected_classes = 'foo-bar-class wp-block-example has-link-color';
$expected_styles = 'test: style; --wp--style--color--link: #fff;';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
@@ -282,7 +282,7 @@ function test_named_gradient_support() {
'innerHTML' => array(),
);
- $expected_classes = 'wp-block-example foo-bar-class has-background has-red-gradient-background';
+ $expected_classes = 'foo-bar-class wp-block-example has-background has-red-gradient-background';
$expected_styles = 'test: style;';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
@@ -313,7 +313,7 @@ function test_custom_gradient_support() {
'innerHTML' => array(),
);
- $expected_classes = 'wp-block-example foo-bar-class has-background';
+ $expected_classes = 'foo-bar-class wp-block-example has-background';
$expected_styles = 'test: style; background: some-gradient-style;';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
@@ -349,8 +349,8 @@ function test_color_unsupported() {
'innerHTML' => array(),
);
- $expected_classes = 'wp-block-example foo-bar-class';
- $expected_styles = 'test:style;';
+ $expected_classes = 'foo-bar-class wp-block-example';
+ $expected_styles = 'test: style;';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
}
@@ -378,7 +378,7 @@ function test_named_font_size() {
'innerHTML' => array(),
);
- $expected_classes = 'wp-block-example foo-bar-class has-large-font-size';
+ $expected_classes = 'foo-bar-class wp-block-example has-large-font-size';
$expected_styles = 'test: style;';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
@@ -407,7 +407,7 @@ function test_custom_font_size() {
'innerHTML' => array(),
);
- $expected_classes = 'wp-block-example foo-bar-class';
+ $expected_classes = 'foo-bar-class wp-block-example';
$expected_styles = 'test: style; font-size: 10px;';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
@@ -435,8 +435,8 @@ function test_font_size_unsupported() {
'innerHTML' => array(),
);
- $expected_classes = 'wp-block-example foo-bar-class';
- $expected_styles = 'test:style;';
+ $expected_classes = 'foo-bar-class wp-block-example';
+ $expected_styles = 'test: style;';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
}
@@ -464,7 +464,7 @@ function test_line_height() {
'innerHTML' => array(),
);
- $expected_classes = 'wp-block-example foo-bar-class';
+ $expected_classes = 'foo-bar-class wp-block-example';
$expected_styles = 'test: style; line-height: 10;';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
@@ -491,8 +491,8 @@ function test_line_height_unsupported() {
'innerHTML' => array(),
);
- $expected_classes = 'wp-block-example foo-bar-class';
- $expected_styles = 'test:style;';
+ $expected_classes = 'foo-bar-class wp-block-example';
+ $expected_styles = 'test: style;';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
}
@@ -520,7 +520,7 @@ function test_block_alignment() {
'innerHTML' => array(),
);
- $expected_classes = 'wp-block-example foo-bar-class alignwide';
+ $expected_classes = 'foo-bar-class wp-block-example alignwide';
$expected_styles = 'test: style;';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
@@ -547,8 +547,8 @@ function test_block_alignment_unsupported() {
'innerHTML' => array(),
);
- $expected_classes = 'wp-block-example foo-bar-class';
- $expected_styles = 'test:style;';
+ $expected_classes = 'foo-bar-class wp-block-example';
+ $expected_styles = 'test: style;';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
}
@@ -594,7 +594,7 @@ function test_all_supported() {
'innerHTML' => array(),
);
- $expected_classes = 'wp-block-example foo-bar-class has-text-color has-background alignwide';
+ $expected_classes = 'foo-bar-class wp-block-example has-text-color has-background alignwide';
$expected_styles = 'test: style; color: #000; background-color: #fff; background: some-gradient; font-size: 10px; line-height: 20;';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
@@ -636,7 +636,7 @@ function test_one_supported() {
'innerHTML' => array(),
);
- $expected_classes = 'wp-block-example foo-bar-class';
+ $expected_classes = 'foo-bar-class wp-block-example';
$expected_styles = 'test: style; font-size: 10px;';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
@@ -682,7 +682,7 @@ function test_render_callback_required() {
'innerHTML' => array(),
);
- $expected_classes = 'wp-block-example foo-bar-class';
+ $expected_classes = 'foo-bar-class';
$expected_styles = 'test:style;';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
@@ -709,8 +709,8 @@ function test_custom_classnames_support() {
'innerHTML' => array(),
);
- $expected_styles = 'test:style; ';
- $expected_classes = 'wp-block-example foo-bar-class my-custom-classname';
+ $expected_styles = 'test: style;';
+ $expected_classes = 'foo-bar-class wp-block-example my-custom-classname';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
}
@@ -738,8 +738,35 @@ function test_custom_classnames_support_opt_out() {
'innerHTML' => array(),
);
+ $expected_styles = 'test: style;';
+ $expected_classes = 'foo-bar-class wp-block-example';
+
+ $this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
+ }
+
+ /**
+ * Tests generated classname server-side block support opt-out.
+ */
+ function test_generatted_classnames_support_opt_out() {
+ $block_type_settings = array(
+ 'attributes' => array(),
+ 'supports' => array(
+ 'className' => false,
+ ),
+ 'render_callback' => true,
+ );
+ $this->register_block_type( 'core/example', $block_type_settings );
+
+ $block = array(
+ 'blockName' => 'core/example',
+ 'attrs' => array(),
+ 'innerBlock' => array(),
+ 'innerContent' => array(),
+ 'innerHTML' => array(),
+ );
+
$expected_styles = 'test:style;';
- $expected_classes = 'wp-block-example foo-bar-class';
+ $expected_classes = 'foo-bar-class';
$this->assert_content_and_styles_and_classes_match( $block, $expected_classes, $expected_styles );
}