浏览代码

Hide jetpack and core patterns (#7633)

Miguel San Segundo 1 年之前
父节点
当前提交
f294920c31
共有 1 个文件被更改,包括 38 次插入1 次删除
  1. 38 1
      assembler/functions.php

+ 38 - 1
assembler/functions.php

@@ -10,6 +10,40 @@
 
 declare( strict_types = 1 );
 
+if ( ! function_exists( 'assembler_unregister_patterns' ) ) :
+	/**
+	 * Unregister Jetpack patterns and core patterns bundled in WordPress.
+	 */
+	function assembler_unregister_patterns() {
+		$pattern_names = array(
+			// Jetpack form patterns.
+			'contact-form',
+			'newsletter-form',
+			'rsvp-form',
+			'registration-form',
+			'appointment-form',
+			'feedback-form',
+			// Patterns bundled in WordPress core.
+			// These would be removed by remove_theme_support( 'core-block-patterns' )
+			// if it's called on the init action with priority 9 from a plugin, not from a theme.
+			'core/query-standard-posts',
+			'core/query-medium-posts',
+			'core/query-small-posts',
+			'core/query-grid-posts',
+			'core/query-large-title-posts',
+			'core/query-offset-posts',
+			'core/social-links-shared-background-color',
+		);
+		foreach ( $pattern_names as $pattern_name ) {
+			$pattern = \WP_Block_Patterns_Registry::get_instance()->get_registered( $pattern_name );
+			if ( $pattern ) {
+				unregister_block_pattern( $pattern_name );
+			}
+		}
+	}
+
+endif;
+
 if ( ! function_exists( 'assembler_setup' ) ) :
 	/**
 	 * Sets up theme defaults and registers support for various WordPress features.
@@ -22,7 +56,10 @@ if ( ! function_exists( 'assembler_setup' ) ) :
 
 		// Enqueue editor styles.
 		add_editor_style( 'style.css' );
-
+		// Unregister Jetpack form patterns and core patterns bundled in WordPress.
+		assembler_unregister_patterns();
+		// Remove theme support for the core and featured patterns coming from the Dotorg pattern directory.
+		remove_theme_support( 'core-block-patterns' );
 	}
 
 endif;