Skip to content

Commit 559203c

Browse files
authored
Merge pull request #293 from infinum/feature/filters
Fixing anonymous filter
2 parents cae9804 + 194ffe0 commit 559203c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+414
-114
lines changed

website/blog/2022-04-25-using-assets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ The output of the icon on frontend is very simple. In the Quote component, it wa
7878
An excellent example, where you can see in even more detail how SVGs are being used, is our `icon` component. It isn't included in Eightshift theme by default, so you have to add it to your project with WP CLI. To include it in your project, use the following command:
7979

8080
```bash
81-
wp boilerplate use_component --name=icon
81+
wp boilerplate blocks use-component --name=icon
8282
```
8383

8484
If you include the Icon component inside a block, you will have the option to choose between multiple icons defined in the manifest. Another way to render SVGs from the Icon component is by using the `Components::render` helper method:

website/blog/2022-05-10-acf-in-a-project.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ This will generate a PHP code snippet that you can use in your theme. Now you ma
2929

3030
## CustomMeta class
3131

32-
Those ACF goodies in Eightshift Development kit we talked about earlier? Let us introduce you to one of them. We have a WP CLI command which we can use to generate a CustomMeta class where we can add our field groups. The command is `wp boilerplate create_acf_meta`. This command has one required parameter, and that is `name`. To create a class that we will use for registering our custom fields, we'll use the following command:
32+
Those ACF goodies in Eightshift Development kit we talked about earlier? Let us introduce you to one of them. We have a WP CLI command which we can use to generate a CustomMeta class where we can add our field groups. The command is `wp boilerplate create acf-meta`. This command has one required parameter, and that is `name`. To create a class that we will use for registering our custom fields, we'll use the following command:
3333

3434
```bash
35-
wp boilerplate create_acf_meta --name=intro
35+
wp boilerplate create acf-meta --name=intro
3636
```
3737

3838
This command will generate a **_CustomMeta_** folder inside **_src_** folder and add a new file called **_IntroAcfMeta.php_**. Inside that file, you should see the following method:
@@ -113,7 +113,7 @@ It's better to use class constants because if you decide to change the field nam
113113
ACF's Options page has a wide array of uses and it's very likely that you'll need some sort of Theme Options in your project. To make the implementation of Theme Options a bit easier, we have a CLI command which generates the `ThemeOptions` class in your project. Just use the following command:
114114

115115
```bash
116-
wp boilerplate create_theme_options
116+
wp boilerplate create theme-options
117117
```
118118

119119
This command generates a class with two methods. The first one, `createThemeOptionsPage()` creates a Theme Options page and adds it to the WP Admin sidebar. The second one, `registerThemeOptions()`, is what registers the fields you will have in Theme Options. Here is an example how Theme Options look after being created using `wp boilerplate`:

website/docs/legacy/v5/basics/blocks-patterns.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,18 @@ To remove all core patterns add this code to you `src/Blocks/Blocks.php` class.
3333
Filter goes in the register method:
3434
```php
3535
// Remove block patterns.
36-
add_filter('block_editor_settings', [$this, 'removeCorePatterns']);
36+
add_action('after_setup_theme', [$this, 'removeCorePatterns']);
3737
```
3838

3939
Callback method:
4040
```php
4141
/**
42-
* Remove core block patterns
42+
* Remove core block patterns.
4343
*
44-
* @param array $settings Array of block editor settings to filter out.
45-
*
46-
* @return array Filtered array.
44+
* @return void
4745
*/
48-
public function removeCorePatterns(array $settings): array
46+
public function removeCorePatterns(): void
4947
{
50-
$settings['__experimentalBlockPatterns'] = [];
51-
52-
return $settings;
48+
remove_theme_support('core-block-patterns');
5349
}
5450
```

website/forms/php/filters/admin/settings-data.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: Settings data
66
This filter allows adding a custom settings page in the WordPress admin area. Useful when creating custom option pages for Forms add-on plugins.
77

88
```php
9-
add_filter('es_forms_admin_settings_data', 'getSettingsConfig');
9+
\add_filter('es_forms_admin_settings_data', [$this, 'getSettingsConfig']);
1010

1111
/**
1212
* Settings config data.

website/forms/php/filters/block/country/alternative-data-set.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ For example, if you only want to allow choosing between 4 countries, you can do
1717
* **onlyUse** - Allows providing a custom list of countries, instead of using the full dataset.
1818

1919
```php
20-
add_filter('es_forms_block_country_alternative_data_set', function(): array {
20+
\add_filter('es_forms_block_country_alternative_data_set', [$this, 'getBlockCountryAlternativeDataSet']);
21+
22+
/**
23+
* Get country alternative changes for data set and provide filters.
24+
*
25+
* This filter will only provide alternative options and change the original list.
26+
*
27+
* @return array<mixed>
28+
*/
29+
public function getBlockCountryAlternativeDataSet(): array
30+
{
2131
{
2232
return [
2333
[
@@ -49,5 +59,5 @@ add_filter('es_forms_block_country_alternative_data_set', function(): array {
4959
],
5060
];
5161
}
52-
})
62+
}
5363
```

website/forms/php/filters/block/field/style-classes.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ title: Custom field classes
66
This filter allows you to add custom CSS classes to the field element. You can use this filter to provide custom styles based on some attributes of the field.
77

88
```php
9-
add_filter('es_forms_block_field_style_classes', function(array $attributes): array {
9+
\add_filter('es_forms_block_field_style_classes', [$this, 'getBlockFieldStyleClasses']);
10+
11+
/**
12+
* Add additional style classes to field block.
13+
*
14+
* @param array<string, mixed> $attributes Block attributes.
15+
*
16+
* @return array<string, mixed>
17+
*/
18+
public function getBlockFieldStyleClasses(array $attributes): array
19+
{
1020
return [
1121
'input' => [
1222
'custom-style'.
@@ -15,5 +25,5 @@ add_filter('es_forms_block_field_style_classes', function(array $attributes): ar
1525
'default',
1626
]
1727
];
18-
})
28+
}
1929
```

website/forms/php/filters/block/field/style-options.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ title: Custom field styles
66
This filter allows you to add definitions for custom field styles. When defined, the style option will be shown in the field options. Make sure to provide a CSS style that targets the class with the name of the `value` provided.
77

88
```php
9-
add_filter('es_forms_block_field_style_options', function(): array {
9+
\add_filter('es_forms_block_field_style_options', [$this, 'getBlockFieldStyleOptions']);
10+
11+
/**
12+
* Add additional style options to field block
13+
*
14+
* This filter will add new options to the style select dropdown in the field block. Field style option selector will not show unless a filter is provided. This option is shown in Block Editor.
15+
*
16+
* @return array<string, mixed>
17+
*/
18+
public function getBlockFieldStyleOptions(): array
19+
{
1020
return [
1121
'input' => [
1222
[
@@ -29,5 +39,5 @@ add_filter('es_forms_block_field_style_options', function(): array {
2939
],
3040
]
3141
];
32-
})
42+
}
3343
```

website/forms/php/filters/block/file/preview-remove-label.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@ title: Uploaded item remove button label
66
This filter allows you to change the label for the _Remove_ button in the preview section for the uploaded files. Within the provided string an SVG icon or similar can be included, or anything else that `Dropzone.js` supports.
77

88
```php
9-
add_filter('es_forms_block_file_preview_remove_label', function(): string {
10-
return 'Remove item'; // This can be string or svg.
11-
})
9+
\add_filter('es_forms_block_file_preview_remove_label', [$this, 'getBlockFilePreviewRemoveLabel']);
10+
11+
/**
12+
* Changing the default custom file preview remove label.
13+
*
14+
* This filter will override our default file preview remove label.
15+
*
16+
* @return string
17+
*/
18+
public function getBlockFilePreviewRemoveLabel(): string
19+
{
20+
return \esc_html__('Remove item', 'text-domain'); // This can be string or svg.
21+
}
1222
```

website/forms/php/filters/block/form-selector/form-templates.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@ title: Form templates
66
This filter allows adding custom form templates to the form selector. This way you can predefine form templates and insert them with a single click.
77

88
```php
9-
add_filter('es_forms_block_form_selector_form_templates', function(): array {
9+
\add_filter('es_forms_block_form_selector_form_templates', [$this, 'getBlockFormSelectorFormTemplates']);
10+
11+
/**
12+
* Add additional forms templates in blocks form selector.
13+
*
14+
* @return array<int, mixed>
15+
*/
16+
public function getBlockFormSelectorFormTemplates(): array
17+
{
1018
return [
1119
[
12-
"label" => "Test Form",
20+
"label" => "Test Forms",
1321
"slug" => "test-form",
1422
"blockName" => "eightshift-forms/mailer",
1523
'icon' => "<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20' fill='none'><path d='M7 1H2.5A1.5 1.5 0 0 0 1 2.5V7a1.5 1.5 0 0 0 1.5 1.5H7A1.5 1.5 0 0 0 8.5 7V2.5A1.5 1.5 0 0 0 7 1Zm0 10.5H2.5A1.5 1.5 0 0 0 1 13v4.5A1.5 1.5 0 0 0 2.5 19H7a1.5 1.5 0 0 0 1.5-1.5V13A1.5 1.5 0 0 0 7 11.5ZM17.5 1H13a1.5 1.5 0 0 0-1.5 1.5V7A1.5 1.5 0 0 0 13 8.5h4.5A1.5 1.5 0 0 0 19 7V2.5A1.5 1.5 0 0 0 17.5 1Zm0 10.5H13a1.5 1.5 0 0 0-1.5 1.5v4.5A1.5 1.5 0 0 0 13 19h4.5a1.5 1.5 0 0 0 1.5-1.5V13a1.5 1.5 0 0 0-1.5-1.5Z' stroke='currentColor' stroke-linecap='round' fill='none'/></svg>",
@@ -41,5 +49,5 @@ add_filter('es_forms_block_form_selector_form_templates', function(): array {
4149
]
4250
],
4351
];
44-
})
52+
}
4553
```

website/forms/php/filters/block/form/data-type-selector.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,27 @@ In other words, you can use this filter to change the value of the `formDataType
99
The attribute is used to output a `data-type-selector` HTML attribute of the form element.
1010

1111
```php
12-
add_filter('es_forms_block_form_data_type_selector', function(string $selector, array $attr): string {
12+
\add_filter('es_forms_block_form_data_type_selector', [$this 'getFormDataTypeSelector'], 10, 2);
13+
14+
/**
15+
* Changing the form type selector on render
16+
* This filter will override the attribute-provided type selector for a Form component.
17+
* Passes form component attributes to the callback function as well, so you can check all sorts of conditions when filtering.
18+
*
19+
* In other words, you can use this filter to change the value of the `formDataTypeSelector` attribute during a form render.
20+
* The attribute is used to output a `data-type-selector` HTML attribute of the form element.
21+
*
22+
* @param string $selector The data type selector to filter.
23+
* @param array<mixed> $attr Form component attributes.
24+
*
25+
* @return string Filtered value.
26+
*/
27+
public function getFormDataTypeSelector(string $selector, array $attr): string
28+
{
1329
if (($attr['formType'] ?? '') === 'mailchimp') {
1430
return '';
1531
}
1632

1733
return 'my-new-selector';
18-
}, 10, 2)
34+
}
1935
```

0 commit comments

Comments
 (0)