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

Missing argument in add_theme_support( 'editor-font-sizes' ) displays PHP warning in WP 5.9 #38768

Open
chthonic-ds opened this issue Feb 12, 2022 · 2 comments · May be fixed by #38769
Open
Assignees
Labels
[Priority] Low Used to indicate that the issue at hand isn't a top priority to address and can be handled later [Type] Enhancement A suggestion for improvement. [Type] WP Core Ticket Requires an upstream change from WordPress. Core Trac ticket should be linked.

Comments

@chthonic-ds
Copy link
Contributor

chthonic-ds commented Feb 12, 2022

Description

Updating to WP 5.9 on a site using a classic theme without a theme.json file, I see the following PHP warning:

Warning: Invalid argument supplied for foreach() in \wp-includes\class-wp-theme-json.php on line 1949

Font sizes for this theme are managed in CSS, so the following theme supports have been set to prevent font size controls being exposed in the editor:

add_theme_support( 'editor-font-sizes' ); // Prevents default font sizes being used.
add_theme_support( 'disable-custom-font-sizes' );

The warning appears because an array is expected as an argument of the editor-font-sizes support:

add_theme_suport( 'editor-font-sizes', array() );

Testing WP prior to 5.9, passing an argument was not previously required to prevent a warning. A google search returns a couple of tutorial-style sites not setting an empty array, suggesting there might be more of this configuration out there.

In this case it's not a problem applying a fix at the theme level, but to help prevent other themes being affected how about performing a check in class-wp-theme-json.php?

Checking an array exists prevents the notice:

if ( isset( $settings['fontSizes'] ) && is_array( $settings['fontSizes'] ) ) { // Line 1946 of class-wp-theme-json.php

Step-by-step reproduction instructions

  1. Add the following to the functions.php of a theme running on WP 5.9:
function yvxasrfazh_disable_editor_font_sizes() {
	add_theme_support( 'editor-font-sizes' );
	add_theme_support( 'disable-custom-font-sizes' );
}

add_action( 'after_setup_theme', 'yvxasrfazh_disable_editor_font_sizes' );
  1. Load the site, observe a PHP warning.
  2. Add an empty array as an argument to the editor-font-sizes support.
  3. Load the site, see the PHP warning has disappeared

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 5.9, any theme

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

chthonic-ds pushed a commit to chthonic-ds/gutenberg that referenced this issue Feb 13, 2022
Checks if value of 'editor-font-sizes' theme support is supplied as an array. Fixes WordPress#38768
@chthonic-ds chthonic-ds changed the title Missing second argument in add_theme_support( 'editor-font-sizes' ) displays PHP warning in WP 5.9 Missing argument in add_theme_support( 'editor-font-sizes' ) displays PHP warning in WP 5.9 Feb 13, 2022
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Feb 13, 2022
@skorasaurus skorasaurus added the [Type] WP Core Ticket Requires an upstream change from WordPress. Core Trac ticket should be linked. label May 10, 2022
@kathrynwp kathrynwp added [Type] Enhancement A suggestion for improvement. [Priority] Low Used to indicate that the issue at hand isn't a top priority to address and can be handled later and removed [Status] In Progress Tracking issues with work in progress labels Jul 20, 2022
@kathrynwp
Copy link

Thanks for the report and the PR!

Noting that I can still replicate this issue with:

WordPress 6.0.1
No plugins active
Theme: Twenty Twenty-One
PHP version 7.3.8

@t-hamano
Copy link
Contributor

Update: I have confirmed that this problem still exists in WordPress 6.1.1, whether or not the latest Gutenberg plugin is enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Priority] Low Used to indicate that the issue at hand isn't a top priority to address and can be handled later [Type] Enhancement A suggestion for improvement. [Type] WP Core Ticket Requires an upstream change from WordPress. Core Trac ticket should be linked.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants