diff --git a/composer.json b/composer.json index 0c401e9..5885ec4 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,7 @@ "require": { "newfold-labs/wp-module-installer": "^1.1", "newfold-labs/wp-module-data": "^2.4.3", + "newfold-labs/wp-module-patterns": "^0.1.12", "newfold-labs/wp-module-ai": "^1.0.4", "wp-forge/wp-upgrade-handler": "^1.0", "mustache/mustache": "^2.14" diff --git a/composer.lock b/composer.lock index b76c877..c245a1e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a51d9791ffca6d77413ac5106c009021", + "content-hash": "4e92790391dd445c3bb55bbe4a4b1563", "packages": [ { "name": "mustache/mustache", @@ -192,6 +192,56 @@ }, "time": "2023-09-18T06:42:43+00:00" }, + { + "name": "newfold-labs/wp-module-patterns", + "version": "0.1.12", + "source": { + "type": "git", + "url": "https://github.com/newfold-labs/wp-module-patterns.git", + "reference": "6f4189c97a9e37f24531af8cfae986041d4b613b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/newfold-labs/wp-module-patterns/zipball/6f4189c97a9e37f24531af8cfae986041d4b613b", + "reference": "6f4189c97a9e37f24531af8cfae986041d4b613b", + "shasum": "" + }, + "require-dev": { + "newfold-labs/wp-php-standards": "^1.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "NewfoldLabs\\WP\\Module\\Patterns\\": "includes" + }, + "files": [ + "bootstrap.php" + ] + }, + "scripts": { + "lint": [ + "vendor/bin/phpcs . --ignore=*/build/* --standard=Newfold -d error_reporting=\"E_ALL&~E_DEPRECATED\"" + ], + "clean": [ + "vendor/bin/phpcbf . --ignore=*/build/* --standard=Newfold -d error_reporting=\"E_ALL&~E_DEPRECATED\"" + ] + }, + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "Hristina Conjic", + "email": "hristina.conjic@newfold.com" + } + ], + "description": "WordPress Cloud Patterns", + "support": { + "source": "https://github.com/newfold-labs/wp-module-patterns/tree/0.1.12", + "issues": "https://github.com/newfold-labs/wp-module-patterns/issues" + }, + "time": "2024-01-03T21:56:57+00:00" + }, { "name": "wp-forge/wp-query-builder", "version": "1.0.3", diff --git a/includes/Services/FlowService.php b/includes/Services/FlowService.php index cbeddea..e6fd1ea 100644 --- a/includes/Services/FlowService.php +++ b/includes/Services/FlowService.php @@ -423,4 +423,14 @@ public static function get_experience_level() { $data = self::read_data_from_wp_option( false ); return isset( $data['data']['wpComfortLevel'] ) ? $data['data']['wpComfortLevel'] : false; } + + /** + * Fetches the homepages generated in the Sitegen flow. + * + * @return false|array + */ + public static function get_sitegen_homepages() { + $data = self::read_data_from_wp_option( false ); + return ! empty( $data['sitegen']['homepages']['data'] ) ? $data['sitegen']['homepages']['data'] : false; + } } diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index 3d3dbb8..adbac05 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -9,6 +9,7 @@ use NewfoldLabs\WP\Module\Onboarding\Data\Themes; use NewfoldLabs\WP\Module\Onboarding\Data\Themes\Colors; use NewfoldLabs\WP\Module\Onboarding\Data\Themes\Fonts; +use NewfoldLabs\WP\Module\Patterns\SiteClassification as PatternsSiteClassification; /** * Class SiteGenService @@ -252,7 +253,6 @@ public static function generate_child_theme( $data ) { } return true; - } /** @@ -332,7 +332,7 @@ public static function get_customize_sidebar_data() { ), 'color_palette' ); - $font_pair = self::instantiate_site_meta( + $font_pair = self::instantiate_site_meta( array( 'site_description' => $prompt, ), @@ -350,10 +350,85 @@ public static function get_customize_sidebar_data() { $default_design = Fonts::get_sitegen_default_design_data(); return array( - 'design' => $default_design, + 'design' => $default_design, 'colorPalettes' => $color_palette, - 'designStyles' => $font_pair, + 'designStyles' => $font_pair, ); } + /** + * Filters Wonder Blocks transients before they are set. + * + * @return void + */ + public static function pre_set_filter_wonder_blocks_transients() { + $args = wp_parse_args( + array( + 'primary_type' => PatternsSiteClassification::get_primary_type(), + 'secondary_type' => PatternsSiteClassification::get_secondary_type(), + ) + ); + $id = md5( serialize( $args ) ); + + \add_action( "pre_set_transient_wba_templates_{$id}", array( __CLASS__, 'filter_wonder_blocks_templates_transient' ), 10, 1 ); + \add_action( 'pre_set_transient_wba_templates_categories', array( __CLASS__, 'filter_wonder_blocks_categories_transient' ), 10, 1 ); + } + + /** + * Filters the Wonder Blocks templates transient. + * + * @param array $value The original value of the transient. + * @return array + */ + public static function filter_wonder_blocks_templates_transient( $value ) { + if ( empty( $value ) || ! is_array( $value ) ) { + return $value; + } + + $homepages = FlowService::get_sitegen_homepages(); + if ( ! $homepages ) { + return $value; + } + + foreach ( $homepages as $slug => $data ) { + array_push( + $value, + array( + 'id' => $slug, + 'slug' => $slug, + 'description' => $slug, + 'content' => $data['content'], + 'categories' => array( 'home', 'featured' ), + ) + ); + } + + return $value; + } + + /** + * Filters the Wonder Blocks categories transient. + * + * @param array $value The original value of the transient. + * @return array + */ + public static function filter_wonder_blocks_categories_transient( $value ) { + if ( empty( $value ) || ! is_array( $value ) ) { + return $value; + } + + $homepages = FlowService::get_sitegen_homepages(); + if ( ! $homepages ) { + return $value; + } + + foreach ( $value as $index => $category ) { + if ( 'home' === $category['title'] ) { + $category['count'] = $category['count'] + count( $homepages ); + $value[ $index ] = $category; + } + } + + return $value; + } }