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

theme json boilerplate fix to ensure fontSizes are saved back to the theme #749

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

eirichmond
Copy link
Contributor

related to #707

@matiasbenedetto
Copy link
Contributor

related to #707

Hi @eirichmond ! thanks for adding some rationale in #707 (comment) and submitting this PR.

To make the proposed changes easier to review and test it's always good to provide common answers to 'what', 'why' and 'how' the PR is solving a problem and also provide some 'testing instructions' also.

Copy link
Contributor

@matiasbenedetto matiasbenedetto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing a potential solution. I get your rationale from #707 (comment), but I don't think this change would solve the problem described in #707.

Why?
assets/boilerplate/theme.json is only used to create new blank themes so the change will only impact brand new blank themes, other themes using the default font sizes won't be impacted. Also this is a way to just disable the list of default font sizes for the new blank themes created but not a way to save the changes made to those default font sizes. Apart from that, I think, blank themes are supposed to be the smallest possible, and adding an array of default font sizes doesn't seem in line with that idea.

@eirichmond
Copy link
Contributor Author

eirichmond commented Nov 27, 2024

@matiasbenedetto I appreciate the feedback but it's worth noting that #707 specifically refers to creating a blank theme, and this solution would only impact that particular scenario if the boilerplate is only used to create a new blank theme.

Create a blank theme.
Edit the default font size presets.
Save changes to the theme.

You will see that the edited font sizes are not present in the resulting theme.json file, and the default font sizes are reset to the Core defaults.

It was also stated that this approach "is just a way to disable the list of default font sizes for new blank themes created, but not a way to save the changes made to those default font sizes."

This is not true. The proposed boilerplate change ensures that:
A) defaultFontSizes is disabled.
B) The default font sizes from Core are replicated, making them editable via Global Styles.
C) Changes made via Global Styles and saved to the database are not removed when saving back to the theme.json file via the plugin. This directly addresses and fixes the bug mentioned in #707.

By reproducing the steps outlined in the original issue, you’ll find that this approach resolves the problem.

As for other themes, it’s worth noting that if defaultFontSizes is set to true by default, the fontSizes configuration isn’t implemented in the same way as described in #707. This distinction is important, as the issue specifically pertains to blank themes created via the plugin and the associated workflow.

@eirichmond
Copy link
Contributor Author

To further add to the discussion, I’m not sure how this could logically work without first changing the boilerplate to include defaultFontSizes: false if you wanted to save the Global Styles font settings back to the theme. Currently, the process behaves like this after the user clicks Save to Theme:

  1. Theme is loaded:
    The theme.json file from the new blank theme (or the current theme) is loaded. In the case of a blank theme boilerplate, defaultFontSizes: false is not set, so it defaults to defaultFontSizes: true. Additionally, fontSizes is not defined in the theme boilerplate.

  2. Default settings are loaded:
    The default theme settings from Core are loaded, which include defaultFontSizes: true and the default fontSizes.

  3. Default fontSizes are applied:
    The default fontSizes are added to the theme’s fontSizes (which is empty at this stage) in what appears to be a recursive process.

  4. Database user styles are cleared:
    The user’s Global Styles settings from the database are wiped.

As a result:

  • The theme.json in the theme ends up with an empty fontSizes array.

  • The database user styles for font sizes are cleared.

  • The Global Styles font size presets revert to the default Core fontSizes.

This makes it clear that without defaultFontSizes: false explicitly set and predefined fontSizes included first, the behavior will always revert to the Core defaults, making it impossible to preserve changes made in Global Styles.

@eirichmond
Copy link
Contributor Author

@matiasbenedetto, perhaps this is a better fix in my last push.

What this fixes: When the Typography > Font Size preset is changed via Global Styles and then saved back to the database, the changes are not reflected in the theme when "Save Changes to Theme" is used.

Why this fix: This improves the theme development workflow. When changes are made via Global Styles and "Save Changes to Theme" is used, any font size presets should be respected and applied.

How it's fixed: Before the data is stringified, a new function, font_size_preset_changes, runs the data through a method of the parent class to check if any font sizes have been added to the database. Rather than saving the merged data with an empty fontSizes reference, the data from the database is used before it is cleared and applied to the theme.json file. Additionally, defaultFontSizes is set to false to ensure the font sizes are respected from the theme rather than the core.

@eirichmond eirichmond changed the title theme json boilerplace fix to ensure fontsizes are saved back the theme theme json boilerplate fix to ensure fontsizes are saved back the theme Dec 2, 2024
@eirichmond eirichmond changed the title theme json boilerplate fix to ensure fontsizes are saved back the theme theme json boilerplate fix to ensure fontSizes are saved back the theme Dec 2, 2024
@eirichmond eirichmond changed the title theme json boilerplate fix to ensure fontSizes are saved back the theme theme json boilerplate fix to ensure fontSizes are saved back to the theme Dec 2, 2024
Copy link
Contributor Author

@eirichmond eirichmond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments added to explain the changes in more detail.

// move Font size preset settings from 'default' to 'theme' to ensure
// any changes made via Global Styles are saved back to the theme
$data = static::font_size_preset_changes( $data );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the initial function to start the check and change the $data variable

}
}
return $data;
}
/**
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function that gets and user data and then uses the parent class method if it exists to access data that is private, then checks if fontSizes is set then appends the settings needs to write to the theme.json file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants