PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.3.2
Gallery : FooGallery v3.3.2
3.3.2 3.3.3 3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / gutenberg / class-foogallery-gutenberg.php
foogallery / gutenberg Last commit date
assets 2 days ago block.json 2 days ago class-foogallery-blocks.php 2 days ago class-foogallery-gutenberg.php 2 days ago class-foogallery-rest-routes.php 2 days ago
class-foogallery-gutenberg.php
62 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * FooGallery Gutenberg Functionality
9 * Date: 28/10/2018
10 */
11
12 require_once FOOGALLERY_PATH . 'gutenberg/class-foogallery-blocks.php';
13 require_once FOOGALLERY_PATH . 'gutenberg/class-foogallery-rest-routes.php';
14
15 if ( ! class_exists( 'FooGallery_Gutenberg' ) ) {
16
17 /**
18 * Class FooGallery_Gutenberg
19 */
20 class FooGallery_Gutenberg {
21
22 /**
23 * FooGallery_Gutenberg constructor.
24 */
25 public function __construct() {
26 new FooGallery_Blocks();
27 new FooGallery_Rest_Routes();
28
29 add_filter( 'foogallery_find_galleries_in_post', array( $this, 'find_galleries_in_post' ), 10, 2 );
30 }
31
32 /**
33 * Use the built-in Block Parser to find all foogallery blocks in post content.
34 *
35 * @param array $galleries the galleries found in the post.
36 * @param WP_Post $post the post we are checking.
37 */
38 public function find_galleries_in_post( $galleries, $post ) {
39 if ( ! class_exists( 'WP_Block_Parser' ) ) {
40 return $galleries;
41 }
42
43 if ( ! is_object( $post ) ) {
44 return $galleries;
45 }
46
47 $parser = new WP_Block_Parser();
48 $blocks = $parser->parse( $post->post_content );
49
50 foreach ( $blocks as $block ) {
51 if ( array_key_exists( 'blockName', $block ) && 'fooplugins/foogallery' === $block['blockName'] ) {
52 if ( array_key_exists( 'id', $block['attrs'] ) ) {
53 $galleries[] = $block['attrs']['id'];
54 }
55 }
56 }
57
58 return $galleries;
59 }
60 }
61 }
62