-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Image Block: Add data-id attribute on server side render for core galleries #35975
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b0cddec
Adding a server render_callback in order to add a data-id attribute t…
ramonjd a0b5948
Switch to using the_post instead of server side block render
6af28ef
Change order of attribs and check for innerBlocks
48975cd
Reinstating render_callback
ramonjd 15e8532
This commit adds a data-id attribute to every image innerblock of a g…
ramonjd fcd872f
NEWSFLASH! Array keys must be surrounded by spaces unless they cont…
ramonjd a958531
Adding a render function so that block based themes render the galler…
ramonjd ff4ba58
Add guards for undefined indexes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Change order of attribs and check for innerBlocks
- Loading branch information
commit 6af28ef59ba53e53dedb17f678fec76250eab37f
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
Is there are case where we'd want to run this code for rest requests?
I'm thinking it's safe to return early if we're targeting post data on the frontend, unless I'm missing a use case.
For example, add a
var_dump('I LOVE THE BAND KISS!')or some other logging after this if statement, and try to save a post. It doesn't have to contain a gallery.The POST response will contain invalid, but possibly true, content:
string(21) "I LOVE THE BAND KISS!" {id: 115, date: "2021-11-02T03:18:06", date_gmt: "2021-11-02T03:18:06",…}Pinging a WP API endpoint that contains gallery post content still works for me with this check in place:
E.g.,

http://localhost:4759/wp-json/wp/v2/posts/104There 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'd be somewhat wary about using
is_admin()in a condition check here. All it means is that the context when this post is setup is happening withoutwp-admin, it doesn't actually mean that the post is being edited or the like. Somewhat could just as easily be expecting to get this data over anadmin-ajax.phpcall or simply trying to render their gallery in an admin page.The same goes for
REST_REQUEST. It can both be used in the Block Editor. But it can also be used by someone making an API call to grab data for somewhere on the front-end of their website where they would expect the ids to be present.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.
Thanks for the advice @TimothyBJacobs 🙇
I think @glendaviesnz was trying to find ways to isolate the logic to frontend rendering to avoid block validation errors, given that
data-idisn't output by the save method of the image block.🤔 Assuming block validation wasn't an issue, do you see any issues with removing the if check here entirely?
Cheers!
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.
No, I think removing the check entirely would be ideal.