Skip to content

Commit c0ef2b2

Browse files
committed
Remove default values from KB block attributes and add ACF Pro stubs
- Remove default values from limit, showArticleCount, showExcerpt, hasClickableSection, and showEmptySections attributes in block.json - Add php-stubs/acf-pro-stubs dependency to composer.json - Remove CLAUDE.md and AGENTS.md from zip exclusions - Remove vendor/.DS_Store and vendor/bin/* from zip exclusions - Remove build:vendor script from composer.json - Update block editor to use plugin settings as fallback defaults when attribute
1 parent 83d903c commit c0ef2b2

20 files changed

Lines changed: 1040 additions & 635 deletions

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"phpstan/extension-installer": "^1",
2828
"phpstan/phpstan": "^1",
2929
"php-stubs/wordpress-stubs": "^6",
30+
"php-stubs/acf-pro-stubs": "^6.5",
3031
"wp-coding-standards/wpcs": "^3",
3132
"dealerdirect/phpcodesniffer-composer-installer": "^1",
3233
"yoast/phpunit-polyfills": "^3",
@@ -41,7 +42,6 @@
4142
"minimum-stability": "dev",
4243
"prefer-stable": true,
4344
"scripts": {
44-
"build:vendor": "composer install --no-dev --optimize-autoloader --classmap-authoritative",
4545
"phpstan": "vendor/bin/phpstan analyse --memory-limit=2048M",
4646
"phpstan-baseline": "vendor/bin/phpstan analyse --memory-limit=2048M --generate-baseline",
4747
"phpcs": "vendor/bin/phpcs -p -v -s --standard=phpcs.xml.dist $(find . -name '*.php')",
@@ -61,6 +61,6 @@
6161
"@phpcompat",
6262
"@phpstan"
6363
],
64-
"zip": "mkdir -p build && zip -X -r build/$(basename $(pwd)).zip . -x '*.git*' 'node_modules/*' '.*' '*/.git*' '*/.DS_Store' 'vendor/**/.DS_Store' 'vendor/bin/*' 'CODE_OF_CONDUCT.md' 'CONTRIBUTING.md' 'ISSUE_TEMPLATE.md' 'PULL_REQUEST_TEMPLATE.md' 'CLAUDE.md' 'AGENTS.md' '*.dist' '*.yml' '*.neon' 'composer.*' 'package.json' 'package-lock.json' 'dev-helpers**' 'build**' 'wporg-assets**' 'test-tools**' 'docs/*' 'phpunit**' 'phpstan-bootstrap.php' 'phpcompat-tools**'"
64+
"zip": "mkdir -p build && zip -X -r build/$(basename $(pwd)).zip . -x '*.git*' 'node_modules/*' '.*' '*/.git*' '*/.DS_Store' 'CODE_OF_CONDUCT.md' 'CONTRIBUTING.md' 'ISSUE_TEMPLATE.md' 'PULL_REQUEST_TEMPLATE.md' '*.dist' '*.yml' '*.neon' 'composer.*' 'package.json' 'package-lock.json' 'dev-helpers**' 'build**' 'wporg-assets**' 'test-tools**' 'docs/*' 'phpunit**' 'phpstan-bootstrap.php' 'phpcompat-tools**'"
6565
}
66-
}
66+
}

includes/blocks/build/kb/block.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,19 @@
2929
"default": 0
3030
},
3131
"limit": {
32-
"type": "number",
33-
"default": 5
32+
"type": "number"
3433
},
3534
"showArticleCount": {
36-
"type": "boolean",
37-
"default": false
35+
"type": "boolean"
3836
},
3937
"showExcerpt": {
40-
"type": "boolean",
41-
"default": false
38+
"type": "boolean"
4239
},
4340
"hasClickableSection": {
44-
"type": "boolean",
45-
"default": true
41+
"type": "boolean"
4642
},
4743
"showEmptySections": {
48-
"type": "boolean",
49-
"default": false
44+
"type": "boolean"
5045
},
5146
"title": {
5247
"type": "string",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-i18n', 'wp-server-side-render'), 'version' => 'be109a63fab2b2055dda');
1+
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-i18n', 'wp-server-side-render'), 'version' => '4aaacd10762a661fea0b');

includes/blocks/build/kb/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/blocks/src/articles/block.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
"title": "Knowledge Base Articles",
77
"category": "knowledgebase",
88
"icon": "book",
9-
"keywords": [
10-
"knowledgbase",
11-
"articles",
12-
"kb"
13-
],
9+
"keywords": ["knowledgbase", "articles", "kb"],
1410
"description": "Display the Knowledge Base Articles by Product or Section",
1511
"supports": {
1612
"html": false
@@ -62,4 +58,4 @@
6258
"editorScript": "file:./index.js",
6359
"editorStyle": "file:./index.css",
6460
"style": "file:./style.css"
65-
}
61+
}

includes/blocks/src/articles/edit.js

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ export default function Edit({ attributes, setAttributes }) {
4444

4545
const filterSectionsByProduct = productId
4646
? {
47-
filterTerm: (term) =>
48-
term.kb_product && term.kb_product.term_id === productId,
49-
}
47+
filterTerm: (term) =>
48+
term.kb_product && term.kb_product.term_id === productId,
49+
}
5050
: {};
5151

5252
const productSelectorProps = {
@@ -109,7 +109,10 @@ export default function Edit({ attributes, setAttributes }) {
109109
onChange={(value) => setAttributes({ depth: value })}
110110
min={-1}
111111
max={10}
112-
help={__('-1 for unlimited depth, 0 for current section only', 'knowledgebase')}
112+
help={__(
113+
'-1 for unlimited depth, 0 for current section only',
114+
'knowledgebase'
115+
)}
113116
/>
114117
</PanelRow>
115118
<PanelRow>
@@ -127,43 +130,46 @@ export default function Edit({ attributes, setAttributes }) {
127130
showHeading
128131
? productId
129132
? __(
130-
'Product heading will be shown',
131-
'knowledgebase'
132-
)
133+
'Product heading will be shown',
134+
'knowledgebase'
135+
)
133136
: __(
134-
'Section heading will be shown',
135-
'knowledgebase'
136-
)
137+
'Section heading will be shown',
138+
'knowledgebase'
139+
)
137140
: productId
138141
? __(
139-
'Product heading will be hidden',
140-
'knowledgebase'
141-
)
142+
'Product heading will be hidden',
143+
'knowledgebase'
144+
)
142145
: __(
143-
'Section heading will be hidden',
144-
'knowledgebase'
145-
)
146+
'Section heading will be hidden',
147+
'knowledgebase'
148+
)
146149
}
147150
/>
148151
</PanelRow>
149152
{showHeading && (
150153
<PanelRow>
151154
<ToggleControl
152-
label={__('Link heading to selection', 'knowledgebase')}
155+
label={__(
156+
'Link heading to selection',
157+
'knowledgebase'
158+
)}
153159
checked={linkHeading}
154160
onChange={() =>
155161
setAttributes({ linkHeading: !linkHeading })
156162
}
157163
help={
158164
linkHeading
159165
? __(
160-
'Heading will link to the selected product or section.',
161-
'knowledgebase'
162-
)
166+
'Heading will link to the selected product or section.',
167+
'knowledgebase'
168+
)
163169
: __(
164-
'Heading will remain plain text.',
165-
'knowledgebase'
166-
)
170+
'Heading will remain plain text.',
171+
'knowledgebase'
172+
)
167173
}
168174
/>
169175
</PanelRow>

includes/blocks/src/components/section-selector.js

Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -4,107 +4,107 @@ import { useSelect } from '@wordpress/data';
44
import { store as coreStore } from '@wordpress/core-data';
55

66
const SectionSelector = ({
7-
value,
8-
onChange,
9-
label,
10-
help,
11-
taxonomy = 'wzkb_category',
12-
includeEmptyLabel = '',
13-
formatLabel,
14-
className = '',
15-
wrapperClass = '',
16-
queryArgs = {},
17-
filterTerm,
7+
value,
8+
onChange,
9+
label,
10+
help,
11+
taxonomy = 'wzkb_category',
12+
includeEmptyLabel = '',
13+
formatLabel,
14+
className = '',
15+
wrapperClass = '',
16+
queryArgs = {},
17+
filterTerm,
1818
}) => {
19-
const { terms, hasResolved, error } = useSelect(
20-
(select) => {
21-
const query = {
22-
per_page: -1,
23-
hide_empty: 1,
24-
};
19+
const { terms, hasResolved, error } = useSelect(
20+
(select) => {
21+
const query = {
22+
per_page: -1,
23+
hide_empty: 1,
24+
};
2525

26-
const selectorArgs = [
27-
'taxonomy',
28-
taxonomy,
29-
{
30-
...query,
31-
...queryArgs,
32-
},
33-
];
26+
const selectorArgs = [
27+
'taxonomy',
28+
taxonomy,
29+
{
30+
...query,
31+
...queryArgs,
32+
},
33+
];
3434

35-
try {
36-
return {
37-
terms: select(coreStore).getEntityRecords(...selectorArgs),
38-
hasResolved: select(coreStore).hasFinishedResolution(
39-
'getEntityRecords',
40-
selectorArgs
41-
),
42-
error: null,
43-
};
44-
} catch (fetchError) {
45-
return {
46-
terms: [],
47-
hasResolved: true,
48-
error: fetchError,
49-
};
50-
}
51-
},
52-
[taxonomy]
53-
);
35+
try {
36+
return {
37+
terms: select(coreStore).getEntityRecords(...selectorArgs),
38+
hasResolved: select(coreStore).hasFinishedResolution(
39+
'getEntityRecords',
40+
selectorArgs
41+
),
42+
error: null,
43+
};
44+
} catch (fetchError) {
45+
return {
46+
terms: [],
47+
hasResolved: true,
48+
error: fetchError,
49+
};
50+
}
51+
},
52+
[taxonomy]
53+
);
5454

55-
const defaultLabel = (term) => {
56-
const baseLabel = `#${term.id} - ${term.name}`;
57-
if ('wzkb_category' === taxonomy && term.kb_product?.name) {
58-
return `${baseLabel} (${term.kb_product.name})`;
59-
}
60-
return baseLabel;
61-
};
55+
const defaultLabel = (term) => {
56+
const baseLabel = `#${term.id} - ${term.name}`;
57+
if ('wzkb_category' === taxonomy && term.kb_product?.name) {
58+
return `${baseLabel} (${term.kb_product.name})`;
59+
}
60+
return baseLabel;
61+
};
6262

63-
const filteredTerms =
64-
typeof filterTerm === 'function' ? terms?.filter(filterTerm) : terms;
63+
const filteredTerms =
64+
typeof filterTerm === 'function' ? terms?.filter(filterTerm) : terms;
6565

66-
const options =
67-
filteredTerms?.map((term) => ({
68-
label: (formatLabel || defaultLabel)(term),
69-
value: term.id.toString(),
70-
})) || [];
66+
const options =
67+
filteredTerms?.map((term) => ({
68+
label: (formatLabel || defaultLabel)(term),
69+
value: term.id.toString(),
70+
})) || [];
7171

72-
if (includeEmptyLabel) {
73-
options.unshift({ value: '', label: includeEmptyLabel });
74-
}
72+
if (includeEmptyLabel) {
73+
options.unshift({ value: '', label: includeEmptyLabel });
74+
}
7575

76-
const inputValue = value && value > 0 ? value.toString() : '';
76+
const inputValue = value && value > 0 ? value.toString() : '';
7777

78-
return (
79-
<>
80-
{error && (
81-
<Notice status="error" isDismissible={false}>
82-
{__(
83-
'Error loading categories. Please try again.',
84-
'knowledgebase'
85-
)}
86-
</Notice>
87-
)}
78+
return (
79+
<>
80+
{error && (
81+
<Notice status="error" isDismissible={false}>
82+
{__(
83+
'Error loading categories. Please try again.',
84+
'knowledgebase'
85+
)}
86+
</Notice>
87+
)}
8888

89-
{!hasResolved ? (
90-
<Spinner />
91-
) : (
92-
<div className={wrapperClass}>
93-
<ComboboxControl
94-
className={className}
95-
label={label}
96-
value={inputValue}
97-
onChange={(selected) =>
98-
onChange(parseInt(selected, 10) || 0)
99-
}
100-
options={options}
101-
placeholder={includeEmptyLabel}
102-
help={help}
103-
/>
104-
</div>
105-
)}
106-
</>
107-
);
89+
{!hasResolved ? (
90+
<Spinner />
91+
) : (
92+
<div className={wrapperClass}>
93+
<ComboboxControl
94+
className={className}
95+
label={label}
96+
value={inputValue}
97+
onChange={(selected) =>
98+
onChange(parseInt(selected, 10) || 0)
99+
}
100+
options={options}
101+
placeholder={includeEmptyLabel}
102+
help={help}
103+
/>
104+
</div>
105+
)}
106+
</>
107+
);
108108
};
109109

110110
export default SectionSelector;

0 commit comments

Comments
 (0)