diff --git a/projects/packages/publicize/src/class-publicize-base.php b/projects/packages/publicize/src/class-publicize-base.php index d346ff80ee608..71057588154e8 100644 --- a/projects/packages/publicize/src/class-publicize-base.php +++ b/projects/packages/publicize/src/class-publicize-base.php @@ -1133,7 +1133,7 @@ public function register_post_meta() { 'single' => true, 'default' => array( 'image_generator_settings' => array( - 'template' => ( new Social_Image_Generator\Settings() )->get_default_template(), + 'template' => ( new Jetpack_Social_Settings\Settings() )->sig_get_default_template(), 'enabled' => false, ), ), diff --git a/projects/packages/publicize/src/class-publicize-setup.php b/projects/packages/publicize/src/class-publicize-setup.php index f81ff58154171..2c8663f0490f8 100644 --- a/projects/packages/publicize/src/class-publicize-setup.php +++ b/projects/packages/publicize/src/class-publicize-setup.php @@ -42,7 +42,8 @@ public static function on_jetpack_feature_publicize_enabled() { add_action( 'rest_api_init', array( new Connections_Post_Field(), 'register_fields' ), 5 ); add_action( 'rest_api_init', array( new REST_Controller(), 'register_rest_routes' ) ); add_action( 'current_screen', array( static::class, 'init_sharing_limits' ) ); - add_action( 'rest_api_init', array( new Auto_Conversion\REST_Settings_Controller(), 'register_routes' ) ); + add_action( 'rest_api_init', array( new Jetpack_Social_Settings\Settings(), 'register_settings' ) ); + add_action( 'admin_init', array( new Jetpack_Social_Settings\Settings(), 'register_settings' ) ); ( new Social_Image_Generator\Setup() )->init(); } diff --git a/projects/packages/publicize/src/social-image-generator/class-setup.php b/projects/packages/publicize/src/social-image-generator/class-setup.php index de0c55ec42dc3..89c29c5c13e13 100644 --- a/projects/packages/publicize/src/social-image-generator/class-setup.php +++ b/projects/packages/publicize/src/social-image-generator/class-setup.php @@ -7,6 +7,8 @@ namespace Automattic\Jetpack\Publicize\Social_Image_Generator; +use Automattic\Jetpack\Publicize\Jetpack_Social_Settings\Settings; + /** * Class for setting up Social Image Generator-related functionality. */ @@ -15,7 +17,7 @@ class Setup { * Initialise SIG-related functionality. */ public function init() { - if ( ! ( new Settings() )->is_available() ) { + if ( ! ( new Settings() )->is_sig_available() ) { return; } @@ -23,7 +25,6 @@ public function init() { // We're using the `wp_after_insert_post` hook because we need access to the updated post meta. By using the default priority // of 10 we make sure that our code runs before Sync processes the post. add_action( 'wp_after_insert_post', array( $this, 'generate_token_on_save' ), 10, 3 ); - add_action( 'rest_api_init', array( new REST_Settings_Controller(), 'register_routes' ) ); add_action( 'rest_api_init', array( new REST_Token_Controller(), 'register_routes' ) ); } @@ -75,7 +76,7 @@ public function generate_token_on_save( $post_id, $post, $update ) { $settings = new Settings(); - if ( ! $settings->is_available() ) { + if ( ! $settings->is_sig_available() ) { return; } @@ -88,7 +89,7 @@ public function generate_token_on_save( $post_id, $post, $update ) { if ( ! $update && 'auto-draft' === $post->post_status && - $settings->is_enabled() && + $settings->get_settings()['socialImageGeneratorSettings']['enabled'] && empty( $post_settings->get_settings( true ) ) ) { $post_settings->update_setting( 'enabled', true ); 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(),