[wp-trac] [WordPress Trac] #43826: get_post_galleries() should return gallery blocks
WordPress Trac
noreply at wordpress.org
Sun Nov 4 20:04:47 UTC 2018
#43826: get_post_galleries() should return gallery blocks
------------------------------------------+---------------------
Reporter: pento | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 5.0
Component: Media | Version:
Severity: normal | Resolution:
Keywords: needs-patch needs-unit-tests | Focuses:
------------------------------------------+---------------------
Comment (by birgire):
@Takahashi_Fumiki
Thanks for the patch.
When I add a gallery I get something like this:
{{{
<!-- wp:gallery -->
<ul class="wp-block-gallery columns-3 is-cropped">
<li class="blocks-gallery-item">
<figure>
<img src="https://example.com/wp-
content/uploads/2018/11/image.jpg" alt="" data-id="123" data-
link="https://example.com/testing/image/" class="wp-image-123"/>
<figcaption>Test image.</figcaption>
</figure>
</li>
<li>...cut...</li>
<li>...cut...</li>
</ul>
<!-- /wp:gallery -->
}}}
So I assume the task here is to support this format in
{{{get_post_galleries()}}} ?
----
I noticed in [attachment:"43826.patch"] the following:
{{{
if ( false !== strpos( $post->post_content, '<!-- wp:gallery' ) ) {
}}}
We can instead use the {{{has_block()}}} function to check for the gallery
block, e.g.:
{{{
if ( has_block( 'gallery', $post->post_content ) ) {
}}}
There's also the {{{parse_blocks()}}}, that might help to get the
{{{innerHTML}}} of the {{{core/gallery}}} block names, instead of using:
{{{
if ( preg_match_all( '/<!-- wp:gallery([^>]*)-->(.*?)<!-- \/wp:gallery
-->/s', $post->post_content, $blocks, PREG_SET_ORDER ) ) {
}}}
Adding tests for the block format string cases (like above) sounds good.
Here are the current {{{get_post_galleries()}}} tests that would be
helpful:
https://core.trac.wordpress.org/browser/tags/4.9.8/tests/phpunit/tests/media.php
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43826#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list