Skip to content

Commit

Permalink
Merge pull request #293 from infinum/feature/filters
Browse files Browse the repository at this point in the history
Fixing anonymous filter
  • Loading branch information
iruzevic authored Jan 31, 2024
2 parents cae9804 + 194ffe0 commit 559203c
Show file tree
Hide file tree
Showing 45 changed files with 414 additions and 114 deletions.
2 changes: 1 addition & 1 deletion website/blog/2022-04-25-using-assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ The output of the icon on frontend is very simple. In the Quote component, it wa
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:

```bash
wp boilerplate use_component --name=icon
wp boilerplate blocks use-component --name=icon
```

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:
Expand Down
6 changes: 3 additions & 3 deletions website/blog/2022-05-10-acf-in-a-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ This will generate a PHP code snippet that you can use in your theme. Now you ma

## CustomMeta class

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:
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:

```bash
wp boilerplate create_acf_meta --name=intro
wp boilerplate create acf-meta --name=intro
```

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:
Expand Down Expand Up @@ -113,7 +113,7 @@ It's better to use class constants because if you decide to change the field nam
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:

```bash
wp boilerplate create_theme_options
wp boilerplate create theme-options
```

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`:
Expand Down
14 changes: 5 additions & 9 deletions website/docs/legacy/v5/basics/blocks-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,18 @@ To remove all core patterns add this code to you `src/Blocks/Blocks.php` class.
Filter goes in the register method:
```php
// Remove block patterns.
add_filter('block_editor_settings', [$this, 'removeCorePatterns']);
add_action('after_setup_theme', [$this, 'removeCorePatterns']);
```

Callback method:
```php
/**
* Remove core block patterns
* Remove core block patterns.
*
* @param array $settings Array of block editor settings to filter out.
*
* @return array Filtered array.
* @return void
*/
public function removeCorePatterns(array $settings): array
public function removeCorePatterns(): void
{
$settings['__experimentalBlockPatterns'] = [];

return $settings;
remove_theme_support('core-block-patterns');
}
```
2 changes: 1 addition & 1 deletion website/forms/php/filters/admin/settings-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: Settings data
This filter allows adding a custom settings page in the WordPress admin area. Useful when creating custom option pages for Forms add-on plugins.

```php
add_filter('es_forms_admin_settings_data', 'getSettingsConfig');
\add_filter('es_forms_admin_settings_data', [$this, 'getSettingsConfig']);

/**
* Settings config data.
Expand Down
14 changes: 12 additions & 2 deletions website/forms/php/filters/block/country/alternative-data-set.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ For example, if you only want to allow choosing between 4 countries, you can do
* **onlyUse** - Allows providing a custom list of countries, instead of using the full dataset.

```php
add_filter('es_forms_block_country_alternative_data_set', function(): array {
\add_filter('es_forms_block_country_alternative_data_set', [$this, 'getBlockCountryAlternativeDataSet']);

/**
* Get country alternative changes for data set and provide filters.
*
* This filter will only provide alternative options and change the original list.
*
* @return array<mixed>
*/
public function getBlockCountryAlternativeDataSet(): array
{
{
return [
[
Expand Down Expand Up @@ -49,5 +59,5 @@ add_filter('es_forms_block_country_alternative_data_set', function(): array {
],
];
}
})
}
```
14 changes: 12 additions & 2 deletions website/forms/php/filters/block/field/style-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ title: Custom field classes
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.

```php
add_filter('es_forms_block_field_style_classes', function(array $attributes): array {
\add_filter('es_forms_block_field_style_classes', [$this, 'getBlockFieldStyleClasses']);

/**
* Add additional style classes to field block.
*
* @param array<string, mixed> $attributes Block attributes.
*
* @return array<string, mixed>
*/
public function getBlockFieldStyleClasses(array $attributes): array
{
return [
'input' => [
'custom-style'.
Expand All @@ -15,5 +25,5 @@ add_filter('es_forms_block_field_style_classes', function(array $attributes): ar
'default',
]
];
})
}
```
14 changes: 12 additions & 2 deletions website/forms/php/filters/block/field/style-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ title: Custom field styles
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.

```php
add_filter('es_forms_block_field_style_options', function(): array {
\add_filter('es_forms_block_field_style_options', [$this, 'getBlockFieldStyleOptions']);

/**
* Add additional style options to field block
*
* 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.
*
* @return array<string, mixed>
*/
public function getBlockFieldStyleOptions(): array
{
return [
'input' => [
[
Expand All @@ -29,5 +39,5 @@ add_filter('es_forms_block_field_style_options', function(): array {
],
]
];
})
}
```
16 changes: 13 additions & 3 deletions website/forms/php/filters/block/file/preview-remove-label.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ title: Uploaded item remove button label
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.

```php
add_filter('es_forms_block_file_preview_remove_label', function(): string {
return 'Remove item'; // This can be string or svg.
})
\add_filter('es_forms_block_file_preview_remove_label', [$this, 'getBlockFilePreviewRemoveLabel']);

/**
* Changing the default custom file preview remove label.
*
* This filter will override our default file preview remove label.
*
* @return string
*/
public function getBlockFilePreviewRemoveLabel(): string
{
return \esc_html__('Remove item', 'text-domain'); // This can be string or svg.
}
```
14 changes: 11 additions & 3 deletions website/forms/php/filters/block/form-selector/form-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ title: Form templates
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.

```php
add_filter('es_forms_block_form_selector_form_templates', function(): array {
\add_filter('es_forms_block_form_selector_form_templates', [$this, 'getBlockFormSelectorFormTemplates']);

/**
* Add additional forms templates in blocks form selector.
*
* @return array<int, mixed>
*/
public function getBlockFormSelectorFormTemplates(): array
{
return [
[
"label" => "Test Form",
"label" => "Test Forms",
"slug" => "test-form",
"blockName" => "eightshift-forms/mailer",
'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>",
Expand Down Expand Up @@ -41,5 +49,5 @@ add_filter('es_forms_block_form_selector_form_templates', function(): array {
]
],
];
})
}
```
20 changes: 18 additions & 2 deletions website/forms/php/filters/block/form/data-type-selector.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,27 @@ In other words, you can use this filter to change the value of the `formDataType
The attribute is used to output a `data-type-selector` HTML attribute of the form element.

```php
add_filter('es_forms_block_form_data_type_selector', function(string $selector, array $attr): string {
\add_filter('es_forms_block_form_data_type_selector', [$this 'getFormDataTypeSelector'], 10, 2);

/**
* Changing the form type selector on render
* This filter will override the attribute-provided type selector for a Form component.
* Passes form component attributes to the callback function as well, so you can check all sorts of conditions when filtering.
*
* In other words, you can use this filter to change the value of the `formDataTypeSelector` attribute during a form render.
* The attribute is used to output a `data-type-selector` HTML attribute of the form element.
*
* @param string $selector The data type selector to filter.
* @param array<mixed> $attr Form component attributes.
*
* @return string Filtered value.
*/
public function getFormDataTypeSelector(string $selector, array $attr): string
{
if (($attr['formType'] ?? '') === 'mailchimp') {
return '';
}

return 'my-new-selector';
}, 10, 2)
}
```
14 changes: 12 additions & 2 deletions website/forms/php/filters/block/form/global-msg-headings.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ title: Global msg headings
By default there are no headings on error or success messages but with this filter you will be able to set them. This filter is applied to all forms.

```php
add_filter('es_forms_block_form_global_msg_headings', function(): array {
\add_filter('es_forms_block_form_global_msg_headings', [$this, 'getGlobalMsgHeadings']);

/**
* Set global msg headings.
*
* This filter will set global message headings for success and error.
*
* @return array<string, string>
*/
public function getGlobalMsgHeadings(): array
{
return [
'success' => \__('Good news!', 'eightshift-form'),
'error' => \__('Something went wrong.', 'eightshift-form'),
];
})
}
```
18 changes: 13 additions & 5 deletions website/forms/php/filters/block/form/hide-global-msg-timeout.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ title: Global message timeout

This filter allows you to change the timeout of all global messages (e.g. after successful form submission), in milliseconds.


```php
add_filter('es_forms_block_form_hide_global_msg_timeout', function(): string {
return '10000'; // 10 seconds.
})

\add_filter('es_forms_block_form_hide_global_msg_timeout', [$this, 'getBlockFormHideGlobalMsgTimeout']);

/**
* Changing the default success hide global message wait time.
*
* This filter will override our default wait time before the global message is removed. The time is calculated in milliseconds. *Example: 1000ms = 1s*.
*
* @return string
*/
public function getBlockFormHideGlobalMsgTimeout(): string
{
return '10000'; // 10 seconds.
}
```
17 changes: 15 additions & 2 deletions website/forms/php/filters/block/form/phone-sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,24 @@ title: Phone sync
By default if you change the value on the phone field the country field (if present) will be updated automatically. If you want to disable this feature you can use this filter or use the form global/local settings. This filter will override global settings for phone sync.

```php
add_filter('es_forms_block_form_phone_sync', function(string $formType, string $formId): bool {
\add_filter('es_forms_block_form_phone_sync', [$this, 'getFormPhoneSync'], 10, 2);

/**
* Set phone sync settings.
*
* This filter will override global settings for phone sync.
*
* @param string $formType Type of form used like greenhouse, hubspot, etc.
* @param string $formId Form ID.
*
* @return bool
*/
public function getFormPhoneSync(string $formType, string $formId): bool
{
if ($formType === 'hubspot') {
return true;
}

return false;
}, 10, 2)
}
```
16 changes: 13 additions & 3 deletions website/forms/php/filters/block/form/redirect-timeout.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@ id: redirect-timeout
title: Redirect timeout
---


This filter allows you to change the delay for the redirect after a successful form submission, in milliseconds.

```php
add_filter('es_forms_block_form_redirection_timeout', function(): string {
\add_filter('es_forms_block_form_redirection_timeout', [$this, 'getBlockFormRedirectionTimeout']);

/**
* Changing the default success redirection wait time
*
* This filter will override our default wait time once the form returns success and it is redirected. The time is calculated in milliseconds. *Example: 1000ms = 1s*.
*
* @return string
*/
public function getBlockFormRedirectionTimeout(): string
{
return '1000'; // 1 seconds.
})
}
```


17 changes: 15 additions & 2 deletions website/forms/php/filters/block/form/success-redirect-url.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@ title: Success redirect URL
This filter allows you to override the success redirect URL, regardless of the one selected in Settings. With the `$formType` parameter you can customize the URL for each form type.

```php
add_filter('es_forms_block_form_success_redirect_url', function(string $formType, string $formId): string {
\add_filter('es_forms_block_form_success_redirect_url', [$this, 'getBlockFormSuccessRedirectUrl'], 10, 2);

/**
* Set success redirect url value.
*
* This filter will override settings for success redirect url.
*
* @param string $formType Type of form used like greenhouse, hubspot, etc.
* @param string $formId Form ID.
*
* @return string
*/
public function getBlockFormSuccessRedirectUrl(string $formType, string $formId): string
{
return 'https://infinum.com/custom-filter';
}, 10, 2)
}
```


Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,26 @@ While you can create variations list from the forms global setting, by using thi
Filter returns an array of arrays. The first value is the variation value and the second value is the variation label.

```php
add_filter('es_forms_block_form_success_redirect_variation_options', function(): string {
\add_filter('es_forms_block_form_success_redirect_variation_options', [$this, 'getBlockFormSuccessRedirectVariationOptions']);

/**
* Set success redirect variation options value.
*
* This filter will override settings for success redirect variation options.
*
* @return array<string, string>
*/
public function getBlockFormSuccessRedirectVariationOptions(): array
{
return [
[
'test1',
__('label1', '<text_domain>'),
\esc_html__('label1', '<text_domain>'),
],
[
'test2',
__('label2', '<text_domain>'),
\esc_html__('label2', '<text_domain>'),
],
];
});
}
```
Loading

0 comments on commit 559203c

Please sign in to comment.