From e09b27c5710048d8bde99dbd93e7fb910a080dd0 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Mon, 11 Apr 2022 19:39:15 +0530 Subject: [PATCH 1/7] Add footer block pattern --- inc/classes/patterns/content/class-footer.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 inc/classes/patterns/content/class-footer.php diff --git a/inc/classes/patterns/content/class-footer.php b/inc/classes/patterns/content/class-footer.php new file mode 100644 index 00000000..8f8a2719 --- /dev/null +++ b/inc/classes/patterns/content/class-footer.php @@ -0,0 +1,61 @@ + __( 'Footer', 'elementary' ), + 'categories' => array( 'footer' ), + 'blockTypes' => array( 'core/template-part/footer' ), + 'content' => $this->block_pattern_content(), + ); + } + + /** + * Footer Block Pattern content. + * + * @return string Block pattern content. + */ + public function block_pattern_content() { + ob_start(); + ?> + +
+ +
+ + +

+ WordPress' + ); + ?> +

+
+
+ Date: Mon, 11 Apr 2022 19:42:38 +0530 Subject: [PATCH 2/7] Add hidden-404 block pattern --- .../patterns/content/class-hidden-404.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 inc/classes/patterns/content/class-hidden-404.php diff --git a/inc/classes/patterns/content/class-hidden-404.php b/inc/classes/patterns/content/class-hidden-404.php new file mode 100644 index 00000000..867182ef --- /dev/null +++ b/inc/classes/patterns/content/class-hidden-404.php @@ -0,0 +1,58 @@ + __( '404 content', 'elementary' ), + 'inserter' => false, + 'content' => $this->block_pattern_content(), + ); + } + + /** + * 404 Block Pattern content. + * + * @return string Block pattern content. + */ + public function block_pattern_content() { + ob_start(); + ?> + +

+ + +

+ + + + + + + + + + + + Date: Mon, 11 Apr 2022 19:43:30 +0530 Subject: [PATCH 3/7] Add base class for block pattern classes --- .../patterns/class-block-pattern-base.php | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 inc/classes/patterns/class-block-pattern-base.php diff --git a/inc/classes/patterns/class-block-pattern-base.php b/inc/classes/patterns/class-block-pattern-base.php new file mode 100644 index 00000000..a2bb79d2 --- /dev/null +++ b/inc/classes/patterns/class-block-pattern-base.php @@ -0,0 +1,30 @@ + Date: Mon, 11 Apr 2022 19:44:20 +0530 Subject: [PATCH 4/7] Add register block pattern/pattern-categories --- inc/classes/patterns/class-block-patterns.php | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 inc/classes/patterns/class-block-patterns.php diff --git a/inc/classes/patterns/class-block-patterns.php b/inc/classes/patterns/class-block-patterns.php new file mode 100644 index 00000000..2db8c5e2 --- /dev/null +++ b/inc/classes/patterns/class-block-patterns.php @@ -0,0 +1,98 @@ + array( + 'label' => __( 'Featured', 'elementary' ), + ), + 'footer' => array( + 'label' => __( 'Footer', 'elementary' ), + ), + 'query' => array( + 'label' => __( 'Query', 'elementary' ), + ), + ); + + /** + * Filters the block pattern categories. + * + * @since 1.0.0 + * + * @param array $block_pattern_categories Array of block pattern categories. + */ + $block_pattern_categories = apply_filters( 'elementary_block_patterns_categories', $block_pattern_categories ); + + foreach ( $block_pattern_categories as $name => $properties ) { + if ( ! WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( $name ) ) { + register_block_pattern_category( $name, $properties ); + } + } + } + + /** + * Register block patterns. + * + * @since 1.0.0 + */ + public function elementary_register_block_patterns() { + $block_patterns_classes = array( + 'footer' => 'Footer', + 'hidden-404' => 'Hidden_404', + ); + + /** + * Filters the theme block patterns. + * + * @since 1.0.0 + * + * @param array $block_patterns The theme block patterns. + */ + $block_patterns = apply_filters( 'elementary_block_patterns', $block_patterns_classes ); + + foreach ( $block_patterns as $name => $class ) { + if ( ! WP_Block_Patterns_Registry::get_instance()->is_registered( $name ) ) { + $class = self::BLOCK_CONTENT_NAMESPACE . $class; + register_block_pattern( + self::PATTERN_NAMESPACE . '/' . $name, + ( new $class() )->block_pattern() + ); + } + } + } +} From fda96b8aac61c8eca738d0c373f961a557d82e80 Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Mon, 11 Apr 2022 19:44:56 +0530 Subject: [PATCH 5/7] Add file to define helper functions inside theme --- inc/helpers/custom-functions.php | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 inc/helpers/custom-functions.php diff --git a/inc/helpers/custom-functions.php b/inc/helpers/custom-functions.php new file mode 100644 index 00000000..701cb0db --- /dev/null +++ b/inc/helpers/custom-functions.php @@ -0,0 +1,8 @@ + Date: Mon, 11 Apr 2022 19:45:26 +0530 Subject: [PATCH 6/7] Add theme functions.php file --- functions.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 functions.php diff --git a/functions.php b/functions.php new file mode 100644 index 00000000..91650b22 --- /dev/null +++ b/functions.php @@ -0,0 +1,46 @@ +get( 'Version' ) ); +endif; + +if ( ! defined( 'ELEMENTARY_TEMP_DIR' ) ) : + define( 'ELEMENTARY_TEMP_DIR', untrailingslashit( get_template_directory() ) ); +endif; + +if ( ! defined( 'ELEMENTARY_BUILD_URI' ) ) : + define( 'ELEMENTARY_BUILD_URI', untrailingslashit( get_template_directory_uri() ) . '/assets/build' ); +endif; + +if ( ! defined( 'ELEMENTARY_BUILD_DIR' ) ) : + define( 'ELEMENTARY_BUILD_DIR', untrailingslashit( get_template_directory() ) . '/assets/build' ); +endif; + +if ( ! function_exists( 'elementary_support' ) ) : + /** + * Add required theme support. + * + * @since 1.0.0 + */ + function elementary_support() { + // Add support for core block styles. + add_theme_support( 'wp-block-styles' ); + } + +endif; + +add_action( 'after_setup_theme', 'elementary_support' ); + +require_once ELEMENTARY_TEMP_DIR . '/vendor/autoload.php'; + +// Add block patterns. +$elementary_block_patterns_register = new \Elementary\Patterns\Block_Patterns(); +add_action( 'init', array( $elementary_block_patterns_register, 'elementary_register_block_patterns_categories' ) ); +add_action( 'init', array( $elementary_block_patterns_register, 'elementary_register_block_patterns' ) ); From 7d46f80606a82a0176fb146baae2bc06b07e880d Mon Sep 17 00:00:00 2001 From: thelovekesh Date: Mon, 11 Apr 2022 19:46:07 +0530 Subject: [PATCH 7/7] Add autoloading of classes inside inc dir --- composer.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/composer.json b/composer.json index 86ae44db..4dc4b5cd 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,14 @@ "dealerdirect/phpcodesniffer-composer-installer": true } }, + "autoload": { + "classmap": [ + "inc/" + ], + "files": [ + "inc/helpers/custom-functions.php" + ] + }, "autoload-dev": { "psr-4": { "Elementary\\Tests\\": "tests/php/"