From bde1f75ac65469e340a72ce9c359a6590e48b0a7 Mon Sep 17 00:00:00 2001 From: Swanand01 Date: Wed, 22 May 2024 16:21:14 +0530 Subject: [PATCH 01/17] Use `wp_prime_option_caches_by_group` to reduce db queries --- includes/Settings.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/includes/Settings.php b/includes/Settings.php index d61e424c977e..f1af2d1bc20c 100644 --- a/includes/Settings.php +++ b/includes/Settings.php @@ -438,6 +438,11 @@ public function register(): void { * @return string|array|bool|int Setting value. */ public function get_setting( string $key, $default_value = false ) { + if ( \function_exists( 'wp_prime_option_caches_by_group' ) ) { + wp_prime_option_caches_by_group( self::SETTING_GROUP ); + wp_prime_option_caches_by_group( self::SETTING_GROUP_EXPERIMENTS ); + } + // Distinguish between `false` as a default, and not passing one, just like WordPress. $passed_default = \func_num_args() > 1; From a87297d2dee45f99b2d7cb2e770dc5c10dbd0802 Mon Sep 17 00:00:00 2001 From: Swanand01 Date: Wed, 22 May 2024 16:42:09 +0530 Subject: [PATCH 02/17] Add `prime_option_caches` and call it on `init` --- includes/Settings.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/includes/Settings.php b/includes/Settings.php index f1af2d1bc20c..c5904103d913 100644 --- a/includes/Settings.php +++ b/includes/Settings.php @@ -163,6 +163,19 @@ class Settings implements Service, Registerable, PluginUninstallAware { */ public function __construct( Shopping_Vendors $shopping_vendors ) { $this->shopping_vendors = $shopping_vendors; + add_action( 'init', [ $this, 'prime_option_caches' ] ); + } + + /** + * Primes option caches for specified groups if the function exists. + * + * @since 1.37.0 + */ + public function prime_option_caches(): void { + if ( \function_exists( 'wp_prime_option_caches_by_group' ) ) { + wp_prime_option_caches_by_group( self::SETTING_GROUP ); + wp_prime_option_caches_by_group( self::SETTING_GROUP_EXPERIMENTS ); + } } /** @@ -438,11 +451,6 @@ public function register(): void { * @return string|array|bool|int Setting value. */ public function get_setting( string $key, $default_value = false ) { - if ( \function_exists( 'wp_prime_option_caches_by_group' ) ) { - wp_prime_option_caches_by_group( self::SETTING_GROUP ); - wp_prime_option_caches_by_group( self::SETTING_GROUP_EXPERIMENTS ); - } - // Distinguish between `false` as a default, and not passing one, just like WordPress. $passed_default = \func_num_args() > 1; From 0a10307af5a2d920ad3e067f29ae8f1c3c10d386 Mon Sep 17 00:00:00 2001 From: Swanand01 Date: Wed, 22 May 2024 17:05:33 +0530 Subject: [PATCH 03/17] Move `add_action` to `register` --- includes/Settings.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/Settings.php b/includes/Settings.php index c5904103d913..8e4246dded65 100644 --- a/includes/Settings.php +++ b/includes/Settings.php @@ -163,7 +163,6 @@ class Settings implements Service, Registerable, PluginUninstallAware { */ public function __construct( Shopping_Vendors $shopping_vendors ) { $this->shopping_vendors = $shopping_vendors; - add_action( 'init', [ $this, 'prime_option_caches' ] ); } /** @@ -437,6 +436,8 @@ public function register(): void { ], ] ); + + add_action( 'init', [ $this, 'prime_option_caches' ] ); } /** From 944791626ae9f0039b4adc10a4cac7e9cf05a0ec Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 23 May 2024 10:38:38 +0200 Subject: [PATCH 04/17] Rewrite hook logic in Site Kit class Avoids early database calls --- includes/Integrations/Site_Kit.php | 36 ++++++++++++++++++------------ 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/includes/Integrations/Site_Kit.php b/includes/Integrations/Site_Kit.php index 145a05e5ccbc..525178b41fc3 100644 --- a/includes/Integrations/Site_Kit.php +++ b/includes/Integrations/Site_Kit.php @@ -95,21 +95,29 @@ public function __construct( Analytics $analytics, Context $context, Plugin_Stat public function register(): void { add_filter( 'googlesitekit_amp_gtag_opt', [ $this, 'filter_site_kit_gtag_opt' ] ); - $handler = $this->settings->get_setting( $this->settings::SETTING_NAME_TRACKING_HANDLER ); - - if ( 'web-stories' === $handler ) { - add_filter( - 'googlesitekit_analytics-4_tag_amp_blocked', - function ( $blocked ) { - if ( $this->context->is_web_story() ) { - return true; - } - return $blocked; + add_filter( + 'googlesitekit_analytics-4_tag_amp_blocked', + function ( $blocked ) { + $handler = $this->settings->get_setting( $this->settings::SETTING_NAME_TRACKING_HANDLER ); + + if ( 'web-stories' === $handler && $this->context->is_web_story() ) { + return true; } - ); - } elseif ( 'site-kit' === $handler && $this->is_analytics_module_active() ) { - remove_action( 'web_stories_print_analytics', [ $this->analytics, 'print_analytics_tag' ] ); - } + + return $blocked; + } + ); + + add_action( + 'web_stories_print_analytics', + function () { + $handler = $this->settings->get_setting( $this->settings::SETTING_NAME_TRACKING_HANDLER ); + if ( 'site-kit' === $handler && $this->is_analytics_module_active() ) { + remove_action( 'web_stories_print_analytics', [ $this->analytics, 'print_analytics_tag' ] ); + } + }, + 5 + ); } /** From f402b5caa1fe6b4903ea39d6aaad76659bbc7968 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 23 May 2024 10:53:13 +0200 Subject: [PATCH 05/17] Apply fixes --- includes/Integrations/Site_Kit.php | 2 +- tests/phpunit/integration/tests/Integrations/Site_Kit.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Integrations/Site_Kit.php b/includes/Integrations/Site_Kit.php index 525178b41fc3..69c9aee422dc 100644 --- a/includes/Integrations/Site_Kit.php +++ b/includes/Integrations/Site_Kit.php @@ -110,7 +110,7 @@ function ( $blocked ) { add_action( 'web_stories_print_analytics', - function () { + function (): void { $handler = $this->settings->get_setting( $this->settings::SETTING_NAME_TRACKING_HANDLER ); if ( 'site-kit' === $handler && $this->is_analytics_module_active() ) { remove_action( 'web_stories_print_analytics', [ $this->analytics, 'print_analytics_tag' ] ); diff --git a/tests/phpunit/integration/tests/Integrations/Site_Kit.php b/tests/phpunit/integration/tests/Integrations/Site_Kit.php index 27d22a9cb1a0..2123301171e5 100644 --- a/tests/phpunit/integration/tests/Integrations/Site_Kit.php +++ b/tests/phpunit/integration/tests/Integrations/Site_Kit.php @@ -72,7 +72,7 @@ public function test_init_analytics_module_active(): void { $this->instance->register(); $this->assertSame( 10, has_filter( 'googlesitekit_amp_gtag_opt', [ $this->instance, 'filter_site_kit_gtag_opt' ] ) ); - $this->assertFalse( has_action( 'web_stories_print_analytics', [ $analytics, 'print_analytics_tag' ] ) ); + $this->assertSame( 5, has_action( 'web_stories_print_analytics', [ $analytics, 'print_analytics_tag' ] ) ); } /** From 87d43788ad4220e6e2a13e14df7bdb03c57da43b Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 23 May 2024 11:00:47 +0200 Subject: [PATCH 06/17] Fix test --- tests/phpunit/integration/tests/Integrations/Site_Kit.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/integration/tests/Integrations/Site_Kit.php b/tests/phpunit/integration/tests/Integrations/Site_Kit.php index 2123301171e5..fd95689b6990 100644 --- a/tests/phpunit/integration/tests/Integrations/Site_Kit.php +++ b/tests/phpunit/integration/tests/Integrations/Site_Kit.php @@ -72,7 +72,7 @@ public function test_init_analytics_module_active(): void { $this->instance->register(); $this->assertSame( 10, has_filter( 'googlesitekit_amp_gtag_opt', [ $this->instance, 'filter_site_kit_gtag_opt' ] ) ); - $this->assertSame( 5, has_action( 'web_stories_print_analytics', [ $analytics, 'print_analytics_tag' ] ) ); + $this->assertSame( 10, has_action( 'web_stories_print_analytics', [ $analytics, 'print_analytics_tag' ] ) ); } /** From 56dcdcf0f31a6c546e716ce32809fe70b0d4a7d0 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 23 May 2024 11:16:07 +0200 Subject: [PATCH 07/17] Only load Tracking class on stories admin screens Avoids unnecessary database queries on other screens --- includes/Tracking.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/includes/Tracking.php b/includes/Tracking.php index 6184c09bb6ea..24a522af071a 100644 --- a/includes/Tracking.php +++ b/includes/Tracking.php @@ -96,6 +96,13 @@ class Tracking extends Service_Base { */ private WooCommerce $woocommerce; + /** + * Context instance. + * + * @var Context Context instance. + */ + private Context $context; + /** * Tracking constructor. * @@ -107,6 +114,7 @@ class Tracking extends Service_Base { * @param Settings $settings Settings instance. * @param Preferences $preferences Preferences instance. * @param WooCommerce $woocommerce WooCommerce instance. + * @param Context $context Context instance. */ public function __construct( Experiments $experiments, @@ -114,7 +122,8 @@ public function __construct( Assets $assets, Settings $settings, Preferences $preferences, - WooCommerce $woocommerce + WooCommerce $woocommerce, + Context $context ) { $this->assets = $assets; $this->experiments = $experiments; @@ -122,6 +131,7 @@ public function __construct( $this->settings = $settings; $this->preferences = $preferences; $this->woocommerce = $woocommerce; + $this->context = $context; } /** @@ -132,6 +142,10 @@ public function __construct( * @since 1.0.0 */ public function register(): void { + if ( ! $this->context->is_story_editor() && 'web-story' !== $this->context->get_screen_post_type() ) { + return; + } + // By not passing an actual script src we can print only the inline script. $this->assets->register_script( self::SCRIPT_HANDLE, @@ -155,7 +169,7 @@ public function register(): void { * @return string Registration action to use. */ public static function get_registration_action(): string { - return 'admin_init'; + return 'admin_head'; } /** From 3b06384806e2a4880d82399114772345357070f7 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 23 May 2024 11:16:42 +0200 Subject: [PATCH 08/17] Do not use `get_dashboard_settings` for adding admin menu Avoids database query by fetching plugin status information --- includes/Admin/Dashboard.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/Admin/Dashboard.php b/includes/Admin/Dashboard.php index 78af490f3f62..634a81c0ca8f 100644 --- a/includes/Admin/Dashboard.php +++ b/includes/Admin/Dashboard.php @@ -237,7 +237,14 @@ public function get_hook_suffix( string $key ) { public function add_menu_page(): void { $parent = 'edit.php?post_type=' . $this->story_post_type->get_slug(); - $settings = $this->get_dashboard_settings(); + // Not using get_dashboard_settings() to avoid an extra database query. + + $settings = [ + 'canViewDefaultTemplates' => true, + ]; + + /** This filter is documented in includes/Admin/Dashboard.php */ + $settings = apply_filters( 'web_stories_dashboard_settings', $settings ); /** * The edit_posts capability. From 1a9733b9854a9f56cc0eea4dc728f00500cb5120 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 23 May 2024 11:27:26 +0200 Subject: [PATCH 09/17] Delay getting `web_stories_archive_page_id` option --- includes/Story_Post_Type.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/includes/Story_Post_Type.php b/includes/Story_Post_Type.php index a7d50e786111..81d8d6a2b938 100644 --- a/includes/Story_Post_Type.php +++ b/includes/Story_Post_Type.php @@ -288,19 +288,17 @@ public function clear_user_posts_count( int $post_id, WP_Post $post ): void { */ public function get_has_archive() { $archive_page_option = $this->settings->get_setting( $this->settings::SETTING_NAME_ARCHIVE ); - $custom_archive_page_id = (int) $this->settings->get_setting( $this->settings::SETTING_NAME_ARCHIVE_PAGE_ID ); $has_archive = true; if ( 'disabled' === $archive_page_option ) { $has_archive = false; - } elseif ( - 'custom' === $archive_page_option && - $custom_archive_page_id && - 'publish' === get_post_status( $custom_archive_page_id ) - ) { - $uri = get_page_uri( $custom_archive_page_id ); - if ( $uri ) { - $has_archive = urldecode( $uri ); + } elseif ( 'custom' === $archive_page_option ) { + $custom_archive_page_id = (int) $this->settings->get_setting( $this->settings::SETTING_NAME_ARCHIVE_PAGE_ID ); + if ( $custom_archive_page_id && 'publish' === get_post_status( $custom_archive_page_id ) ) { + $uri = get_page_uri( $custom_archive_page_id ); + if ( $uri ) { + $has_archive = urldecode( $uri ); + } } } From 0445d89cfda518e8758634ebf156afa73abfcdee Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 23 May 2024 12:29:30 +0200 Subject: [PATCH 10/17] Fix test --- tests/phpunit/integration/tests/Tracking.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/integration/tests/Tracking.php b/tests/phpunit/integration/tests/Tracking.php index a168b642bd76..f9de6755f352 100644 --- a/tests/phpunit/integration/tests/Tracking.php +++ b/tests/phpunit/integration/tests/Tracking.php @@ -26,6 +26,7 @@ use Google\Web_Stories\Integrations\Site_Kit; use Google\Web_Stories\Integrations\WooCommerce; use Google\Web_Stories\Settings; +use Google\Web_Stories\Story_Post_Type; use Google\Web_Stories\User\Preferences; use PHPUnit\Framework\MockObject\MockObject; use WP_UnitTest_Factory; @@ -69,6 +70,7 @@ public function set_up(): void { $assets = $this->injector->make( Assets::class ); $settings = $this->injector->make( Settings::class ); $preferences = $this->injector->make( Preferences::class ); + $context = $this->injector->make( \Google\Web_Stories\Context::class ); $this->woocommerce = $this->createMock( WooCommerce::class ); $this->instance = new \Google\Web_Stories\Tracking( $this->experiments, @@ -76,7 +78,8 @@ public function set_up(): void { $assets, $settings, $preferences, - $this->woocommerce + $this->woocommerce, + $context ); } @@ -84,6 +87,10 @@ public function set_up(): void { * @covers ::register */ public function test_register_tracking_script(): void { + global $current_screen; + + $current_screen = convert_to_screen( Story_Post_Type::POST_TYPE_SLUG ); + $this->site_kit->method( 'get_plugin_status' )->willReturn( [ 'installed' => true, From 4943a1ee43e5bc2bb3741de78e3ffe26fc90b153 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 23 May 2024 12:31:00 +0200 Subject: [PATCH 11/17] Load on frontend only --- includes/Integrations/Core_Themes_Support.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/Integrations/Core_Themes_Support.php b/includes/Integrations/Core_Themes_Support.php index a199e3087176..3ac771a393b7 100644 --- a/includes/Integrations/Core_Themes_Support.php +++ b/includes/Integrations/Core_Themes_Support.php @@ -134,6 +134,9 @@ public function add_core_theme_classes( $classes ) { * @since 1.5.0 */ public function register(): void { + if ( is_admin() ) { + return; + } if ( ! \in_array( get_stylesheet(), self::$supported_themes, true ) ) { return; From 597433b7e4f30e17ac2473b46465356e8e76e41c Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 23 May 2024 12:58:21 +0200 Subject: [PATCH 12/17] Always registers the script --- includes/Tracking.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/Tracking.php b/includes/Tracking.php index 24a522af071a..f59c9a43e19a 100644 --- a/includes/Tracking.php +++ b/includes/Tracking.php @@ -137,15 +137,11 @@ public function __construct( /** * Initializes tracking. * - * Registers the setting in WordPress. + * Registers the script in WordPress. * * @since 1.0.0 */ public function register(): void { - if ( ! $this->context->is_story_editor() && 'web-story' !== $this->context->get_screen_post_type() ) { - return; - } - // By not passing an actual script src we can print only the inline script. $this->assets->register_script( self::SCRIPT_HANDLE, @@ -155,6 +151,10 @@ public function register(): void { false ); + if ( ! $this->context->is_story_editor() && 'web-story' !== $this->context->get_screen_post_type() ) { + return; + } + wp_add_inline_script( self::SCRIPT_HANDLE, 'window.webStoriesTrackingSettings = ' . wp_json_encode( $this->get_settings() ) . ';' From 6fd4e5513d79add7b6bb387189195b1dfedf66b6 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 23 May 2024 12:58:28 +0200 Subject: [PATCH 13/17] Fix test --- tests/phpunit/integration/tests/Tracking.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/integration/tests/Tracking.php b/tests/phpunit/integration/tests/Tracking.php index f9de6755f352..1fd7b1f821a3 100644 --- a/tests/phpunit/integration/tests/Tracking.php +++ b/tests/phpunit/integration/tests/Tracking.php @@ -22,6 +22,7 @@ use _WP_Dependency; use Google\Web_Stories\Assets; +use Google\Web_Stories\Context; use Google\Web_Stories\Experiments; use Google\Web_Stories\Integrations\Site_Kit; use Google\Web_Stories\Integrations\WooCommerce; @@ -70,7 +71,7 @@ public function set_up(): void { $assets = $this->injector->make( Assets::class ); $settings = $this->injector->make( Settings::class ); $preferences = $this->injector->make( Preferences::class ); - $context = $this->injector->make( \Google\Web_Stories\Context::class ); + $context = $this->injector->make( Context::class ); $this->woocommerce = $this->createMock( WooCommerce::class ); $this->instance = new \Google\Web_Stories\Tracking( $this->experiments, @@ -90,7 +91,7 @@ public function test_register_tracking_script(): void { global $current_screen; $current_screen = convert_to_screen( Story_Post_Type::POST_TYPE_SLUG ); - + $this->site_kit->method( 'get_plugin_status' )->willReturn( [ 'installed' => true, From 00f25862ccfb617bf7fa14f84ca4abe0a6b9914c Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 23 May 2024 12:59:03 +0200 Subject: [PATCH 14/17] Fix alignment --- includes/Story_Post_Type.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Story_Post_Type.php b/includes/Story_Post_Type.php index 81d8d6a2b938..967e3ca0d4c2 100644 --- a/includes/Story_Post_Type.php +++ b/includes/Story_Post_Type.php @@ -287,8 +287,8 @@ public function clear_user_posts_count( int $post_id, WP_Post $post ): void { * @return bool|string Whether the post type should have an archive, or archive slug. */ public function get_has_archive() { - $archive_page_option = $this->settings->get_setting( $this->settings::SETTING_NAME_ARCHIVE ); - $has_archive = true; + $archive_page_option = $this->settings->get_setting( $this->settings::SETTING_NAME_ARCHIVE ); + $has_archive = true; if ( 'disabled' === $archive_page_option ) { $has_archive = false; From fd6143f8d8a3a2e4b1df4c2f6cdc54c723cc7f10 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 23 May 2024 13:29:40 +0200 Subject: [PATCH 15/17] Remove now obsolete workaround --- includes/Settings.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/includes/Settings.php b/includes/Settings.php index 8e4246dded65..6487b28c4ee1 100644 --- a/includes/Settings.php +++ b/includes/Settings.php @@ -357,9 +357,6 @@ public function register(): void { 'additionalProperties' => true, ], ], - // WPGraphQL errors when encountering array or object types. - // See https://github.com/wp-graphql/wp-graphql/issues/2065. - 'show_in_graphql' => false, ] ); From 097080686f92158a6bf60bff25edc8658c737742 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 23 May 2024 13:33:00 +0200 Subject: [PATCH 16/17] Register customizer settings --- includes/Admin/Customizer.php | 4 +++- includes/Integrations/Core_Themes_Support.php | 11 ++++----- includes/Settings.php | 24 +++++++++++++++---- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/includes/Admin/Customizer.php b/includes/Admin/Customizer.php index eeb0f9e00c5a..9c3b1f46fdee 100644 --- a/includes/Admin/Customizer.php +++ b/includes/Admin/Customizer.php @@ -548,13 +548,15 @@ public function validate_number_of_columns( WP_Error $validity, int $value ): WP * @since 1.5.0 */ public function render_stories(): string { + // Not using Settings::get_setting() to avoid calling rest_sanitize_value_from_schema(). + /** * Render options. * * @var array $options * @phpstan-var StoryAttributes */ - $options = (array) $this->settings->get_setting( self::STORY_OPTION ); + $options = (array) get_option( self::STORY_OPTION ); if ( empty( $options['show_stories'] ) || true !== $options['show_stories'] ) { return ''; diff --git a/includes/Integrations/Core_Themes_Support.php b/includes/Integrations/Core_Themes_Support.php index 3ac771a393b7..08c98115197e 100644 --- a/includes/Integrations/Core_Themes_Support.php +++ b/includes/Integrations/Core_Themes_Support.php @@ -30,7 +30,6 @@ use Google\Web_Stories\Admin\Customizer; use Google\Web_Stories\Assets; -use Google\Web_Stories\Renderer\Stories\Renderer; use Google\Web_Stories\Service_Base; use function Google\Web_Stories\render_theme_stories; @@ -98,7 +97,7 @@ public function extend_theme_support(): void { public function embed_web_stories(): void { $stylesheet = get_stylesheet(); if ( is_readable( sprintf( '%sassets/css/web-stories-theme-style-%s.css', WEBSTORIES_PLUGIN_DIR_PATH, $stylesheet ) ) ) { - $this->assets->enqueue_style_asset( 'web-stories-theme-style-' . $stylesheet, [ Renderer::STYLE_HANDLE ] ); + $this->assets->enqueue_style_asset( 'web-stories-theme-style-' . $stylesheet, [] ); } ?>
@@ -134,16 +133,14 @@ public function add_core_theme_classes( $classes ) { * @since 1.5.0 */ public function register(): void { - if ( is_admin() ) { - return; - } - if ( ! \in_array( get_stylesheet(), self::$supported_themes, true ) ) { return; } $this->extend_theme_support(); + // Not using Settings::get_setting() to avoid calling rest_sanitize_value_from_schema(). + /** * Customizer options. * @@ -168,6 +165,6 @@ public function register(): void { * @return string Registration action to use. */ public static function get_registration_action(): string { - return 'after_setup_theme'; + return 'wp_head'; } } diff --git a/includes/Settings.php b/includes/Settings.php index 6487b28c4ee1..f7a6ffd9d9a4 100644 --- a/includes/Settings.php +++ b/includes/Settings.php @@ -149,6 +149,11 @@ class Settings implements Service, Registerable, PluginUninstallAware { */ public const SETTING_NAME_TRACKING_HANDLER = 'web_stories_ga_tracking_handler'; + /** + * Customizer settings. + */ + public const SETTING_NAME_CUSTOMIZER_SETTINGS = 'web_stories_customizer_settings'; + /** * Shopping_Vendors instance. * @@ -348,10 +353,10 @@ public function register(): void { self::SETTING_GROUP_EXPERIMENTS, self::SETTING_NAME_EXPERIMENTS, [ - 'description' => __( 'Experiments', 'web-stories' ), - 'type' => 'object', - 'default' => [], - 'show_in_rest' => [ + 'description' => __( 'Experiments', 'web-stories' ), + 'type' => 'object', + 'default' => [], + 'show_in_rest' => [ 'schema' => [ 'properties' => [], 'additionalProperties' => true, @@ -434,6 +439,17 @@ public function register(): void { ] ); + register_setting( + self::SETTING_GROUP, + self::SETTING_NAME_CUSTOMIZER_SETTINGS, + [ + 'description' => __( 'Customizer settings', 'web-stories' ), + 'type' => 'array', + 'default' => [], + 'show_in_rest' => false, + ] + ); + add_action( 'init', [ $this, 'prime_option_caches' ] ); } From 1080062d68722b80b2894dcfc6646ada2c6bc9bd Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 23 May 2024 13:43:04 +0200 Subject: [PATCH 17/17] Remove now obsolete dependency --- includes/Admin/Customizer.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/includes/Admin/Customizer.php b/includes/Admin/Customizer.php index 9c3b1f46fdee..98a582a5df1a 100644 --- a/includes/Admin/Customizer.php +++ b/includes/Admin/Customizer.php @@ -30,7 +30,6 @@ use Google\Web_Stories\Infrastructure\Conditional; use Google\Web_Stories\Service_Base; -use Google\Web_Stories\Settings; use Google\Web_Stories\Stories_Script_Data; use Google\Web_Stories\Story_Post_Type; use Google\Web_Stories\Story_Query; @@ -106,13 +105,6 @@ class Customizer extends Service_Base implements Conditional { */ private WP_Customize_Manager $wp_customize; - /** - * Settings instance. - * - * @var Settings Settings instance. - */ - private Settings $settings; - /** * Story_Post_Type instance. * @@ -132,17 +124,14 @@ class Customizer extends Service_Base implements Conditional { * * @since 1.12.0 * - * @param Settings $settings Settings instance. * @param Story_Post_Type $story_post_type Story_Post_Type instance. * @param Stories_Script_Data $stories_script_data Stories_Script_Data instance. * @return void */ public function __construct( - Settings $settings, Story_Post_Type $story_post_type, Stories_Script_Data $stories_script_data ) { - $this->settings = $settings; $this->story_post_type = $story_post_type; $this->stories_script_data = $stories_script_data; }