[wp-trac] [WordPress Trac] #55203: Bug with get_post_galleries
WordPress Trac
noreply at wordpress.org
Sat Feb 19 23:42:55 UTC 2022
#55203: Bug with get_post_galleries
--------------------------+-----------------------------
Reporter: BinaryMoon | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 5.9
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Hi - I really like the changes made to get_post_galleries in 5.9 but there
is a bug with it.
The change I am referring to can be seen here:
https://core.trac.wordpress.org/ticket/43826
In this section
https://core.trac.wordpress.org/browser/trunk/src/wp-
includes/media.php?rev=52190#L4770
There is no check that you are actually dealing with galleries, and so
non-gallery blocks can be returned. I spotted this in a problem when using
`get_post_gallery` and a paragraph was being returned.
This happens when the gallery block is not the first block in the post
content. If you have a paragraph, and then a gallery, and use
`get_post_gallery` the paragraph will be returned instead of the gallery.
The process as I see it is:
* check for block name
* check has innerBlocks and not gallery (for nested blocks)
* check if has inner blocks
* grab ids and use those
Currently there is no check that the block being looped through is
actually a gallery.
I think it needs to check if the block is a gallery or not before doing
any processing. I would add this check after the check for ''innerblocks
and not gallery''.
The following fixed the issue for me.
[[Image(https://cldup.com/OgtyNxvnsz.png)]]
Currently get_post_gallery will only work when the gallery is the first
item in the post. If there's a different block in the post then it's
possible that will be used instead.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/55203>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list