You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The store is mutated optimistically before saveContentGuidelines() is awaited. If the save fails (network error, server error), the UI shows imported guidelines that were never persisted. Snapshot current state before mutating and rollback on failure.
2. Handle missing guideline categories in import JSON
Decide behavior when a guideline category object (e.g., "images") is entirely missing from the imported JSON, rather than being present with an empty guidelines value. Currently silently ignored.
2. Handling missing guideline categories in import JSON
Currently, the import logic treats an empty "guidelines": "" value as the marker for deletion.
The current implementation checks for the expected categories (site, images, copy, additional, etc.). If a category is not present in the imported JSON, the store retains the previously saved value for that category.
the store kept the existing values for other categories such as copy, blocks, and additional.
From a user perspective, when uploading a JSON file, it is reasonable to treat that file as the single source of truth. In this example, a user might only want to define site guidelines and expect all other categories to become blank. Currently, achieving that requires preserving the full JSON structure and explicitly setting "" for every category that should be cleared.
I feel that if a key is not present, it could indicate that the user does not intend to include that category, and we could remove or clear it accordingly.
In another scenario, if the file does not contain guideline_categories at all (for example {}), the response is:
“We ran into a problem importing your guidelines. Check that your file contains valid JSON markup and try again.”
This behavior seems reasonable.
However, if we decide that users must include all expected keys, then we should validate the structure and show a clearer error message when keys are missing. For example, if images is missing, we could warn that the JSON structure is incomplete and require users to explicitly pass "" for categories they want to clear. This would make the input format stricter but would also ensure a consistent and predictable structure instead of relying on implicit logic such as “missing key = delete.”
3. Improve import error messages
This appears to already be handled.
When an invalid file is uploaded, the UI shows:
> "We ran into a problem importing your guidelines. Check that your file contains valid JSON markup and try again."
Regarding success notices, we could potentially make them more contextual instead of generic ones by incorporating the following change:
The current Content Guidelines export (guidelines.json) follows the same pattern. Because of this precedent, adding a timestamp might be something worth discussing first to ensure consistency with other export features.
Tagging @aagam-shah and @andrewserong since this was discussed earlier, would appreciate your thoughts on the approach here.
if images is missing, we could warn that the JSON structure is incomplete and require users to explicitly pass "" for categories they want to clear. This would make the input format stricter but would also ensure a consistent and predictable structure instead of relying on implicit logic such as “missing key = delete.”
I agree with this. IMO, strong validations on the JSON structure is more transparent.
Regarding success notices, we could potentially make them more contextual instead of generic ones by incorporating the following change.
Yes we can do this. For the block category of guidelines, we could either include the block type as well, or keep it simple, and just say, "Block guidelines [ saved | removed ]" . Previous discussion on this: #76155 (comment)
Handling missing guideline categories in import JSON
Whilst I also find it intuitive to have full JSON validation. However, I have an alternative view on approaching this problem. The current discussion is based on user behaviour and experience whilst updating/importing their content guidelines.
To ensure that user is empowered to import the the very first draft of guidelines using JSON import functionality, they must be made aware of the JSON schema of the guidelines. This paves the way for a proper documentation/help section to guide the user with the schema.
The documentation could be used as the reference guide on whether the absence of key means deletion or exception to the import functionality.
I think both ways - "treating absence as deletion" and "treating absence as ignorance" have merit. It is how the documentation helps the user to negotiate the feature.
If we do that, the import-success will contain a lot of success notices, no? Say the import file had 10 guidelines. Then there will be 10 different notices if you import that file. I don't think it would make a good impression to the users.
Edit: I think you are not talking about the import success message here, just the regular edit-guideline flow's save success message. Yes that would improve the UI. Not related to import/export flow though, so I wouldn't keep that as a blocker to this issue.
After another round of review, I think we got all the items of this issue covered. I am closing this issue. Feel free to reopen if you think anything went amiss.
Activity
im3dabasia commentedon Mar 16, 2026
Most of this feedback has already been incorporated here:
Code ref
gutenberg/routes/content-guidelines/api.ts
Lines 155 to 174 in 11ecb64
Currently, the import logic treats an empty
"guidelines": ""value as the marker for deletion.The current implementation checks for the expected categories (site, images, copy, additional, etc.). If a category is not present in the imported JSON, the store retains the previously saved value for that category.
When I tested the following case:
{ "guideline_categories": { "site": { "guidelines": "Some value" } } }the store kept the existing values for other categories such as
copy,blocks, andadditional.From a user perspective, when uploading a JSON file, it is reasonable to treat that file as the single source of truth. In this example, a user might only want to define site guidelines and expect all other categories to become blank. Currently, achieving that requires preserving the full JSON structure and explicitly setting "" for every category that should be cleared.
I feel that if a key is not present, it could indicate that the user does not intend to include that category, and we could remove or clear it accordingly.
In another scenario, if the file does not contain guideline_categories at all (for example {}), the response is:
This behavior seems reasonable.
However, if we decide that users must include all expected keys, then we should validate the structure and show a clearer error message when keys are missing. For example, if images is missing, we could warn that the JSON structure is incomplete and require users to explicitly pass "" for categories they want to clear. This would make the input format stricter but would also ensure a consistent and predictable structure instead of relying on implicit logic such as “missing key = delete.”
This appears to already be handled.
When an invalid file is uploaded, the UI shows:
> "We ran into a problem importing your guidelines. Check that your file contains valid JSON markup and try again."
Regarding success notices, we could potentially make them more contextual instead of generic ones by incorporating the following change:
Currently, other WordPress exports (patterns, site export, reusable blocks JSON) follow a simple naming convention without timestamps.
The current Content Guidelines export (guidelines.json) follows the same pattern. Because of this precedent, adding a timestamp might be something worth discussing first to ensure consistency with other export features.
Tagging @aagam-shah and @andrewserong since this was discussed earlier, would appreciate your thoughts on the approach here.
saroshaga commentedon Mar 17, 2026
Thank you for looking into this @im3dabasia 🙌
I agree with this. IMO, strong validations on the JSON structure is more transparent.
Yes we can do this. For the block category of guidelines, we could either include the block type as well, or keep it simple, and just say, "Block guidelines [ saved | removed ]" . Previous discussion on this: #76155 (comment)
iamchughmayank commentedon Mar 20, 2026
Some good points here in the conversation.
Regarding the point:
Whilst I also find it intuitive to have full JSON validation. However, I have an alternative view on approaching this problem. The current discussion is based on user behaviour and experience whilst updating/importing their content guidelines.
To ensure that user is empowered to import the the very first draft of guidelines using JSON import functionality, they must be made aware of the JSON schema of the guidelines. This paves the way for a proper documentation/help section to guide the user with the schema.
The documentation could be used as the reference guide on whether the absence of key means deletion or exception to the import functionality.
I think both ways - "treating absence as deletion" and "treating absence as ignorance" have merit. It is how the documentation helps the user to negotiate the feature.
aswasif007 commentedon Apr 14, 2026
Linking this PR as it addresses some of the issues: #76621
aswasif007 commentedon Apr 15, 2026
We had updated this behaviour. The store no longer keeps the existing values if they are absent from the import file.
aswasif007 commentedon Apr 15, 2026
If we do that, the import-success will contain a lot of success notices, no? Say the import file had 10 guidelines. Then there will be 10 different notices if you import that file. I don't think it would make a good impression to the users.
Edit: I think you are not talking about the import success message here, just the regular edit-guideline flow's save success message. Yes that would improve the UI. Not related to import/export flow though, so I wouldn't keep that as a blocker to this issue.
aswasif007 commentedon Apr 15, 2026
After another round of review, I think we got all the items of this issue covered. I am closing this issue. Feel free to reopen if you think anything went amiss.