Add newsletter
This commit is contained in:
74
inc/class-newsletter.php
Normal file
74
inc/class-newsletter.php
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace WP_Ultimo;
|
||||||
|
|
||||||
|
class Newsletter {
|
||||||
|
use \WP_Ultimo\Traits\Singleton;
|
||||||
|
|
||||||
|
const SETTING_FIELD_SLUG = 'newsletter_optin';
|
||||||
|
|
||||||
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fix stripe settings
|
||||||
|
*
|
||||||
|
* @since 2.0.18
|
||||||
|
*
|
||||||
|
* @param array $settings The final settings array being saved, containing ALL options.
|
||||||
|
* @param array $settings_to_save Array containing just the options being updated.
|
||||||
|
* @param array $saved_settings Array containing the original settings.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
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' ),
|
||||||
|
],
|
||||||
|
] );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $settings;
|
||||||
|
|
||||||
|
} // end fix_saving_settings;
|
||||||
|
}
|
@ -412,7 +412,7 @@ class Settings {
|
|||||||
* @param array $atts Field attributes such as title, description, tooltip, default value, etc.
|
* @param array $atts Field attributes such as title, description, tooltip, default value, etc.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function add_field($section_slug, $field_slug, $atts) {
|
public function add_field($section_slug, $field_slug, $atts, $priority = 10) {
|
||||||
/*
|
/*
|
||||||
* Adds the field to the desired fields array.
|
* Adds the field to the desired fields array.
|
||||||
*/
|
*/
|
||||||
@ -529,7 +529,7 @@ class Settings {
|
|||||||
|
|
||||||
return $fields;
|
return $fields;
|
||||||
|
|
||||||
});
|
}, $priority );
|
||||||
|
|
||||||
$settings = $this->get_all();
|
$settings = $this->get_all();
|
||||||
/*
|
/*
|
||||||
@ -567,28 +567,36 @@ class Settings {
|
|||||||
'title' => __('Your Business', 'wp-ultimo'),
|
'title' => __('Your Business', 'wp-ultimo'),
|
||||||
'desc' => __('General information about your business..', 'wp-ultimo'),
|
'desc' => __('General information about your business..', 'wp-ultimo'),
|
||||||
'type' => 'header',
|
'type' => 'header',
|
||||||
));
|
),
|
||||||
|
10
|
||||||
|
);
|
||||||
|
|
||||||
$this->add_field('general', 'company_name', array(
|
$this->add_field('general', 'company_name', array(
|
||||||
'title' => __('Company Name', 'wp-ultimo'),
|
'title' => __('Company Name', 'wp-ultimo'),
|
||||||
'desc' => __('This name is used when generating invoices, for example.', 'wp-ultimo'),
|
'desc' => __('This name is used when generating invoices, for example.', 'wp-ultimo'),
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
'default' => get_network_option(null, 'site_name'),
|
'default' => get_network_option(null, 'site_name'),
|
||||||
));
|
),
|
||||||
|
20
|
||||||
|
);
|
||||||
|
|
||||||
$this->add_field('general', 'company_logo', array(
|
$this->add_field('general', 'company_logo', array(
|
||||||
'title' => __('Upload Company Logo', 'wp-ultimo'),
|
'title' => __('Upload Company Logo', 'wp-ultimo'),
|
||||||
'desc' => __('Add your company logo to be used on the login page and other places.', 'wp-ultimo'),
|
'desc' => __('Add your company logo to be used on the login page and other places.', 'wp-ultimo'),
|
||||||
'type' => 'image',
|
'type' => 'image',
|
||||||
'default' => '',
|
'default' => '',
|
||||||
));
|
),
|
||||||
|
30
|
||||||
|
);
|
||||||
|
|
||||||
$this->add_field('general', 'company_email', array(
|
$this->add_field('general', 'company_email', array(
|
||||||
'title' => __('Company Email Address', 'wp-ultimo'),
|
'title' => __('Company Email Address', 'wp-ultimo'),
|
||||||
'desc' => __('This email is used when generating invoices, for example.', 'wp-ultimo'),
|
'desc' => __('This email is used when generating invoices, for example.', 'wp-ultimo'),
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
'default' => get_network_option(null, 'admin_email'),
|
'default' => get_network_option(null, 'admin_email'),
|
||||||
));
|
),
|
||||||
|
40
|
||||||
|
);
|
||||||
|
|
||||||
$this->add_field('general', 'company_address', array(
|
$this->add_field('general', 'company_address', array(
|
||||||
'title' => __('Company Address', 'wp-ultimo'),
|
'title' => __('Company Address', 'wp-ultimo'),
|
||||||
@ -599,7 +607,8 @@ class Settings {
|
|||||||
'html_attr' => array(
|
'html_attr' => array(
|
||||||
'rows' => 5,
|
'rows' => 5,
|
||||||
),
|
),
|
||||||
));
|
),
|
||||||
|
50);
|
||||||
|
|
||||||
$this->add_field('general', 'company_country', array(
|
$this->add_field('general', 'company_country', array(
|
||||||
'title' => __('Company Country', 'wp-ultimo'),
|
'title' => __('Company Country', 'wp-ultimo'),
|
||||||
@ -607,13 +616,14 @@ class Settings {
|
|||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'options' => 'wu_get_countries',
|
'options' => 'wu_get_countries',
|
||||||
'default' => array($this, 'get_default_company_country'),
|
'default' => array($this, 'get_default_company_country'),
|
||||||
));
|
), 60);
|
||||||
|
|
||||||
$this->add_field('general', 'currency_header', array(
|
$this->add_field('general', 'currency_header', array(
|
||||||
'title' => __('Currency Options', 'wp-ultimo'),
|
'title' => __('Currency Options', 'wp-ultimo'),
|
||||||
'desc' => __('The following options affect how prices are displayed on the frontend, the backend and in reports.', 'wp-ultimo'),
|
'desc' => __('The following options affect how prices are displayed on the frontend, the backend and in reports.', 'wp-ultimo'),
|
||||||
'type' => 'header',
|
'type' => 'header',
|
||||||
));
|
), 70
|
||||||
|
);
|
||||||
|
|
||||||
$this->add_field('general', 'currency_symbol', array(
|
$this->add_field('general', 'currency_symbol', array(
|
||||||
'title' => __('Currency', 'wp-ultimo'),
|
'title' => __('Currency', 'wp-ultimo'),
|
||||||
@ -621,7 +631,8 @@ class Settings {
|
|||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'default' => 'USD',
|
'default' => 'USD',
|
||||||
'options' => 'wu_get_currencies',
|
'options' => 'wu_get_currencies',
|
||||||
));
|
), 80
|
||||||
|
);
|
||||||
|
|
||||||
$this->add_field('general', 'currency_position', array(
|
$this->add_field('general', 'currency_position', array(
|
||||||
'title' => __('Currency Position', 'wp-ultimo'),
|
'title' => __('Currency Position', 'wp-ultimo'),
|
||||||
@ -635,14 +646,15 @@ class Settings {
|
|||||||
'%s %v' => __('Left with space ($ 99.99)', 'wp-ultimo'),
|
'%s %v' => __('Left with space ($ 99.99)', 'wp-ultimo'),
|
||||||
'%v %s' => __('Right with space (99.99 $)', 'wp-ultimo'),
|
'%v %s' => __('Right with space (99.99 $)', 'wp-ultimo'),
|
||||||
)
|
)
|
||||||
));
|
), 90
|
||||||
|
);
|
||||||
|
|
||||||
$this->add_field('general', 'decimal_separator', array(
|
$this->add_field('general', 'decimal_separator', array(
|
||||||
'title' => __('Decimal Separator', 'wp-ultimo'),
|
'title' => __('Decimal Separator', 'wp-ultimo'),
|
||||||
'desc' => __('This setting affects all prices displayed across the plugin elements.', 'wp-ultimo'),
|
'desc' => __('This setting affects all prices displayed across the plugin elements.', 'wp-ultimo'),
|
||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
'default' => '.',
|
'default' => '.',
|
||||||
));
|
), 100);
|
||||||
|
|
||||||
$this->add_field('general', 'thousand_separator', array(
|
$this->add_field('general', 'thousand_separator', array(
|
||||||
'title' => __('Thousand Separator', 'wp-ultimo'),
|
'title' => __('Thousand Separator', 'wp-ultimo'),
|
||||||
@ -650,7 +662,7 @@ class Settings {
|
|||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
'default' => ',',
|
'default' => ',',
|
||||||
'raw' => true
|
'raw' => true
|
||||||
));
|
),110);
|
||||||
|
|
||||||
$this->add_field('general', 'precision', array(
|
$this->add_field('general', 'precision', array(
|
||||||
'title' => __('Number of Decimals', 'wp-ultimo'),
|
'title' => __('Number of Decimals', 'wp-ultimo'),
|
||||||
@ -658,7 +670,7 @@ class Settings {
|
|||||||
'type' => 'number',
|
'type' => 'number',
|
||||||
'default' => '2',
|
'default' => '2',
|
||||||
'min' => 0,
|
'min' => 0,
|
||||||
));
|
), 120);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Login & Registration
|
* Login & Registration
|
||||||
|
@ -145,6 +145,8 @@ final class WP_Ultimo {
|
|||||||
*/
|
*/
|
||||||
$this->settings = WP_Ultimo\Settings::get_instance();
|
$this->settings = WP_Ultimo\Settings::get_instance();
|
||||||
|
|
||||||
|
WP_Ultimo\Newsletter::get_instance();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if the WP Multisite WaaS requirements are present.
|
* Check if the WP Multisite WaaS requirements are present.
|
||||||
*
|
*
|
||||||
|
@ -88,9 +88,9 @@ function wu_register_settings_section($section_slug, $atts) {
|
|||||||
* @param array $atts Field attributes such as title, description, tooltip, default value, etc.
|
* @param array $atts Field attributes such as title, description, tooltip, default value, etc.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function wu_register_settings_field($section_slug, $field_slug, $atts) {
|
function wu_register_settings_field($section_slug, $field_slug, $atts, $priority = 10) {
|
||||||
|
|
||||||
WP_Ultimo()->settings->add_field($section_slug, $field_slug, $atts);
|
WP_Ultimo()->settings->add_field($section_slug, $field_slug, $atts, $priority);
|
||||||
|
|
||||||
} // end wu_register_settings_field;
|
} // end wu_register_settings_field;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user