Skip to content

Commit 93ad233

Browse files
committed
MInor code tweaks.
1 parent 5e366f2 commit 93ad233

File tree

8 files changed

+82
-85
lines changed

8 files changed

+82
-85
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function get_lists() {
101101
return array();
102102
}
103103

104-
// we *could* support paging, but few users have that many lists (and shouldn't)
104+
// we *could* support paging, but 100 is more than enough for now.
105105
$lists = $api->get( 'lists', 100, array( 'fields' => 'lists.id,lists.name,lists.email_type_option' ) );
106106
if ( is_wp_error( $lists ) ) {
107107
return array();
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"$schema": "https://schemas.wp.org/trunk/block.json",
3-
"apiVersion": 3,
4-
"name": "mailchimp/mailchimp-form-field",
2+
"$schema": "https://schemas.wp.org/trunk/block.json",
3+
"apiVersion": 3,
4+
"name": "mailchimp/mailchimp-form-field",
55
"title": "Form Field",
66
"category": "widgets",
7-
"attributes": {
8-
"tag": {
9-
"type": "string"
10-
},
7+
"attributes": {
8+
"tag": {
9+
"type": "string"
10+
},
1111
"label": {
1212
"type": "string"
1313
},
@@ -17,20 +17,20 @@
1717
"type": {
1818
"type": "string"
1919
}
20-
},
21-
"supports": {
22-
"html": false,
23-
"reusable": true,
20+
},
21+
"supports": {
22+
"html": false,
23+
"reusable": true,
2424
"lock": false,
25-
"typography": {
25+
"typography": {
2626
"fontSize": true,
2727
"lineHeight": true
2828
}
29-
},
29+
},
3030
"parent": [
31-
"mailchimp/mailchimp"
32-
],
31+
"mailchimp/mailchimp"
32+
],
3333
"usesContext": ["mailchimp/list_id","mailchimp/show_required_indicator"],
3434
"editorScript": "file:./index.js",
35-
"render": "file:./field-markup.php"
35+
"render": "file:./field-markup.php"
3636
}

includes/blocks/mailchimp-form-field/edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ export const BlockEdit = (props) => {
316316
} = props;
317317
const { visible, tag } = attributes;
318318
const { mailchimpListData } = window;
319-
const isPublic = mailchimpListData?.[listId]?.[tag]?.public || true;
319+
const isPublic = mailchimpListData?.[listId]?.[tag]?.public;
320320
const isRequired = mailchimpListData?.[listId]?.[tag]?.required || false;
321321

322322
return (

includes/blocks/mailchimp-form-field/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ variations.forEach((variation, index) => {
108108
});
109109

110110
registerBlockType(metadata, {
111-
icon: 'feedback',
112111
edit: BlockEdit,
113112
save: () => null,
114113
variations,

includes/blocks/mailchimp/block.json

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"$schema": "https://schemas.wp.org/trunk/block.json",
3-
"apiVersion": 3,
4-
"name": "mailchimp/mailchimp",
5-
"title": "Mailchimp List Subscribe Form",
6-
"category": "widgets",
7-
"description": "Mailchimp List Subscribe Form",
8-
"attributes": {
2+
"$schema": "https://schemas.wp.org/trunk/block.json",
3+
"apiVersion": 3,
4+
"name": "mailchimp/mailchimp",
5+
"title": "Mailchimp List Subscribe Form",
6+
"category": "widgets",
7+
"description": "Mailchimp List Subscribe Form",
8+
"attributes": {
99
"list_id": {
1010
"type": "string"
1111
},
@@ -43,46 +43,46 @@
4343
"default": true
4444
}
4545
},
46-
"supports": {
47-
"html": false,
48-
"multiple": false,
49-
"reusable": true,
50-
"align": [ "wide", "full" ],
51-
"__experimentalBorder": {
52-
"color": true,
53-
"radius": true,
54-
"style": true,
55-
"width": true,
56-
"__experimentalDefaultControls": {
57-
"radius": true,
58-
"style": true,
59-
"width": true
60-
}
61-
},
62-
"spacing": {
63-
"margin": true,
64-
"padding": true
65-
},
66-
"color": {
67-
"background": true,
68-
"text": true,
69-
"border": true
70-
},
71-
"typography": {
72-
"fontSize": true,
73-
"lineHeight": true,
74-
"textAlign": true
75-
}
76-
},
77-
"allowedBlocks": [
78-
"mailchimp/mailchimp-form-field"
79-
],
80-
"providesContext": {
81-
"mailchimp/list_id": "list_id",
82-
"mailchimp/show_required_indicator": "show_required_indicator"
83-
},
84-
"textdomain": "mailchimp",
85-
"editorScript": "file:./index.js",
86-
"render": "file:./markup.php",
87-
"editorStyle": "file:./editor.css"
46+
"supports": {
47+
"html": false,
48+
"multiple": false,
49+
"reusable": true,
50+
"align": [ "wide", "full" ],
51+
"__experimentalBorder": {
52+
"color": true,
53+
"radius": true,
54+
"style": true,
55+
"width": true,
56+
"__experimentalDefaultControls": {
57+
"radius": true,
58+
"style": true,
59+
"width": true
60+
}
61+
},
62+
"spacing": {
63+
"margin": true,
64+
"padding": true
65+
},
66+
"color": {
67+
"background": true,
68+
"text": true,
69+
"border": true
70+
},
71+
"typography": {
72+
"fontSize": true,
73+
"lineHeight": true,
74+
"textAlign": true
75+
}
76+
},
77+
"allowedBlocks": [
78+
"mailchimp/mailchimp-form-field"
79+
],
80+
"providesContext": {
81+
"mailchimp/list_id": "list_id",
82+
"mailchimp/show_required_indicator": "show_required_indicator"
83+
},
84+
"textdomain": "mailchimp",
85+
"editorScript": "file:./index.js",
86+
"render": "file:./markup.php",
87+
"editorStyle": "file:./editor.css"
8888
}

includes/blocks/mailchimp/edit.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,20 @@ export const BlockEdit = (props) => {
5858
show_required_indicator = true,
5959
} = attributes;
6060

61+
const [listData, setListData] = useState({});
62+
const [isLoading, setIsLoading] = useState(true);
63+
const [error, setError] = useState('');
6164
const blockProps = useBlockProps();
6265
const { replaceInnerBlocks } = useDispatch(blockEditorStore);
6366

67+
// Select current innerBlocks
68+
const innerBlocks = useSelect(
69+
(select) => select(blockEditorStore).getBlocksByClientId(clientId)?.[0]?.innerBlocks || [],
70+
[clientId],
71+
);
72+
const exisingTags = innerBlocks.map((block) => block?.attributes?.tag);
73+
const visibleFieldsCount = innerBlocks.filter((block) => block?.attributes?.visible).length;
74+
6475
const listOptions = [];
6576
// Check if selected list is not in the list of available lists.
6677
const listIds = lists?.map((list) => list.id) || [];
@@ -79,18 +90,7 @@ export const BlockEdit = (props) => {
7990
})) || []),
8091
);
8192

82-
const [listData, setListData] = useState({});
83-
const [isLoading, setIsLoading] = useState(true);
84-
const [error, setError] = useState('');
85-
86-
// Select current innerBlocks
87-
const innerBlocks = useSelect(
88-
(select) => select(blockEditorStore).getBlocksByClientId(clientId)?.[0]?.innerBlocks || [],
89-
[clientId],
90-
);
91-
const exisingTags = innerBlocks.map((block) => block?.attributes?.tag);
92-
const visibleFieldsCount = innerBlocks.filter((block) => block?.attributes?.visible).length;
93-
93+
// Fetch list data and update innerBlocks if needed.
9494
const updateList = (listId, replaceBlocks = false) => {
9595
setError('');
9696
setIsLoading(true);
@@ -291,7 +291,7 @@ export const BlockEdit = (props) => {
291291
<RichText
292292
id="mc_signup_submit"
293293
className="button"
294-
tagName="button"
294+
tagName="a"
295295
placeholder={__('Enter a button text.', 'mailchimp')}
296296
value={submit_text}
297297
onChange={(submit_text) =>

includes/blocks/mailchimp/markup.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
?>
99
<div <?php echo get_block_wrapper_attributes(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
1010
<?php
11-
// Check if we should display the form. TODO: Add a list ID check.
11+
// Check if we should display the form.
1212
if ( ! mailchimp_sf_should_display_form() ) {
1313
return;
1414
}
1515

16-
// Backwards compatibility for old block.
16+
// Backwards compatibility for old block, which didn't have innerBlocks.
1717
$block_instance = $block->parsed_block;
1818
$inner_blocks = $block_instance['innerBlocks'] ?? [];
1919
if ( empty( $inner_blocks ) ) {

mailchimp.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ function mailchimp_sf_load_resources() {
157157
'ajax_url' => trailingslashit( home_url() ),
158158
)
159159
);
160-
}
161160

162-
if ( ! is_admin() ) {
163161
// Datepicker theme
164162
wp_enqueue_style( 'flick', MCSF_URL . 'assets/css/flick/flick.css', array(), MCSF_VER );
165163

0 commit comments

Comments
 (0)