| @@ -10,12 +10,9 @@ | ||
| 10 | 10 | namespace Automattic\Jetpack\Extensions\Mailchimp; |
| 11 | 11 | |
| 12 | 12 | use Automattic\Jetpack\Assets; |
| 13 | 13 | use Automattic\Jetpack\Blocks; |
| 14 | -use Automattic\Jetpack\Connection\Client; | |
| 15 | -use Automattic\Jetpack\Connection\Manager as Connection_Manager; | |
| 16 | 14 | use Automattic\Jetpack\External_Connections; |
| 17 | -use Automattic\Jetpack\Status\Host; | |
| 18 | 15 | use Jetpack; |
| 19 | 16 | use Jetpack_Gutenberg; |
| 20 | 17 | |
| 21 | 18 | if ( ! defined( 'ABSPATH' ) ) { |
| @@ -103,41 +100,9 @@ | ||
| 103 | 100 | } |
| 104 | 101 | |
| 105 | 102 | check_admin_referer( 'writing-options' ); |
| 106 | 103 | |
| 107 | - $site_id = Connection_Manager::get_site_id(); | |
| 108 | - if ( is_wp_error( $site_id ) ) { | |
| 109 | - return; | |
| 110 | - } | |
| 111 | - | |
| 112 | - if ( $audience === 'none' ) { | |
| 113 | - $data = array( | |
| 114 | - 'follower_list_id' => '0', | |
| 115 | - 'keyring_id' => '0', | |
| 116 | - ); | |
| 117 | - } else { | |
| 118 | - $connection = External_Connections::get_connection( 'mailchimp' ); | |
| 119 | - if ( empty( $connection ) ) { | |
| 120 | - return; | |
| 121 | - } | |
| 122 | - $data = array( | |
| 123 | - 'follower_list_id' => $audience, | |
| 124 | - 'keyring_id' => $connection['ID'], | |
| 125 | - ); | |
| 126 | - } | |
| 127 | - | |
| 128 | - if ( ( new Host() )->is_wpcom_simple() ) { | |
| 129 | - require_lib( 'mailchimp' ); | |
| 130 | - $response = \MailchimpApi::save_settings( $site_id, $data ); | |
| 131 | - } else { | |
| 132 | - $response = Client::wpcom_json_api_request_as_user( | |
| 133 | - sprintf( '/sites/%d/mailchimp/settings', $site_id ), | |
| 134 | - '1.1', | |
| 135 | - array( 'method' => 'POST' ), | |
| 136 | - $data, | |
| 137 | - 'rest' | |
| 138 | - ); | |
| 139 | - } | |
| 140 | - if ( is_wp_error( $response ) ) { | |
| 104 | + require_once JETPACK__PLUGIN_DIR . '_inc/lib/class-jetpack-mailchimp-helper.php'; | |
| 105 | + if ( is_wp_error( \Jetpack_Mailchimp_Helper::save_audience( $audience ) ) ) { | |
| 141 | 106 | add_settings_error( 'general', 'settings_updated', __( 'Settings save failed.', 'jetpack' ), 'error' ); |
| 142 | 107 | } |
| 143 | 108 | } |