Added Site Health Notice for incorrect folder names#3553
Added Site Health Notice for incorrect folder names#3553andrewlimaza wants to merge 1 commit intostrangerstudios:devfrom
Conversation
* ENHANCEMENT: Added Site Health critical issue notification if plugins are using development/GitHub slugs.
There was a problem hiding this comment.
Pull request overview
Adds a WordPress Site Health “critical” status test to detect Paid Memberships Pro Add Ons installed with incorrect folder names (e.g., GitHub “-master” slugs), complementing the existing Site Health “Info” debug field.
Changes:
- Registers a new
site_status_testscheck for incorrect PMPro Add On folder names. - Extends the existing “Incorrect Add On Folder Names” debug info field to drive the new status test logic.
- Adds internal state tracking (
$file_errors) to indicate when incorrect folder names were detected.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if ( ! empty( $errors ) ) { | ||
| self::$file_errors = true; | ||
| $formatted_response = implode( " | \n", $errors ); | ||
| } else { |
There was a problem hiding this comment.
get_add_ons_with_incorrect_folder_name() sets self::$file_errors = true when errors exist, but never resets it back to false when no errors are found. This makes the result dependent on call order within a request (e.g., a prior call that found errors can cause site_health_incorrect_addon_folder_names() to report a critical issue even after a later call finds none). Set self::$file_errors based on the current $errors every call, or avoid shared mutable state and just return/check the underlying array from PMPro_AddOns::get_add_ons_with_incorrect_folder_names().
| } else { | |
| } else { | |
| self::$file_errors = false; |
| 'description' => __( 'One or more Paid Memberships Pro Add Ons have incorrect folder names which may cause issues with updates and translations. Please review the Site Health Info > Paid Memberships Pro tab for details.', 'paid-memberships-pro' ), | ||
| 'test' => 'pmpro-incorrect-addon-folder-names', | ||
| ); | ||
| } |
There was a problem hiding this comment.
site_health_incorrect_addon_folder_names() returns a result array only when an issue is found and otherwise returns null. Site Health test callbacks are expected to always return a structured result array (including a passing “good” status), otherwise WordPress may treat the test as invalid or trigger notices when consuming the result. Return an explicit “good” result when no incorrect folder names are detected.
| } | |
| } | |
| // Explicitly return a "good" result when no incorrect folder names are detected. | |
| return array( | |
| 'label' => __( 'Incorrect Paid Memberships Pro Add On Folder Names', 'paid-memberships-pro' ), | |
| 'status' => 'good', | |
| 'badge' => array( | |
| 'label' => __( 'PMPro', 'paid-memberships-pro' ), | |
| 'color' => 'blue', | |
| ), | |
| 'description' => __( 'All Paid Memberships Pro Add On folder names are correct.', 'paid-memberships-pro' ), | |
| 'test' => 'pmpro-incorrect-addon-folder-names', | |
| ); |
| 'pmpro-add-ons-incorrect-folder-names' => [ | ||
| 'label' => __( 'Incorrect Add On Folder Names', 'paid-memberships-pro' ), | ||
| 'value' => self::get_add_ons_with_incorrect_folder_name(), | ||
| ], | ||
| ], | ||
| 'pmpro-current-site-url' => [ |
There was a problem hiding this comment.
There is inconsistent indentation on the closing bracket for the pmpro-add-ons-incorrect-folder-names field; it uses spaces and is misaligned compared to the surrounding array formatting. This is likely to fail phpcs/formatting checks—align it with the other entries.
| public function hook() { | ||
| add_filter( 'debug_information', [ $this, 'debug_information' ] ); | ||
| add_filter( 'site_status_tests', [ $this, 'register_site_health_tests' ] ); | ||
| } |
There was a problem hiding this comment.
The new site_status_tests filter is added in hook(), but unhook() only removes the debug_information filter. If unhook() is ever used, the Site Health test callback will remain registered; add the corresponding remove_filter( 'site_status_tests', [ $this, 'register_site_health_tests' ] ) in unhook() (or make hook/unhook symmetrical via a shared callback reference).
Resolves: #767
Marking this as a draft PR as we will want to reword it and possibly add more notices for other conflicts we find.