Explorar o código

Spearhead: fix unregister block pattern bug (#2574)

* Remove calls to unregister.

* Fix package name.

* Ensure these load after Seedlet so that we can deregister Seedlets block patterns.
Jeff Ong %!s(int64=4) %!d(string=hai) anos
pai
achega
c826235937
Modificáronse 2 ficheiros con 45 adicións e 27 borrados
  1. 1 1
      spearhead/functions.php
  2. 44 26
      spearhead/inc/block-patterns.php

+ 1 - 1
spearhead/functions.php

@@ -5,7 +5,7 @@
  * @link https://developer.wordpress.org/themes/basics/theme-functions/
  * @link https://developer.wordpress.org/themes/basics/theme-functions/
  *
  *
  * @package WordPress
  * @package WordPress
- * @subpackage Sk8prk
+ * @subpackage Spearhead
  * @since 1.0.0
  * @since 1.0.0
  */
  */
 
 

+ 44 - 26
spearhead/inc/block-patterns.php

@@ -6,34 +6,52 @@
  * @since   1.0.0
  * @since   1.0.0
  */
  */
 
 
-/**
- * Register Block Pattern Category.
- */
-if ( function_exists( 'register_block_pattern_category' ) ) {
+if ( ! function_exists( 'spearhead_register_block_patterns' ) ) :
+	/**
+	 * Sets up support for block patterns and unregisters Seedlet's.
+	 */
+	function spearhead_register_block_patterns() {
+		/**
+		 * Register Block Pattern Category.
+		 */
+		if ( function_exists( 'register_block_pattern_category' ) ) {
 
 
-	unregister_block_pattern_category( 'seedlet' );
+			register_block_pattern_category(
+				'spearhead',
+				array( 'label' => __( 'Spearhead', 'spearhead' ) )
+			);
+		}
 
 
-	register_block_pattern_category(
-		'spearhead',
-		array( 'label' => __( 'Spearhead', 'spearhead' ) )
-	);
-}
+		/**
+		 * Register Block Patterns.
+		 */
+		if ( function_exists( 'register_block_pattern' ) ) {
 
 
-/**
- * Register Block Patterns.
- */
-if ( function_exists( 'register_block_pattern' ) ) {
+			register_block_pattern(
+				'spearhead/related-posts',
+				array(
+					'title'      => __( 'Related Posts', 'spearhead' ),
+					'categories' => array( 'spearhead' ),
+					'content'    => '<!-- wp:separator {"className":"is-style-wide"} --><hr class="wp-block-separator is-style-wide"/><!-- /wp:separator --><!-- wp:paragraph {"fontSize":"medium"} --><p class="has-medium-font-size">Related</p><!-- /wp:paragraph --><!-- wp:jetpack/related-posts /-->',
+				)
+			);
+		}
 
 
-	unregister_block_pattern( 'seedlet/group-split-background' );
-	unregister_block_pattern( 'seedlet/group-image-overlap' );
-	unregister_block_pattern( 'seedlet/latest-posts-alternating-grid' );
+		/**
+		 * Unregister SeedletBlock Pattern Category.
+		 */
+		if ( function_exists( 'unregister_block_pattern_category' ) ) {
+			unregister_block_pattern_category( 'seedlet' );
+		}
 
 
-	register_block_pattern(
-		'spearhead/related-posts',
-		array(
-			'title'      => __( 'Related Posts', 'spearhead' ),
-			'categories' => array( 'spearhead' ),
-			'content'    => '<!-- wp:separator {"className":"is-style-wide"} --><hr class="wp-block-separator is-style-wide"/><!-- /wp:separator --><!-- wp:paragraph {"fontSize":"medium"} --><p class="has-medium-font-size">Related</p><!-- /wp:paragraph --><!-- wp:jetpack/related-posts /-->',
-		)
-	);
-}
+		/**
+		 * Unregister Block Patterns from Seedlet.
+		 */
+		if ( function_exists( 'unregister_block_pattern' ) ) {
+			unregister_block_pattern( 'seedlet/group-split-background' );
+			unregister_block_pattern( 'seedlet/group-image-overlap' );
+			unregister_block_pattern( 'seedlet/latest-posts-alternating-grid' );
+		}
+	}
+endif;
+add_action( 'after_setup_theme', 'spearhead_register_block_patterns', 12 );