Use new code style
This commit is contained in:
@ -10,17 +10,19 @@ class Newsletter {
|
||||
public function init() {
|
||||
add_action('wu_settings_login', array($this, 'add_settings'), 20);
|
||||
add_filter('wu_pre_save_settings', array($this, 'maybe_update_newsletter_subscription'), 10, 3);
|
||||
|
||||
} // end init;
|
||||
}
|
||||
|
||||
public function add_settings() {
|
||||
wu_register_settings_field('general', self::SETTING_FIELD_SLUG, array(
|
||||
'title' => __('Signup for WP Multisite WaaS Newsletter', 'wp-ultimo'),
|
||||
'desc' => __('Be informed of new releases and all things related to running a WaaS Network.', 'wp-ultimo'),
|
||||
'type' => 'toggle',
|
||||
'value' => '1',
|
||||
),
|
||||
45
|
||||
wu_register_settings_field(
|
||||
'general',
|
||||
self::SETTING_FIELD_SLUG,
|
||||
array(
|
||||
'title' => __('Signup for WP Multisite WaaS Newsletter', 'wp-ultimo'),
|
||||
'desc' => __('Be informed of new releases and all things related to running a WaaS Network.', 'wp-ultimo'),
|
||||
'type' => 'toggle',
|
||||
'value' => '1',
|
||||
),
|
||||
45
|
||||
);
|
||||
}
|
||||
|
||||
@ -37,38 +39,46 @@ class Newsletter {
|
||||
*/
|
||||
public function maybe_update_newsletter_subscription($settings, $settings_to_save, $saved_settings) {
|
||||
|
||||
if ( isset($settings_to_save[ self::SETTING_FIELD_SLUG ]) && $settings_to_save[ self::SETTING_FIELD_SLUG ] && $settings_to_save[ self::SETTING_FIELD_SLUG ] != $saved_settings[ self::SETTING_FIELD_SLUG ] ) {
|
||||
|
||||
$response = wp_remote_post( 'https://wpmultisitewaas.org/wp-json/newsletter/v2/subscribers', [
|
||||
'method' => 'PUT',
|
||||
'body' => wp_json_encode( [
|
||||
'email' => $settings['company_email'],
|
||||
'status' => 'confirmed',
|
||||
'first_name' => $settings['company_name'],
|
||||
'country' => $settings['company_country'],
|
||||
] ),
|
||||
'headers' => [
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => 'Basic ' . base64_encode( '30220d7fb4ec49a7410b3a309b9346c18410bd56:0407cd731d6f074cd0b96f2643b7619e89af1ed2' ),
|
||||
],
|
||||
] );
|
||||
} elseif( empty($settings_to_save[ self::SETTING_FIELD_SLUG ]) && ! empty( $saved_settings[ self::SETTING_FIELD_SLUG ] ) ) {
|
||||
$response = wp_remote_post( 'https://wpmultisitewaas.org/wp-json/newsletter/v2/subscribers', [
|
||||
'method' => 'PUT',
|
||||
'body' => wp_json_encode( [
|
||||
'email' => $settings['company_email'],
|
||||
'status' => 'unsubscribed',
|
||||
] ),
|
||||
'headers' => [
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => 'Basic ' . base64_encode( '30220d7fb4ec49a7410b3a309b9346c18410bd56:0407cd731d6f074cd0b96f2643b7619e89af1ed2' ),
|
||||
],
|
||||
] );
|
||||
if ( isset($settings_to_save[ self::SETTING_FIELD_SLUG ]) && $settings_to_save[ self::SETTING_FIELD_SLUG ] && $settings_to_save[ self::SETTING_FIELD_SLUG ] != $saved_settings[ self::SETTING_FIELD_SLUG ] ) {
|
||||
$response = wp_remote_post(
|
||||
'https://wpmultisitewaas.org/wp-json/newsletter/v2/subscribers',
|
||||
array(
|
||||
'method' => 'PUT',
|
||||
'body' => wp_json_encode(
|
||||
array(
|
||||
'email' => $settings['company_email'],
|
||||
'status' => 'confirmed',
|
||||
'first_name' => $settings['company_name'],
|
||||
'country' => $settings['company_country'],
|
||||
)
|
||||
),
|
||||
'headers' => array(
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => 'Basic ' . base64_encode('30220d7fb4ec49a7410b3a309b9346c18410bd56:0407cd731d6f074cd0b96f2643b7619e89af1ed2'),
|
||||
),
|
||||
)
|
||||
);
|
||||
} elseif ( empty($settings_to_save[ self::SETTING_FIELD_SLUG ]) && ! empty($saved_settings[ self::SETTING_FIELD_SLUG ]) ) {
|
||||
$response = wp_remote_post(
|
||||
'https://wpmultisitewaas.org/wp-json/newsletter/v2/subscribers',
|
||||
array(
|
||||
'method' => 'PUT',
|
||||
'body' => wp_json_encode(
|
||||
array(
|
||||
'email' => $settings['company_email'],
|
||||
'status' => 'unsubscribed',
|
||||
)
|
||||
),
|
||||
'headers' => array(
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => 'Basic ' . base64_encode('30220d7fb4ec49a7410b3a309b9346c18410bd56:0407cd731d6f074cd0b96f2643b7619e89af1ed2'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $settings;
|
||||
|
||||
} // end fix_saving_settings;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user