Skip to content

Commit 929e950

Browse files
committed
set initial block attribute values from the global settings
1 parent 7499500 commit 929e950

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

includes/blocks/class-mailchimp-list-subscribe-form-blocks.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,17 @@ public function register_blocks() {
6767
}
6868

6969
$data = array(
70-
'admin_settings_url' => esc_url_raw( admin_url( 'admin.php?page=mailchimp_sf_options' ) ),
71-
'lists' => $this->get_lists(),
72-
'list_id' => get_option( 'mc_list_id', '' ),
73-
'header_text' => get_option( 'mc_header_content', '' ),
74-
'sub_header_text' => get_option( 'mc_subheader_content', '' ),
75-
'merge_fields_visibility' => $merge_fields_visibility,
76-
'interest_groups_visibility' => $interest_groups_visibility,
70+
'admin_settings_url' => esc_url_raw( admin_url( 'admin.php?page=mailchimp_sf_options' ) ),
71+
'lists' => $this->get_lists(),
72+
'list_id' => get_option( 'mc_list_id', '' ),
73+
'header_text' => get_option( 'mc_header_content', '' ),
74+
'sub_header_text' => get_option( 'mc_subheader_content', '' ),
75+
'submit_text' => get_option( 'mc_submit_text', __( 'Subscribe', 'mailchimp' ) ),
76+
'show_unsubscribe_link' => get_option( 'mc_use_unsub_link', 'off' ) === 'on',
77+
'update_existing_subscribers' => (bool) get_option( 'mc_update_existing', true ),
78+
'double_opt_in' => (bool) get_option( 'mc_double_optin', true ),
79+
'merge_fields_visibility' => $merge_fields_visibility,
80+
'interest_groups_visibility' => $interest_groups_visibility,
7781
);
7882
$data = 'window.mailchimp_sf_block_data = ' . wp_json_encode( $data );
7983
wp_add_inline_script( 'mailchimp-mailchimp-editor-script', $data, 'before' );

includes/blocks/mailchimp/block.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,16 @@
1616
"type": "string"
1717
},
1818
"submit_text": {
19-
"type": "string",
20-
"default": "Subscribe"
19+
"type": "string"
2120
},
2221
"double_opt_in": {
23-
"type": "boolean",
24-
"default": true
22+
"type": "boolean"
2523
},
2624
"update_existing_subscribers": {
27-
"type": "boolean",
28-
"default": true
25+
"type": "boolean"
2926
},
3027
"show_unsubscribe_link": {
31-
"type": "boolean",
32-
"default": false
28+
"type": "boolean"
3329
},
3430
"unsubscribe_link_text": {
3531
"type": "string",

includes/blocks/mailchimp/edit.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,20 @@ export const BlockEdit = (props) => {
4242
list_id: listId,
4343
header_text,
4444
sub_header_text,
45+
submit_text: submitText,
46+
show_unsubscribe_link: showUnsubscribeLink,
47+
update_existing_subscribers: updateExistingSubscribers,
48+
double_opt_in: doubleOptIn,
4549
} = mailchimp_sf_block_data;
4650

4751
const {
4852
header = header_text,
4953
sub_header = sub_header_text,
5054
list_id = listId,
51-
submit_text,
52-
double_opt_in,
53-
update_existing_subscribers,
54-
show_unsubscribe_link,
55+
submit_text = submitText,
56+
double_opt_in = doubleOptIn,
57+
update_existing_subscribers = updateExistingSubscribers,
58+
show_unsubscribe_link = showUnsubscribeLink,
5559
unsubscribe_link_text,
5660
show_required_indicator = true,
5761
required_indicator_text,
@@ -231,7 +235,7 @@ export const BlockEdit = (props) => {
231235

232236
updateList(list_id, false);
233237

234-
// Set the attributes initially, if it's already not set.
238+
// Set the attributes from global settings initially, if it's already not set.
235239
if (attributes.list_id === undefined) {
236240
const attributeUpdates = { list_id: listId };
237241
if (attributes.header === undefined) {
@@ -240,6 +244,18 @@ export const BlockEdit = (props) => {
240244
if (attributes.sub_header === undefined) {
241245
attributeUpdates.sub_header = sub_header_text;
242246
}
247+
if (attributes.submit_text === undefined) {
248+
attributeUpdates.submit_text = submitText;
249+
}
250+
if (attributes.double_opt_in === undefined) {
251+
attributeUpdates.double_opt_in = doubleOptIn;
252+
}
253+
if (attributes.update_existing_subscribers === undefined) {
254+
attributeUpdates.update_existing_subscribers = updateExistingSubscribers;
255+
}
256+
if (attributes.show_unsubscribe_link === undefined) {
257+
attributeUpdates.show_unsubscribe_link = showUnsubscribeLink;
258+
}
243259

244260
setAttributes(attributeUpdates);
245261
}

0 commit comments

Comments
 (0)