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

Add check theme support is an array before indexing #23104

Merged
merged 6 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 18 additions & 24 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,34 +199,28 @@ function gutenberg_experimental_global_styles_get_core() {
function gutenberg_experimental_global_styles_get_theme_presets() {
$theme_presets = array();

$theme_colors = get_theme_support( 'editor-color-palette' )[0];
if ( is_array( $theme_colors ) ) {
foreach ( $theme_colors as $color ) {
$theme_presets['global']['presets']['color'][] = array(
'slug' => $color['slug'],
'value' => $color['color'],
);
}
$theme_colors = gutenberg_experimental_get( get_theme_support( 'editor-color-palette' ), array( '0' ) );
foreach ( $theme_colors as $color ) {
$theme_presets['global']['presets']['color'][] = array(
'slug' => $color['slug'],
'value' => $color['color'],
);
}

$theme_gradients = get_theme_support( 'editor-gradient-presets' )[0];
if ( is_array( $theme_gradients ) ) {
foreach ( $theme_gradients as $gradient ) {
$theme_presets['global']['presets']['gradient'][] = array(
'slug' => $gradient['slug'],
'value' => $gradient['gradient'],
);
}
$theme_gradients = gutenberg_experimental_get( get_theme_support( 'editor-gradient-presets' ), array( '0' ) );
foreach ( $theme_gradients as $gradient ) {
$theme_presets['global']['presets']['gradient'][] = array(
'slug' => $gradient['slug'],
'value' => $gradient['gradient'],
);
}

$theme_font_sizes = get_theme_support( 'editor-font-sizes' )[0];
if ( is_array( $theme_font_sizes ) ) {
foreach ( $theme_font_sizes as $font_size ) {
$theme_presets['global']['presets']['font-size'][] = array(
'slug' => $font_size['slug'],
'value' => $font_size['size'],
);
}
$theme_font_sizes = gutenberg_experimental_get( get_theme_support( 'editor-font-sizes' ), array( '0' ) );
foreach ( $theme_font_sizes as $font_size ) {
$theme_presets['global']['presets']['font-size'][] = array(
'slug' => $font_size['slug'],
'value' => $font_size['size'],
);
}

return $theme_presets;
Expand Down
5 changes: 5 additions & 0 deletions lib/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
* @return array Containing a set of css rules.
*/
function gutenberg_experimental_get( $array, $path ) {
mkaz marked this conversation as resolved.
Show resolved Hide resolved
// Confirm an array is passed in to avoid notice warnings.
if ( ! is_array( $array ) ) {
return array();
}

$path_length = count( $path );
for ( $i = 0; $i < $path_length; ++$i ) {
if ( empty( $array[ $path[ $i ] ] ) ) {
mkaz marked this conversation as resolved.
Show resolved Hide resolved
Expand Down