Skip to content

Commit 493668d

Browse files
author
Luciano van der Veekens
committed
Fix bug in the WordPress Customizer preview related to the CSS classes of a menu item
1 parent 26a280a commit 493668d

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

class-wp-bootstrap-navwalker.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0
105105

106106
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
107107

108+
// Updating the CSS classes of a menu item in the WordPress Customizer preview results in all classes defined
109+
// in that particular input box to come in as one big class string.
110+
$split_on_spaces = function ( $class ) {
111+
return preg_split( '/\s+/', $class );
112+
};
113+
$classes = flatten( array_map( $split_on_spaces, $classes ) );
114+
108115
// Initialize some holder variables to store specially handled item
109116
// wrappers and icons.
110117
$linkmod_classes = array();
@@ -552,4 +559,23 @@ private function linkmod_element_close( $linkmod_type ) {
552559
return $output;
553560
}
554561
}
562+
563+
/**
564+
* Flattens a multidimensional array to a simple array.
565+
*
566+
* @param array $array a multidimensional array.
567+
*
568+
* @return array a simple array
569+
*/
570+
function flatten( $array ) {
571+
$result = array();
572+
foreach ( $array as $element ) {
573+
if ( is_array( $element ) ) {
574+
array_push( $result, ...flatten( $element ) );
575+
} else {
576+
$result[] = $element;
577+
}
578+
}
579+
return $result;
580+
}
555581
}

0 commit comments

Comments
 (0)