Skip to content

Commit 2118888

Browse files
committed
HTML API: Refactor get_post_class() to split CSS class names on whitespace.
1 parent fb2eaf2 commit 2118888

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/wp-includes/post-template.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -496,18 +496,15 @@ function get_post_class( $css_class = '', $post = null ) {
496496

497497
$classes = array();
498498

499-
if ( $css_class ) {
500-
if ( ! is_array( $css_class ) ) {
501-
$css_class = preg_split( '#\s+#', $css_class );
502-
}
503-
$classes = array_map( 'esc_attr', $css_class );
504-
} else {
499+
if ( is_string( $css_class ) ) {
500+
$classes = iterator_to_array( WP_HTML_Tag_Processor::parse_class_list( $css_class ) );
501+
} elseif ( ! is_array( $css_class ) ) {
505502
// Ensure that we always coerce class to being an array.
506-
$css_class = array();
503+
$classes = array();
507504
}
508505

509506
if ( ! $post ) {
510-
return $classes;
507+
return array_map( 'esc_attr', $classes );
511508
}
512509

513510
$classes[] = 'post-' . $post->ID;
@@ -593,8 +590,6 @@ function get_post_class( $css_class = '', $post = null ) {
593590
}
594591
}
595592

596-
$classes = array_map( 'esc_attr', $classes );
597-
598593
/**
599594
* Filters the list of CSS class names for the current post.
600595
*
@@ -606,6 +601,8 @@ function get_post_class( $css_class = '', $post = null ) {
606601
*/
607602
$classes = apply_filters( 'post_class', $classes, $css_class, $post->ID );
608603

604+
$classes = array_map( 'esc_attr', $classes );
605+
609606
return array_unique( $classes );
610607
}
611608

0 commit comments

Comments
 (0)