HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/insiders/wp-load/wp-content/plugins/breadly/lib/patterns.php
<?php

/*//////////////////////////////////////
// Manage patterns
//////////////////////////////////////*/

if ( ! class_exists( 'GTM_Patterns' ) ) {
	class GTM_Patterns {
		private static $instance = null;

		public static function get_instance() {
			if ( null === self::$instance ) {
				self::$instance = new self();
			}

			return self::$instance;
		}

		public function __construct() {
			add_action( 'init', [$this, 'init'], 10 );
		}

		public function init() {
			if ( ! get_theme_support( 'gutenmate-patterns' ) ) {
				return;
			}

			// Register templates
			$template_parts = get_block_templates( [], 'wp_template' );

			foreach ( $template_parts as $template_part ) {
				if ( gtm_startsWith( $template_part->slug, 'single-' ) ) {
					register_block_pattern( $template_part->id, [
						'templateTypes' => ['single'],
						'title'         => $template_part->title,
						'content'       => $template_part->content,
					] );

				} else if ( gtm_startsWith( $template_part->slug, 'page-' ) ) {
					register_block_pattern( $template_part->id, [
						'templateTypes' => ['page'],
						'title'         => $template_part->title,
						'content'       => $template_part->content,
					] );

				}
			}

			// Register template parts
			$template_parts = get_block_templates( [], 'wp_template_part' );

			foreach ( $template_parts as $template_part ) {
				if ( gtm_startsWith( $template_part->slug, 'archive-template-' ) ) {
					register_block_pattern( $template_part->id, [
						'templateTypes' => ['archive', 'category', 'tag', 'date', 'author'],
						'title'         => $template_part->title,
						'content'       => $template_part->content,
					] );

				} else if ( gtm_startsWith( $template_part->slug, 'home-template-' ) ) {
					register_block_pattern( $template_part->id, [
						'templateTypes' => ['front-page'],
						'title'         => $template_part->title,
						'content'       => $template_part->content,
					] );

				} else if ( gtm_startsWith( $template_part->slug, 'blog-template-' ) ) {
					register_block_pattern( $template_part->id, [
						'templateTypes' => ['home', 'archive', 'category', 'tag', 'date', 'author'],
						'title'         => $template_part->title,
						'content'       => $template_part->content,
					] );

				} else if ( gtm_startsWith( $template_part->slug, 'author-template-' ) ) {
					register_block_pattern( $template_part->id, [
						'templateTypes' => ['author'],
						'title'         => $template_part->title,
						'content'       => $template_part->content,
					] );
				} else if ( gtm_startsWith( $template_part->slug, 'shop-template-' ) ) {
					register_block_pattern( $template_part->id, [
						'templateTypes' => ['archive-product'],
						'title'         => $template_part->title,
						'content'       => $template_part->content,
					] );
				} else if ( gtm_startsWith( $template_part->slug, 'shop-product-template-' ) ) {
					register_block_pattern( $template_part->id, [
						'templateTypes' => ['single-product'],
						'title'         => $template_part->title,
						'content'       => $template_part->content,
					] );
				} else if ( gtm_startsWith( $template_part->slug, 'shop-taxonomy-template-' ) ) {
					register_block_pattern( $template_part->id, [
						'templateTypes' => ['taxonomy-product_cat', 'taxonomy-product_tag', 'taxonomy-product_attribute'],
						'title'         => $template_part->title,
						'content'       => $template_part->content,
					] );
				}
			}
		}

		// /**
		//  * Register block pattern from template part
		//  * Arguments is the same as `register_block_pattern()`
		//  * but the `$pattern_properties['content']` must be a Template unique identifier (example: theme_slug//template_slug)
		//  */
		public function register_block_pattern_from_id( $pattern_name, $pattern_properties ) {

			if ( ! empty( $pattern_properties['content'] ) ) {
				$is_code                = strpos( $pattern_properties['content'], '<' ) !== false;
				$is_template_identifier = strpos( $pattern_properties['content'], '//' ) !== false;

				if ( ! $is_code && $is_template_identifier ) {
					$block_template = get_block_template( $pattern_properties['content'], 'wp_template_part' );

					if ( $block_template ) {
						$pattern_properties['content'] = $block_template->content;

					}
				}

				return register_block_pattern( $pattern_name, $pattern_properties );
			}

			return false;
		}

	}
}

GTM_Patterns::get_instance();