fix: add check for taxonomy rewrite array in Links class #937
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
When accessing the /wp-admin/ there is a PHP error that can appear:
Warning: Trying to access array offset on value of type bool in /var/www/html/wp-content/plugins/headstartwp/includes/classes/Links.php on line 67The error occurs because:
get_object_taxonomies( $post_type, 'object' )returns taxonomy objects$taxonomy->rewriteset tofalseinstead of an array$taxonomy->rewrite['slug']without checking ifrewriteis an arrayfalseHow to test the Change
delete_option( 'rewrite_rules' )/wp-admin: Should regenerate rules without errorsrewrite => falseandshow_in_rest => true, verify no errorsrewrite => falseandshow_in_rest => true/wp-adminafter clearing rewrite rulesChangelog Entry
Credits
Props @michael-sumner
Checklist:
Note
Add a check to skip taxonomies with non-array or missing
rewrite['slug']when building rewrite rules to avoid PHP warnings.wp/headless-wp/includes/classes/Links.php):create_taxonomy_rewrites, skip taxonomies whenrewriteis not an array orrewrite['slug']is empty, preventing access of array offsets on non-arrays and limiting rule generation to valid taxonomies.Written by Cursor Bugbot for commit 82cf7d6. This will update automatically on new commits. Configure here.