From 0ef7a43f0f8937524837fea471259bd4355de99a Mon Sep 17 00:00:00 2001 From: Jay McPartland Date: Wed, 15 Oct 2025 17:17:45 +0100 Subject: [PATCH 1/2] Add Multisite Global Media integration --- .../themes/humanity-theme/functions.php | 4 + .../includes/mgm/class-mgm-filters.php | 169 ++++++++++++++++++ 2 files changed, 173 insertions(+) create mode 100644 wp-content/themes/humanity-theme/includes/mgm/class-mgm-filters.php diff --git a/wp-content/themes/humanity-theme/functions.php b/wp-content/themes/humanity-theme/functions.php index 93b5d9ee..762219e7 100644 --- a/wp-content/themes/humanity-theme/functions.php +++ b/wp-content/themes/humanity-theme/functions.php @@ -292,4 +292,8 @@ } #endregion multilingualpress +/** + * Theme Multisite Global Media includes + */ +require_once realpath( __DIR__ . '/includes/mgm/class-mgm-filters.php' ); // phpcs:enable Squiz.Commenting.InlineComment.WrongStyle,PEAR.Commenting.InlineComment.WrongStyle diff --git a/wp-content/themes/humanity-theme/includes/mgm/class-mgm-filters.php b/wp-content/themes/humanity-theme/includes/mgm/class-mgm-filters.php new file mode 100644 index 00000000..fb7b9000 --- /dev/null +++ b/wp-content/themes/humanity-theme/includes/mgm/class-mgm-filters.php @@ -0,0 +1,169 @@ +site = new Site(); + } + + add_filter( 'global_media.process_post.block_amnesty_core_block_section', [ $this, 'section' ], 10, 3 ); + add_filter( 'global_media.process_post.block_amnesty_core_hero', [ $this, 'hero' ], 10, 3 ); + add_filter( 'global_media.process_post.block_amnesty_core_block_slider', [ $this, 'slider' ], 10, 3 ); + add_filter( 'global_media.process_post.block_amnesty_core_action_block', [ $this, 'action' ], 10, 3 ); + add_filter( 'global_media.process_post.block_amnesty_core_background_media_column', [ $this, 'background_media_column' ], 10, 3 ); + add_filter( 'global_media.process_post.block_amnesty_core_custom_card', [ $this, 'custom_card' ], 10, 3 ); + } + + /** + * For when the origin is the global media site, add the prefix to the image ID + * + * @param array $block the parsed block data + * + * @return array + */ + public function section( array $block ): array { + $image_id = absint( $block['attrs']['backgroundImageId'] ?? '0' ); + + if ( $image_id ) { + $block['attrs']['backgroundImageId'] = $this->process( $image_id ); + } + + return $block; + } + + /** + * For when the origin is the global media site, add the prefix to the image ID + * + * @param array $block the parsed block data + * + * @return array + */ + public function hero( array $block ): array { + $image_id = absint( $block['attrs']['imageID'] ?? '0' ); + + if ( $image_id ) { + $block['attrs']['imageID'] = $this->process( $image_id ); + } + + return $block; + } + + /** + * For when the origin is the global media site, add the prefix to the image ID + * + * @param array $block the parsed block data + * + * @return array + */ + public function slider( array $block ): array { + foreach ( (array) $block['attrs']['slides'] as $index => $slide ) { + $image_id = absint( $slide['imageId'] ?? '0' ); + + if ( $image_id ) { + $block['attrs']['slides'][ $index ]['imageId'] = $this->process( $image_id ); + } + } + + return $block; + } + + /** + * For when the origin is the global media site, add the prefix to the image ID + * + * @param array $block the parsed block data + * + * @return array + */ + public function action( array $block ): array { + $image_id = absint( $block['attrs']['imageID'] ?? '0' ); + + if ( $image_id ) { + $block['attrs']['imageID'] = $this->process( $image_id ); + } + + return $block; + } + + /** + * For when the origin is the global media site, add the prefix to the image ID + * + * @param array $block the parsed block data + * + * @return array + */ + public function background_media_column( array $block ): array { + $image_id = absint( $block['attrs']['image'] ?? '0' ); + + if ( $image_id ) { + $block['attrs']['image'] = $this->process( $image_id ); + } + + return $block; + } + + /** + * For when the origin is the global media site, add the prefix to the image ID + * + * @param array $block the parsed block data + * + * @return array + */ + public function custom_card( array $block ): array { + $image_id = absint( $block['attrs']['imageID'] ?? '0' ); + + if ( $image_id ) { + $block['attrs']['imageID'] = $this->process( $image_id ); + } + + return $block; + } + + /** + * Check if the given site Id prefix exists into the give attachment id + * + * @param int|string $id the attachment ID + * + * @return bool + */ + protected function media_has_prefix( int|string $id ): bool { + return false !== strpos( (string) $id, $this->site->idSitePrefix() ); + } + + /** + * Process an attribute value + * + * @param int|string $id the attribute value + * + * @return int + */ + protected function process( int|string $id ): int { + if ( $this->media_has_prefix( $id ) ) { + return absint( $id ); + } + + return absint( $this->site->idSitePrefix() . $id ); + } + +} From 8f68f72300684d29741ae08f6d67761fed456f5e Mon Sep 17 00:00:00 2001 From: Jay McPartland Date: Thu, 23 Oct 2025 13:19:12 +0100 Subject: [PATCH 2/2] Update MGM filters to support video within hero --- .../themes/humanity-theme/includes/mgm/class-mgm-filters.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wp-content/themes/humanity-theme/includes/mgm/class-mgm-filters.php b/wp-content/themes/humanity-theme/includes/mgm/class-mgm-filters.php index fb7b9000..fea09091 100644 --- a/wp-content/themes/humanity-theme/includes/mgm/class-mgm-filters.php +++ b/wp-content/themes/humanity-theme/includes/mgm/class-mgm-filters.php @@ -62,11 +62,16 @@ public function section( array $block ): array { */ public function hero( array $block ): array { $image_id = absint( $block['attrs']['imageID'] ?? '0' ); + $video_id = absint( $block['attrs']['featuredVideoId'] ?? '0' ); if ( $image_id ) { $block['attrs']['imageID'] = $this->process( $image_id ); } + if ( $video_id ) { + $block['attrs']['featuredVideoId'] = $this->process( $video_id ); + } + return $block; }