From 4ecae183cdcf249acb9ad7eafdd384448340641a Mon Sep 17 00:00:00 2001 From: Gergely Juhasz Date: Wed, 8 Nov 2023 18:32:32 +0100 Subject: [PATCH] Update the initial states to use the new settings class --- .../class-jetpack-redux-state-helper.php | 18 +++------- .../jetpack/class.jetpack-gutenberg.php | 15 ++++---- .../social/src/class-jetpack-social.php | 35 +++++++------------ 3 files changed, 22 insertions(+), 46 deletions(-) diff --git a/projects/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-redux-state-helper.php b/projects/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-redux-state-helper.php index 17b72d5a49cc9..27eeef08392f6 100644 --- a/projects/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-redux-state-helper.php +++ b/projects/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-redux-state-helper.php @@ -291,24 +291,14 @@ private static function get_gutenberg_initial_state() { * @return array|null */ public static function get_publicize_initial_state() { - $sig_settings = new Automattic\Jetpack\Publicize\Social_Image_Generator\Settings(); - $auto_conversion_settings = new Automattic\Jetpack\Publicize\Auto_Conversion\Settings(); + $jetpack_social_settings = new Automattic\Jetpack\Publicize\Jetpack_Social_Settings\Settings(); + $settings = $jetpack_social_settings->get_settings( true ); - if ( empty( $sig_settings ) && empty( $auto_conversion_settings ) ) { + if ( empty( $settings ) ) { return null; } - return array( - 'socialImageGeneratorSettings' => array( - 'available' => $sig_settings->is_available(), - 'enabled' => $sig_settings->is_enabled(), - 'defaultTemplate' => $sig_settings->get_default_template(), - ), - 'autoConversionSettings' => array( - 'available' => $auto_conversion_settings->is_available( 'image' ), - 'image' => $auto_conversion_settings->is_enabled( 'image' ), - ), - ); + return $settings; } /** diff --git a/projects/plugins/jetpack/class.jetpack-gutenberg.php b/projects/plugins/jetpack/class.jetpack-gutenberg.php index b9020571d4910..0f82b330e6511 100644 --- a/projects/plugins/jetpack/class.jetpack-gutenberg.php +++ b/projects/plugins/jetpack/class.jetpack-gutenberg.php @@ -732,24 +732,21 @@ public static function enqueue_block_editor_assets() { ); if ( Jetpack::is_module_active( 'publicize' ) && function_exists( 'publicize_init' ) ) { - $publicize = publicize_init(); - $sig_settings = new Automattic\Jetpack\Publicize\Social_Image_Generator\Settings(); - $auto_conversion_settings = new Automattic\Jetpack\Publicize\Auto_Conversion\Settings(); + $publicize = publicize_init(); + $jetpack_social_settings = new Automattic\Jetpack\Publicize\Jetpack_Social_Settings\Settings(); + $settings = $jetpack_social_settings->get_settings( true ); $initial_state['social'] = array( 'sharesData' => $publicize->get_publicize_shares_info( $blog_id ), 'hasPaidPlan' => $publicize->has_paid_plan(), 'isEnhancedPublishingEnabled' => $publicize->has_enhanced_publishing_feature(), - 'isSocialImageGeneratorAvailable' => $sig_settings->is_available(), - 'isSocialImageGeneratorEnabled' => $sig_settings->is_enabled(), + 'isSocialImageGeneratorAvailable' => $settings['socialImageGeneratorSettings']['available'], + 'isSocialImageGeneratorEnabled' => $settings['socialImageGeneratorSettings']['enabled'], 'dismissedNotices' => $publicize->get_dismissed_notices(), 'isInstagramConnectionSupported' => $publicize->has_instagram_connection_feature(), 'isMastodonConnectionSupported' => $publicize->has_mastodon_connection_feature(), 'isNextdoorConnectionSupported' => $publicize->has_nextdoor_connection_feature(), - 'autoConversionSettings' => array( - 'available' => $auto_conversion_settings->is_available( 'image' ), - 'image' => $auto_conversion_settings->is_enabled( 'image' ), - ), + 'autoConversionSettings' => $settings['autoConversionSettings'], 'jetpackSharingSettingsUrl' => esc_url_raw( admin_url( 'admin.php?page=jetpack#/sharing' ) ), ); } diff --git a/projects/plugins/social/src/class-jetpack-social.php b/projects/plugins/social/src/class-jetpack-social.php index a5ece3252cf84..ddfe2894d6717 100644 --- a/projects/plugins/social/src/class-jetpack-social.php +++ b/projects/plugins/social/src/class-jetpack-social.php @@ -229,13 +229,13 @@ public function initial_state() { ); if ( $this->is_connected() ) { - $sig_settings = new Automattic\Jetpack\Publicize\Social_Image_Generator\Settings(); - $auto_conversion_settings = new Automattic\Jetpack\Publicize\Auto_Conversion\Settings(); + $jetpack_social_settings = new Automattic\Jetpack\Publicize\Jetpack_Social_Settings\Settings(); + $settings = $jetpack_social_settings->get_settings( true ); $state = array_merge( $state, array( - 'jetpackSettings' => array( + 'jetpackSettings' => array( 'publicize_active' => self::is_publicize_active(), 'show_pricing_page' => self::should_show_pricing_page(), 'showNudge' => ! $publicize->has_paid_plan( true ), @@ -245,21 +245,13 @@ public function initial_state() { 'isMastodonConnectionSupported' => $publicize->has_mastodon_connection_feature(), 'isNextdoorConnectionSupported' => $publicize->has_nextdoor_connection_feature(), ), - 'connectionData' => array( + 'connectionData' => array( 'connections' => $publicize->get_all_connections_for_user(), // TODO: Sanitize the array 'adminUrl' => esc_url_raw( $publicize->publicize_connections_url( 'jetpack-social-connections-admin-page' ) ), ), - 'sharesData' => $publicize->get_publicize_shares_info( Jetpack_Options::get_option( 'id' ) ), - 'socialImageGeneratorSettings' => array( - 'available' => $sig_settings->is_available(), - 'enabled' => $sig_settings->is_enabled(), - 'defaultTemplate' => $sig_settings->get_default_template(), - ), - 'autoConversionSettings' => array( - 'available' => $auto_conversion_settings->is_available( 'image' ), - 'image' => $auto_conversion_settings->is_enabled( 'image' ), - ), - ) + 'sharesData' => $publicize->get_publicize_shares_info( Jetpack_Options::get_option( 'id' ) ), + ), + $settings ); } @@ -326,8 +318,8 @@ class_exists( 'Jetpack' ) || Assets::enqueue_script( 'jetpack-social-editor' ); - $sig_settings = ( new Automattic\Jetpack\Publicize\Social_Image_Generator\Settings() ); - $auto_conversion_settings = ( new Automattic\Jetpack\Publicize\Auto_Conversion\Settings() ); + $jetpack_social_settings = new Automattic\Jetpack\Publicize\Jetpack_Social_Settings\Settings(); + $settings = $jetpack_social_settings->get_settings( true ); wp_localize_script( 'jetpack-social-editor', @@ -344,12 +336,9 @@ class_exists( 'Jetpack' ) || ), 'hasPaidPlan' => $publicize->has_paid_plan(), 'isEnhancedPublishingEnabled' => $publicize->has_enhanced_publishing_feature(), - 'isSocialImageGeneratorAvailable' => $sig_settings->is_available(), - 'isSocialImageGeneratorEnabled' => $sig_settings->is_enabled(), - 'autoConversionSettings' => array( - 'available' => $auto_conversion_settings->is_available( 'image' ), - 'image' => $auto_conversion_settings->is_enabled( 'image' ), - ), + 'isSocialImageGeneratorAvailable' => $settings['socialImageGeneratorSettings']['available'], + 'isSocialImageGeneratorEnabled' => $settings['socialImageGeneratorSettings']['enabled'], + 'autoConversionSettings' => $settings['autoConversionSettings'], 'dismissedNotices' => $publicize->get_dismissed_notices(), 'isInstagramConnectionSupported' => $publicize->has_instagram_connection_feature(), 'isMastodonConnectionSupported' => $publicize->has_mastodon_connection_feature(),