Skip to content

Commit

Permalink
Update the initial states to use the new settings class
Browse files Browse the repository at this point in the history
  • Loading branch information
gmjuhasz committed Nov 8, 2023
1 parent cfa1dab commit 4ecae18
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
15 changes: 6 additions & 9 deletions projects/plugins/jetpack/class.jetpack-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) ),
);
}
Expand Down
35 changes: 12 additions & 23 deletions projects/plugins/social/src/class-jetpack-social.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
Expand All @@ -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
);
}

Expand Down Expand Up @@ -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',
Expand All @@ -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(),
Expand Down

0 comments on commit 4ecae18

Please sign in to comment.