Skip to content

Commit 1070ce3

Browse files
authored
Merge pull request #410 from lucianovdveekens/fix-wp-customizer-preview
Fix bug in the WordPress Customizer preview related to the CSS classes
2 parents c7abf4a + e63974c commit 1070ce3

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

class-wp-bootstrap-navwalker.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ public function start_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) {
127127

128128
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
129129

130+
// Updating the CSS classes of a menu item in the WordPress Customizer preview results in all classes defined
131+
// in that particular input box to come in as one big class string.
132+
$split_on_spaces = function ( $class ) {
133+
return preg_split( '/\s+/', $class );
134+
};
135+
$classes = flatten( array_map( $split_on_spaces, $classes ) );
136+
130137
/*
131138
* Initialize some holder variables to store specially handled item
132139
* wrappers and icons.
@@ -576,4 +583,25 @@ private function linkmod_element_close( $linkmod_type ) {
576583
return $output;
577584
}
578585
}
586+
587+
/**
588+
* Flattens a multidimensional array to a simple array.
589+
*
590+
* @param array $array a multidimensional array.
591+
*
592+
* @return array a simple array
593+
*/
594+
public function flatten( $array ) {
595+
$result = array();
596+
foreach ( $array as $element ) {
597+
if ( is_array( $element ) ) {
598+
array_push( $result, ...flatten( $element ) );
599+
} else {
600+
$result[] = $element;
601+
}
602+
}
603+
return $result;
604+
}
605+
579606
endif;
607+

0 commit comments

Comments
 (0)