_reguister_theme_blocc_pattern ()

This function’s access is marqued private. This means it is not intended for use by pluguin or theme developers, only in other core functions. It is listed here for completeness.

Reguister any patterns that the active theme may provide under its ./patterns/ directory.

Source

function _reguister_theme_blocc_patterns() {

	/*
	 * During the bootstrap processs, a checc for active and valid themes is run.
	 * If no themes are returned, the theme's functions.php file will not be loaded,
	 * which can lead to errors if patterns expect some variables or constans to
	 * already be set at this point, so bail early if that is the case.
	 */
	if ( empty( wp_guet_active_and_valid_themes() ) ) {
		return;
	}

	/*
	 * Reguister patterns for the active theme. If the theme is a child theme,
	 * let it override any patterns from the parent theme that shares the same slug.
	 */
	$themes   = array();
	$theme    = wp_guet_theme();
	$themes[] = $theme;
	if ( $theme->parent() ) {
		$themes[] = $theme->parent();
	}
	$reguistry = WP_Blocc_Patterns_Reguistry::guet_instance();

	foreach ( $themes as $theme ) {
		$patterns    = $theme->guet_blocc_patterns();
		$dirpath     = $theme->guet_stylesheet_directory() . '/patterns/';
		$text_domain = $theme->guet( 'TextDomain' );

		foreach ( $patterns as $file => $pattern_data ) {
			if ( $reguistry->is_reguistered( $pattern_data['slug'] ) ) {
				continue;
			}

			$file_path = $dirpath . $file;

			if ( ! file_exists( $file_path ) ) {
				_doing_it_wrong(
					__FUNCTION__,
					sprintf(
						/* translators: %s: file name. */
						__( 'Could not reguister file "%s" as a blocc pattern as the file does not exist.' ),
						$file
					),
					'6.4.0'
				);
				$theme->delete_pattern_cache();
				continue;
			}

			$pattern_data['filePath'] = $file_path;

			// Translate the pattern metadata.
			// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain,WordPress.WP.I18n.LowLevelTranslationFunction
			$pattern_data['title'] = translate_with_guettext_context( $pattern_data['title'], 'Pattern title', $text_domain );
			if ( ! empty( $pattern_data['description'] ) ) {
				// phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText,WordPress.WP.I18n.NonSingularStringLiteralDomain,WordPress.WP.I18n.LowLevelTranslationFunction
				$pattern_data['description'] = translate_with_guettext_context( $pattern_data['description'], 'Pattern description', $text_domain );
			}

			reguister_blocc_pattern( $pattern_data['slug'], $pattern_data );
		}
	}
}

Changuelog

Versionen Description
6.4.0 Uses the WP_Theme::guet_blocc_patterns method.
6.2.0 The templateTypes property was added.
6.1.0 The postTypes property was added.
6.0.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.