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

Font Face & Font Library: Load PHP files only if the main class does not exist. #54103

Merged
merged 1 commit into from
Sep 1, 2023

Conversation

hellofromtonya
Copy link
Contributor

What?

Prevents Font Face and Font Library PHP files from loading into memory if each main class already exists in memory (i.e. meaning already in WordPress Core).

Why?

As a fail-safe to avoid Fatal error: Cannot declare class.

In all PRs after Font Face was merged into Core, the PHP 7.0 multisite tests fail:

Fatal error: Cannot declare class WP_Font_Face, because the name is already in use in /var/www/html/wp-content/plugins/gutenberg/lib/compat/wordpress-6.4/fonts/font-face/class-wp-font-face.php on line 19

This change is being made to unblock all PRs.

A follow-up review will happen to investigate why only PHP 7.0 multisite tests fail with this fatal error, while all other PHP versions do not fail. From that follow-up review, recommendations can be made for if this approach should be adopted instead of class_exists guard at the top of each class file.

How?

In the load.php file, it wraps each group of files to only load if its main class does not exist in memory.

Testing Instructions

The PHP 7.0 tests should pass.

@github-actions
Copy link

github-actions bot commented Sep 1, 2023

This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress.

If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged.

If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack.

Thank you! ❤️

View changed files
❔ lib/load.php

@hellofromtonya hellofromtonya added the [Type] Bug An existing feature does not function as intended label Sep 1, 2023
@hellofromtonya hellofromtonya marked this pull request as ready for review September 1, 2023 03:14
@hellofromtonya hellofromtonya removed the request for review from spacedmonkey September 1, 2023 03:14
@hellofromtonya hellofromtonya enabled auto-merge (squash) September 1, 2023 03:15
Copy link
Member

@ramonjd ramonjd 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 looking into this 🙇🏻

@hellofromtonya hellofromtonya merged commit c2d1300 into trunk Sep 1, 2023
@hellofromtonya hellofromtonya deleted the fix/load-files-only-if-class-not-exist branch September 1, 2023 03:46
@github-actions github-actions bot added this to the Gutenberg 16.7 milestone Sep 1, 2023
@mikachan mikachan added the Needs PHP backport Needs PHP backport to Core label Sep 5, 2023
@hellofromtonya hellofromtonya added Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts and removed Needs PHP backport Needs PHP backport to Core labels Sep 6, 2023
@hellofromtonya
Copy link
Contributor Author

Removed Needs PHP backport as this issue relates to only the plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants