Skip to content

Commit 0b7d9c3

Browse files
committed
Remove default list id.
1 parent 6be09f1 commit 0b7d9c3

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,25 @@ public function register_blocks() {
6666
),
6767
'list_id' => array(
6868
'type' => 'string',
69-
'default' => get_option( 'mc_list_id', '' ),
7069
),
7170
'submit_text' => array(
7271
'type' => 'string',
73-
'default' => get_option( 'mc_submit_text', esc_html__( 'Subscribe', 'mailchimp' ) ),
72+
'default' => esc_html__( 'Subscribe', 'mailchimp' ),
7473
),
7574
'interest_groups_visibility' => array(
7675
'type' => 'object',
77-
'default' => $interest_groups_visibility,
7876
),
7977
'double_opt_in' => array(
8078
'type' => 'boolean',
81-
'default' => (bool) get_option( 'mc_double_optin', true ),
79+
'default' => true,
8280
),
8381
'update_existing_subscribers' => array(
8482
'type' => 'boolean',
85-
'default' => (bool) get_option( 'mc_update_existing', true ),
83+
'default' => true,
8684
),
8785
'show_unsubscribe_link' => array(
8886
'type' => 'boolean',
89-
'default' => (bool) get_option( 'mc_use_unsub_link', 'off' ) === 'on',
87+
'default' => false,
9088
),
9189
'unsubscribe_link_text' => array(
9290
'type' => 'string',
@@ -120,6 +118,7 @@ public function register_blocks() {
120118
$data = array(
121119
'admin_settings_url' => esc_url_raw( admin_url( 'admin.php?page=mailchimp_sf_options' ) ),
122120
'lists' => $this->get_lists(),
121+
'list_id' => get_option( 'mc_list_id', '' ),
123122
'merge_fields_visibility' => $merge_fields_visibility,
124123
);
125124
$data = 'window.mailchimp_sf_block_data = ' . wp_json_encode( $data );

includes/blocks/mailchimp/edit.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ const SelectListPlaceholder = () => {
3636

3737
export const BlockEdit = (props) => {
3838
const { clientId, attributes, setAttributes } = props;
39+
const { mailchimp_sf_block_data } = window;
40+
const { lists, merge_fields_visibility, list_id: listId } = mailchimp_sf_block_data;
41+
3942
const {
4043
header,
4144
sub_header,
42-
list_id,
45+
list_id = listId,
4346
submit_text,
4447
double_opt_in,
4548
update_existing_subscribers,
@@ -48,12 +51,10 @@ export const BlockEdit = (props) => {
4851
interest_groups_visibility,
4952
show_required_indicator = true,
5053
} = attributes;
54+
5155
const blockProps = useBlockProps();
5256
const { replaceInnerBlocks } = useDispatch(blockEditorStore);
5357

54-
const { mailchimp_sf_block_data } = window;
55-
const { lists, merge_fields_visibility } = mailchimp_sf_block_data;
56-
5758
const listOptions = [];
5859
// Check if selected list is not in the list of available lists.
5960
const listIds = lists?.map((list) => list.id) || [];
@@ -184,6 +185,11 @@ export const BlockEdit = (props) => {
184185
setIsLoading(true);
185186

186187
updateList(list_id, false);
188+
189+
// Set list_id attribute initially, if it's already not set.
190+
if (attributes.list_id === undefined) {
191+
setAttributes({ list_id: listId });
192+
}
187193
}, []); // eslint-disable-line react-hooks/exhaustive-deps -- Only run on initial render.
188194

189195
if (isLoading) {

includes/blocks/mailchimp/markup.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@
1313
return;
1414
}
1515

16+
// Backwards compatibility for old block.
17+
$block_instance = $block->parsed_block;
18+
$inner_blocks = $block_instance['innerBlocks'] ?? [];
19+
if ( empty( $inner_blocks ) ) {
20+
mailchimp_sf_signup_form();
21+
?>
22+
</div>
23+
<?php
24+
return;
25+
}
26+
1627
// Make sure we have a list ID and it's valid.
28+
$list_id = $attributes['list_id'] ?? '';
1729
$lists = ( new Mailchimp_List_Subscribe_Form_Blocks() )->get_lists();
1830
$list_ids = array_map(
1931
function ( $single_list ) {
@@ -22,22 +34,10 @@ function ( $single_list ) {
2234
$lists
2335
);
2436

25-
if ( ! in_array( $attributes['list_id'], $list_ids, true ) ) {
26-
return;
27-
}
28-
29-
// Backwards compatibility for old block.
30-
$block_instance = $block->parsed_block;
31-
$inner_blocks = $block_instance['innerBlocks'] ?? [];
32-
if ( empty( $inner_blocks ) ) {
33-
mailchimp_sf_signup_form();
34-
?>
35-
</div>
36-
<?php
37+
if ( ! in_array( $list_id, $list_ids, true ) ) {
3738
return;
3839
}
3940

40-
$list_id = $attributes['list_id'] ?? '';
4141
$header = $attributes['header'] ?? '';
4242
$sub_heading = $attributes['sub_header'] ?? '';
4343
$submit_text = $attributes['submit_text'] ?? __( 'Subscribe', 'mailchimp' );

0 commit comments

Comments
 (0)