-
Notifications
You must be signed in to change notification settings - Fork 842
Add autoloader checks to prevent fatal errors on incomplete installations #46489
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
base: trunk
Are you sure you want to change the base?
Conversation
…ions Adds is_readable() checks around autoloader require statements in four plugins to prevent fatal errors when plugins are activated before composer install has been run. Each check includes: - Debug logging when WP_DEBUG is enabled - Admin notice on the plugins page with setup instructions - Inline documentation explaining the purpose of the check Affected plugins: - classic-theme-helper-plugin (also fixes missing autoloader load) - mu-wpcom-plugin - wpcloud-sso - wpcomsh
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. Mu Wpcom plugin:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. Wpcomsh plugin:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. Classic Theme helper plugin plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. Wpcloud Sso plugin: No scheduled milestone found for this plugin. If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 2 files.
Full summary · PHP report · JS report Coverage check overridden by
I don't care about code coverage for this PR
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds defensive autoloader checks to four plugins to prevent fatal errors when plugins are activated before composer install has been run during development. The PR also fixes a bug in classic-theme-helper-plugin where the autoloader was never being loaded, and adds a missing jetpack-blocks dependency to the classic-theme-helper package.
Key changes:
- Wraps autoloader
requirestatements inis_readable()checks for graceful degradation - Adds developer-friendly admin notices with links to setup documentation
- Fixes autoloader loading bug in classic-theme-helper-plugin
Reviewed changes
Copilot reviewed 12 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| projects/plugins/wpcomsh/wpcomsh.php | Adds autoloader check with error logging and admin notice for missing composer dependencies |
| projects/plugins/wpcloud-sso/jetpack-wpcloud-sso.php | Adds autoloader check with error logging and admin notice for missing composer dependencies |
| projects/plugins/mu-wpcom-plugin/mu-wpcom-plugin.php | Adds autoloader check with error logging and admin notice for missing composer dependencies |
| projects/plugins/classic-theme-helper-plugin/classic-theme-helper-plugin.php | Adds autoloader check and fixes bug where autoloader was never loaded |
| projects/packages/classic-theme-helper/composer.json | Adds missing jetpack-blocks dependency |
| projects/plugins/wpcomsh/composer.lock | Updates classic-theme-helper reference and adds jetpack-blocks dependency |
| projects/plugins/mu-wpcom-plugin/composer.lock | Updates classic-theme-helper reference and adds jetpack-blocks dependency |
| projects/plugins/jetpack/composer.lock | Updates classic-theme-helper reference and adds jetpack-blocks dependency |
| projects/plugins/classic-theme-helper-plugin/composer.lock | Adds jetpack-blocks package dependency |
| projects/packages/classic-theme-helper/.phan/baseline.php | Updates Phan baseline after dependency addition resolved undeclared class method issues |
| projects/plugins/wpcomsh/changelog/fix-plugin-autoloader-checks | Documents the autoloader check addition |
| projects/plugins/wpcloud-sso/changelog/fix-plugin-autoloader-checks | Documents the autoloader check addition |
| projects/plugins/mu-wpcom-plugin/changelog/fix-plugin-autoloader-checks | Documents the autoloader check addition |
| projects/plugins/classic-theme-helper-plugin/changelog/fix-plugin-autoloader-checks | Documents the autoloader check and bug fix |
| projects/plugins/jetpack/changelog/fix-plugin-autoloader-checks | Documents the package dependency update |
| projects/packages/classic-theme-helper/changelog/fix-plugin-autoloader-checks | Documents the missing dependency addition |
| if ( get_current_screen()->id !== 'plugins' ) { | ||
| return; | ||
| } | ||
|
|
Copilot
AI
Jan 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The get_current_screen() function may not be available or could return null when the admin_notices hook fires. This could cause a fatal error. Add a check to ensure get_current_screen() is available and returns a valid value before accessing its properties.
| if ( get_current_screen()->id !== 'plugins' ) { | |
| return; | |
| } | |
| if ( ! function_exists( 'get_current_screen' ) ) { | |
| return; | |
| } | |
| $screen = get_current_screen(); | |
| if ( ! $screen || empty( $screen->id ) || 'plugins' !== $screen->id ) { | |
| return; | |
| } |
| if ( get_current_screen()->id !== 'plugins' ) { | ||
| return; | ||
| } | ||
|
|
Copilot
AI
Jan 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The get_current_screen() function may not be available or could return null when the admin_notices hook fires. This could cause a fatal error. Add a check to ensure get_current_screen() is available and returns a valid value before accessing its properties.
| if ( get_current_screen()->id !== 'plugins' ) { | |
| return; | |
| } | |
| if ( ! function_exists( 'get_current_screen' ) ) { | |
| return; | |
| } | |
| $screen = get_current_screen(); | |
| if ( ! $screen || empty( $screen->id ) || 'plugins' !== $screen->id ) { | |
| return; | |
| } |
| if ( get_current_screen()->id !== 'plugins' ) { | ||
| return; | ||
| } | ||
|
|
Copilot
AI
Jan 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The get_current_screen() function may not be available or could return null when the admin_notices hook fires. This could cause a fatal error. Add a check to ensure get_current_screen() is available and returns a valid value before accessing its properties.
| if ( get_current_screen()->id !== 'plugins' ) { | |
| return; | |
| } | |
| if ( ! function_exists( 'get_current_screen' ) ) { | |
| return; | |
| } | |
| $screen = get_current_screen(); | |
| if ( ! $screen || ! isset( $screen->id ) || $screen->id !== 'plugins' ) { | |
| return; | |
| } |
| add_action( | ||
| 'admin_notices', | ||
| function () { | ||
| if ( get_current_screen()->id !== 'plugins' ) { |
Copilot
AI
Jan 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The get_current_screen() function may not be available or could return null when the admin_notices hook fires. This could cause a fatal error. Add a check to ensure get_current_screen() is available and returns a valid value before accessing its properties.
| if ( get_current_screen()->id !== 'plugins' ) { | |
| $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; | |
| if ( ! $screen || ! isset( $screen->id ) || $screen->id !== 'plugins' ) { |
| } else { | ||
| if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { | ||
| error_log( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log | ||
| __( 'Error loading autoloader file for Classic Theme Helper Plugin plugin', 'classic-theme-helper-plugin' ) |
Copilot
AI
Jan 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message contains redundant wording: "Classic Theme Helper Plugin plugin" should be "Classic Theme Helper Plugin" (remove the duplicate "plugin" word).
| __( 'Error loading autoloader file for Classic Theme Helper Plugin plugin', 'classic-theme-helper-plugin' ) | |
| __( 'Error loading autoloader file for Classic Theme Helper Plugin', 'classic-theme-helper-plugin' ) |
Supports #46490 —
wp-envwill execute the plugin, so if starting upwp-envwithout havingcomposer installto create an autoloader in a plugin, it'll fatal and exit. This would allow that and other times where someone activates a dev-uninstalled/built version of a plugin on a site.Proposed changes:
Adds
is_readable()checks around autoloader require statements in four plugins to prevent fatal errors when plugins are activated beforecomposer installhas been run.Affected plugins:
classic-theme-helper-plugin— Also fixes a bug where the autoloader was never being loadedmu-wpcom-pluginwpcloud-ssowpcomshEach check includes:
WP_DEBUGis enabledOther information:
Jetpack product discussion
N/A — Internal developer experience improvement
Does this pull request change what data or activity we track or use?
No
Testing instructions:
composer installfirst