Decouple primary term second round
Context
- While decoupling the hidden fields from the metabox, we needed to have the
show_in_restas positive when registering the meta. That is done in the wpseo meta class. However, the primary terms meta is not added to the hidden fields from the$meta_fields. I added the primary terms in the init function of the wpseo meta class. After further examination we saw that registering the meta fields is done in a specific time and we want to be more flexable for taxonomies that are being registered in a later stage.
Summary
This PR can be summarized in the following changelog entry:
- Refactor the way we decouple the primary terms hidden fields and register their metadata.
Relevant technical choices:
- Registered rest field for all the primary terms, separated from the other meta fields because it is dynamic.
- In that way we are registering the fields on
rest_api_initand we are not limited to the WPSEO meta init method.
Test instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
- Make sure you have 2-3 categories for posts
- Edit a post and select the primary category and save
- [ ] Refresh and check the primary category was saved.
- [ ] Repeat the test with classic editor.
Inspect the the page and look for an input with the id yoast_wpseo_primary_category. Manually change it's value to text, zero, or a negative number and save.
Refresh the page and inspect the page.
- [ ] Check the text value is not there.
Without the metabox
- Comment out line 81 in
class-metabox.php:
// add_action( 'add_meta_boxes', [ $this, 'add_meta_box' ] );
- Make sure you have 2-3 categories for posts
- Edit a post and select the primary category and save
- [ ] Refresh and check the primary category was saved.
- [ ] Change focus keyphrase and save, refresh and check it was saved.
Relevant test scenarios
- [ ] Changes should be tested with the browser console open
- [ ] Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
- [ ] Changes should be tested on different editors (Default Block/Gutenberg/Classic/Elementor/other)
- [ ] Changes should be tested on different browsers
- [ ] Changes should be tested on multisite
Test instructions for QA when the code is in the RC
- [X] QA should use the same steps as above.
QA can test this PR by following these steps:
Impact check
This PR affects the following parts of the plugin, which may require extra testing:
UI changes
- [ ] This PR changes the UI in the plugin. I have added the 'UI change' label to this PR.
Other environments
- [ ] This PR also affects Shopify. I have added a changelog entry starting with
[shopify-seo], added test instructions for Shopify and attached theShopifylabel to this PR.
Documentation
- [ ] I have written documentation for this change. For example, comments in the Relevant technical choices, comments in the code, documentation on Confluence / shared Google Drive / Yoast developer portal, or other.
Quality assurance
- [ ] I have tested this code to the best of my abilities.
- [ ] During testing, I had activated all plugins that Yoast SEO provides integrations for.
- [ ] I have added unit tests to verify the code works as intended.
- [ ] If any part of the code is behind a feature flag, my test instructions also cover cases where the feature flag is switched off.
- [ ] I have written this PR in accordance with my team's definition of done.
- [ ] I have checked that the base branch is correctly set.
Innovation
- [X] No innovation project is applicable for this PR.
- [ ] This PR falls under an innovation project. I have attached the
innovationlabel. - [ ] I have added my hours to the WBSO document.
Fixes https://github.com/Yoast/wordpress-seo/issues/21223
Pull Request Test Coverage Report for Build 04df54d03c4cae059a7cff413a64420a715f62b4
Details
- 44 of 80 (55.0%) changed or added relevant lines in 5 files are covered.
- 594 unchanged lines in 3 files lost coverage.
- Overall coverage increased (+0.006%) to 52.776%
| Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
|---|---|---|---|
| admin/class-admin.php | 0 | 1 | 0.0% |
| packages/js/src/redux/initial-state/primaryTaxonomies.js | 0 | 2 | 0.0% |
| admin/class-primary-term-admin.php | 0 | 4 | 0.0% |
| src/initializers/primary-term-metadata.php | 44 | 53 | 83.02% |
| packages/js/src/helpers/fields/blockEditorSync.js | 0 | 20 | 0.0% |
| <!-- | Total: | 44 | 80 |
| Files with Coverage Reduction | New Missed Lines | % |
|---|---|---|
| inc/class-wpseo-meta.php | 1 | 20.58% |
| packages/js/src/redux/initial-state/primaryTaxonomies.js | 1 | 0.0% |
| src/generated/container.php | 592 | 0.0% |
| <!-- | Total: | 594 |
| Totals | |
|---|---|
| Change from base Build 1ed281fdbf6aa9284055b9f436a7f3afde9fc47c: | 0.006% |
| Covered Lines: | 28354 |
| Relevant Lines: | 54310 |
💛 - Coveralls
I'm putting this PR n hold since we might want to address that from a different perspective: Saving the primary terms in one metadata row.