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.
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
Site Editor: Revert custom templates to their original theme-provided files #28141
Site Editor: Revert custom templates to their original theme-provided files #28141
Changes from 30 commits
a9bc63f
37ec486
edaeb81
192aeab
67d310d
1cc29eb
ff592f6
abec6dd
0a306dd
1118c5e
bd23825
108aff1
a8c1cf4
b4b76b9
b434762
0d33138
4653313
36049c6
dbce5ba
5bfd86b
32aa328
a5b32c3
d581dbc
8cddbc9
feadc71
743b71d
e66c425
a9ce620
01bdfe1
4a01921
5a6cd9f
360cb85
653fc4b
e646065
e5603d0
fb73a6b
2d8aa9e
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
I wonder if there is any way to get consistent markup out of
$template->content
? I wanted to compare the content with the file template's content but looks like the JS serializer gives a different markup from the PHP serializer. Thus when comparing thecontent
from the request to the$template->content
, they are different. I've even tried to reserialize both usingserialize_blocks ( parse_blocks ( $content ) )
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.
I'm not quite sure why we need to compare the template content. 🤔
Couldn't we just rely on
isset( $request['is_custom'] ) && 'false' === $request['is_custom']
to determine that this is a revert call?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.
I think we need a way to differentiate between 1 - retrieving the non-custom content and 2 - reverting to that. Reverting based on presence of
$request['is_custom'] === false
means we cannot access that non-custom content without reverting the post as well. 🤔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.
Maybe another request param like
is_revert
could get around needing to compare content? 🤔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.
It's related to saving a template for the first time. It would save as
is_custom = false
since we aren't updating its state on the client side. So we rely on the content. To get around this, we would need to setis_custom
to true when we start making changes to the template.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.
@Addison-Stavlo It's not super clear by the diff, but I was specifically talking about
update_item
; you can stillget_item
a non-custom item.(Unless I've misunderstood your comment? 🤔 )
@david-szabo97 Apologies if these are dumb comments, but I really forgot everything I researched while working on this issue. 😓
When we save a template for the first time (and subsequent times as well, I think?), we only really send ID and content.
$request['is_custom']
is undefined, and theisset( $request['is_custom'] ) && 'false' === $request['is_custom']
check will fail.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.
There is also an issue I encountered while trying to use the implementation you suggest. For some reason the selector that takes care of collecting the changed properties of the entity, doesn't return the
is_custom
property as changed. It only happens with boolean properties. Changingtrue
/false
to'yes'
/'no'
gets around this problem.According to our discussion, I renamed
is_custom
tosource
and it uses two string values:theme
andcustom
.