Automattic\WooCommerce\Blocks

BlockPatterns::get_block_patterns()privateWC 1.0

Gets block pattern data from the cache if available

Method of the class: BlockPatterns{}

No Hooks.

Return

Array. Block pattern data.

Usage

// private - for code of main (parent) class only
$result = $this->get_block_patterns();

BlockPatterns::get_block_patterns() code WC 9.6.0

private function get_block_patterns() {
	$pattern_data = $this->get_pattern_cache();

	if ( is_array( $pattern_data ) ) {
		return $pattern_data;
	}

	$default_headers = array(
		'title'         => 'Title',
		'slug'          => 'Slug',
		'description'   => 'Description',
		'viewportWidth' => 'Viewport Width',
		'categories'    => 'Categories',
		'keywords'      => 'Keywords',
		'blockTypes'    => 'Block Types',
		'inserter'      => 'Inserter',
		'featureFlag'   => 'Feature Flag',
		'templateTypes' => 'Template Types',
	);

	if ( ! file_exists( $this->patterns_path ) ) {
		return array();
	}

	$files = glob( $this->patterns_path . '/*.php' );
	if ( ! $files ) {
		return array();
	}

	$patterns = array();

	foreach ( $files as $file ) {
		$data           = get_file_data( $file, $default_headers );
		$data['source'] = $file;
		$patterns[]     = $data;
	}

	$this->set_pattern_cache( $patterns );
	return $patterns;
}