Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions devs/developer-tutorials/add-design-options-tab.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ $css_class = apply_filters( VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG, vc_shortcode_cus
```

Important part in this snippet is `vc_shortcode_custom_css_class()` function call, it is parsing `css` attribute and outputs its name in the element's html markup.

Since version 9.1 every element with a `css_editor` param also gets the "Hide element" toggle at the top of the Design Options tab. Its value is stored in the `hide_element` attribute, with per device values in `hide_element_wpb_{device}`, and the hide classes are added through the `VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG` filter, so the template above needs no changes. To leave the toggle out, set `'settings' => [ 'hide_toggle' => false ]` on the param. The Design Options values themselves are set per device only when the param carries `'responsive' => true`: add it to the param above, or map the tab with `vc_config()->get_design_options_tab()`, which already carries it. Read more in [Make a param responsive](/devs/developer-tutorials/make-a-param-responsive).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Its value is stored in the hide_element attribute, with per device values in hide_element_wpb_{device}, and the hide classes are added through the VC_SHORTCODE_CUSTOM_CSS_FILTER_TAG filter, so the template above needs no changes. "
Looks like redundant and complicated data for users here; even I find it hard to understand looks better without it.

16 changes: 16 additions & 0 deletions devs/developer-tutorials/editor-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,21 @@ window.vc.events.on('save:error', function(error) {
```


## Responsive Device Events

```js
/**
* Fires when the device being edited changes: a device is selected in the
* navigation bar or "Apply styles only for selected device type" is switched.
* data.device is the device key (xl, lg, md, sm, xs), or null for global editing.
* Available since 9.1.
*/

window.vc.events.on('wpb:targetDeviceChange', function(data) {
console.log('Editing device:', data.device);
});
```

## Custom Parameter Events

### Dropdown/Select Events
Expand Down Expand Up @@ -398,6 +413,7 @@ jQuery(document).on('change', '.wpb_vc_param_value.attachment_id', function() {
| `save:error` | Save failed | error |
| `vc_iframe_loaded` | Frontend editor loaded | – |
| `vc_reload` | Editor reloading | – |
| `wpb:targetDeviceChange` | Edited device changed in the navigation bar | `{ device }` |

## Element-Specific Events

Expand Down
63 changes: 63 additions & 0 deletions devs/developer-tutorials/make-a-param-responsive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better to add this page to a page list here devs/developer-tutorials/overview/ cos right now it only in left menu

id: make-a-param-responsive
title: Make a param responsive
sidebar_label: Make a param responsive
sidebar_position: 28
hide_table_of_contents: true
slug: /developer-tutorials/make-a-param-responsive
---

# Make a param responsive

Starting from version 9.1 a mapped param can hold a different value per device. Add `'responsive' => true` to the param in your [vc_map()](/devs/inner-api/vc_map) call and the element edit window will show one field per device.

Two shared definitions already carry the flag: `vc_config()->get_design_options_tab()` (Design Options) and `vc_config()->get_css_animation()` (CSS animation). A `css_editor` or `css_animation` param written by hand needs it like any other param.

## Param mapping

```php
<?php
add_action( 'vc_before_init', 'your_name_integrateWithVC' );
function your_name_integrateWithVC() {
vc_map( [
'name' => __( 'Bar tag test', 'my-text-domain' ),
'base' => 'bartag',
'params' => [
[
'type' => 'textfield',
'heading' => __( 'Height', 'my-text-domain' ),
'param_name' => 'height',
'value' => '300',
'responsive' => true,
],
],
] );
}
class WPBakeryShortCode_Bartag extends WPBakeryShortCode {
}
```

When a device is selected in the navigation bar with "Apply styles only for selected device type" enabled, the edit window shows the field of that device, marked with a device icon.

## Saved values

The main param keeps its attribute and each device gets one more, named after it and the device key:

| Device | Attribute |
|-------------------|-------------------|
| Main param | `height` |
| Desktop | `height_wpb_xl` |
| Tablet horizontal | `height_wpb_lg` |
| Tablet vertical | `height_wpb_md` |
| Mobile horizontal | `height_wpb_sm` |
| Mobile vertical | `height_wpb_xs` |

Device left empty uses the value of the main param, and a device value equal to it is not stored. Pages saved before 9.1 simply have no such attributes.

## HTML output

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide a working code example here you can combine it together with you current mapping snippet
add_action( 'vc_before_init', 'your_name_integrateWithVC' );
function your_name_integrateWithVC() {

 vc_map( [
  'name' => __( 'Bar tag test', 'my-text-domain' ),
  'base' => 'bartag',
  'params' => [
   [
    'type' => 'textfield',
    'heading' => __( 'Height', 'my-text-domain' ),
    'param_name' => 'height',
    'value' => '300',
    'responsive' => true,
   ],
  ],
 ] );
}
class WPBakeryShortCode_Bartag extends WPBakeryShortCode {
}

so youser can with one click copy/paste it to his functions.php


In the element template, `wpb_get_responsive_values( $atts, 'height' )` returns the device values that were set, keyed by device key. Pass them to `wpb_responsive()->params()->add_css()` with the selector the rules are written for: each value is wrapped in the media query of its device and the rules are printed once per page. The class the selector targets comes from `get_element_class( $atts )` and is added to the element class list by `$this->getExtraClass()`.

This is how the plugin outputs CSS animation per device, see `WPBakeryShortCode::getCSSAnimation()`. As the output lives in the template, a theme that [replaced it with its own copy](/devs/developer-tutorials/change-shortcodes-html-output) before you added it shows the main value on every device until the copy is updated.

**Note:** with "Apply styles only for selected device type" disabled, device-specific values are not used. They stay in the content until the main value is changed while the toggle is off, which removes them.
2 changes: 2 additions & 0 deletions devs/hooks/actions/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function your_custom_function($param1, $param2) {
| [`vc_after_init_config`](/devs/hooks/actions/vc_after_init_config) | Fires after the configuration library has been initialized. |
| [`vc_after_init_license`](/devs/hooks/actions/vc_after_init_license) | Fires after the license manager has been initialized. |
| [`vc_after_init_modules`](/devs/hooks/actions/vc_after_init_modules) | Fires after the modules manager has been initialized. |
| [`vc_after_init_responsive`](/devs/hooks/actions/vc_after_init_responsive) | Fires after the responsive component has been initialized. |
| [`vc_after_init_settings`](/devs/hooks/actions/vc_after_init_settings) | Fires after the settings manager has been initialized. |
| [`vc_after_init_updater`](/devs/hooks/actions/vc_after_init_updater) | Fires after the updater component has been initialized. |
| [`vc_after_init_vc`](/devs/hooks/actions/vc_after_init_vc) | Fires after the main WPBakery Page Builder instance has been initialized. |
Expand All @@ -54,6 +55,7 @@ function your_custom_function($param1, $param2) {
| [`vc_before_init_frontend_editor`](/devs/hooks/actions/vc_before_init_frontend_editor) | Fires before the frontend editor component is initialized. |
| [`vc_before_init_license`](/devs/hooks/actions/vc_before_init_license) | Fires before the license component is initialized. |
| [`vc_before_init_modules`](/devs/hooks/actions/vc_before_init_modules) | Fires before the modules component is initialized. |
| [`vc_before_init_responsive`](/devs/hooks/actions/vc_before_init_responsive) | Fires before the responsive component is initialized. |
| [`vc_before_init_settings`](/devs/hooks/actions/vc_before_init_settings) | Fires before the settings component is initialized. |
| [`vc_before_init_updater`](/devs/hooks/actions/vc_before_init_updater) | Fires before the updater component is initialized. |
| [`vc_before_init_vc`](/devs/hooks/actions/vc_before_init_vc) | Fires before the main VC instance is initialized. |
Expand Down
26 changes: 26 additions & 0 deletions devs/hooks/actions/vc_after_init_responsive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
sidebar_class_name: hidden-sidebar-item
hide_table_of_contents: true
---

# vc_after_init_responsive

Fires after the responsive component has been initialized. This hook runs inside the `Vc_Manager::responsive()` method, after the `WPB_Responsive` instance has been created and stored in the factory. Available since version 9.1.

## Parameters

This action has no parameters.

## Usage

```php
add_action( 'vc_after_init_responsive', 'wpb_after_responsive_init' );

function wpb_after_responsive_init() {
// Run custom logic once the responsive services (breakpoints, devices, params, hide) are ready

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always better to have here something more visual code exmple then just a comment

}
```

## Source

File: `include/classes/core/class-vc-manager.php`
26 changes: 26 additions & 0 deletions devs/hooks/actions/vc_before_init_responsive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
sidebar_class_name: hidden-sidebar-item
hide_table_of_contents: true
---

# vc_before_init_responsive

Fires before the responsive component is initialized. This hook runs inside the `Vc_Manager::responsive()` method, the first time the responsive services are requested, before the `WPB_Responsive` instance is created. Available since version 9.1.

## Parameters

This action has no parameters.

## Usage

```php
add_action( 'vc_before_init_responsive', 'wpb_before_responsive_init' );

function wpb_before_responsive_init() {
// Run custom logic before the responsive services (breakpoints, devices, params, hide) are created

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always better to have here something more visual code exmple then just a comment

}
```

## Source

File: `include/classes/core/class-vc-manager.php`
3 changes: 2 additions & 1 deletion devs/hooks/filters/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function your_custom_function($value, $additional_params) {
| [`vc_edit_form_class`](/devs/hooks/filters/vc_edit_form_class) | Filters the array of CSS classes applied to the edit form fields container element. |
| [`vc_edit_form_css_class`](/devs/hooks/filters/vc_edit_form_css_class) | Filters the CSS class string applied to the shortcode edit form panel container. |
| [`vc_edit_form_enqueue_script`](/devs/hooks/filters/vc_edit_form_enqueue_script) | Filters the array of scripts registered for parameter types in the edit form. |
| [`vc_edit_form_fields_attributes`](/devs/hooks/filters/vc_edit_form_fields_attributes) | Filters the shortcode attributes of every element before they are used to populate the edit form fields. |
| [`vc_edit_form_fields_attributes_{tag}`](/devs/hooks/filters/vc_edit_form_fields_attributes_tag) | Filters the shortcode attributes before they are used to populate the edit form fields. |
| [`vc_edit_form_fields_optional_params`](/devs/hooks/filters/vc_edit_form_fields_optional_params) | Filters the list of optional parameter types that should not be initialized by default in the edit form. |
| [`vc_edit_form_fields_render_field_{type}_before`](/devs/hooks/filters/vc_edit_form_fields_render_field_type_before) | Filters the HTML output rendered **before** a parameter field of a specific type in the WPBakery element edit form. |
Expand Down Expand Up @@ -217,7 +218,7 @@ function your_custom_function($value, $additional_params) {
| [`wpb_module_ai_element_param_types`](/devs/hooks/filters/wpb_module_ai_element_param_types) | Filters the list of element parameter types that display the AI icon in the editor. |
| [`wpb_module_ai_text_field_words`](/devs/hooks/filters/wpb_module_ai_text_field_words) | Filters the list of keywords used to determine whether a `textfield` parameter should display the AI icon. |
| [`wpb_module_ai_type_response_route_lib`](/devs/hooks/filters/wpb_module_ai_type_response_route_lib) | Filters the routing configuration that maps element parameter types to their AI response handler classes and API endpoints. |
| [`wpb_navbar_getControlScreenSize`](/devs/hooks/filters/wpb_navbar_getControlScreenSize) | Filters the available screen sizes for the responsive preview control in the frontend editor navbar. |
| [`wpb_navbar_getControlScreenSize`](/devs/hooks/filters/wpb_navbar_getControlScreenSize) | Filters the device list of the responsive preview dropdown in the navigation bar of both editors. |
| [`wpb_set_post_custom_meta`](/devs/hooks/filters/wpb_set_post_custom_meta) | Filters the custom meta values associated with a post in the editor. |
| [`wpb_shortcode_acf_display_when_empty_value`](/devs/hooks/filters/wpb_shortcode_acf_display_when_empty_value) | Filters whether the ACF (Advanced Custom Fields) shortcode element should render output when the field value is empty. |
| [`wpb_toggle_heading`](/devs/hooks/filters/wpb_toggle_heading) | Filters the heading HTML output of the Toggle (FAQ) element. |
Expand Down
37 changes: 37 additions & 0 deletions devs/hooks/filters/vc_edit_form_fields_attributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
sidebar_class_name: hidden-sidebar-item
hide_table_of_contents: true
---

# vc_edit_form_fields_attributes

Filters the shortcode attributes of every element before they are used to populate the edit form fields. It runs before the element specific [`vc_edit_form_fields_attributes_{tag}`](/devs/hooks/filters/vc_edit_form_fields_attributes_tag) filter and suits conversions that apply to all elements. WPBakery Page Builder uses it to convert the legacy per device hide attributes to `hide_element`. Available since version 9.1.

Fires when WPBakery opens the element edit form popup, just after the form attributes are assembled and before they are rendered.

## Parameters

| # | Parameter | Type | Description |
|---|-----------|------|-------------|
| 1 | `$atts` | array | Attributes being passed through the filter chain. |
| 2 | `$tag` | string | Shortcode tag of the element being edited (e.g., `vc_column`). |
| 3 | `$settings` | array | Shortcode settings array from `WPBMap::getShortCode( $tag )`. |

## Usage

```php
<?php
add_filter( 'vc_edit_form_fields_attributes', 'my_convert_legacy_atts', 10, 3 );

function my_convert_legacy_atts( $atts, $tag, $settings ) {
// Rename an attribute that was dropped from all elements.
if ( isset( $atts['old_name'] ) && ! isset( $atts['new_name'] ) ) {
$atts['new_name'] = $atts['old_name'];
}
return $atts;
}
```

## Source

File: `include/classes/editors/class-vc-edit-form-fields.php`
18 changes: 9 additions & 9 deletions devs/hooks/filters/wpb_navbar_getControlScreenSize.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ hide_table_of_contents: true

# wpb_navbar_getControlScreenSize

Filters the available screen sizes for the responsive preview control in the frontend editor navbar. This allows adding, removing, or modifying the screen size options.
Filters the device list of the responsive preview dropdown in the navigation bar of both editors. Since version 9.1 the list is built from the [breakpoints](/docs/building-with-wpbakery/responsive-settings) set in Design Options, and selecting an entry also sets the device being edited.

## Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `$screen_sizes` | array | An array of screen size definitions. Each entry contains keys like `title` and other configuration values. |
| `$screen_sizes` | array | List of device entries, widest first. Each entry has `title`, `size` (CSS width of the preview, e.g. `1024px` or `100%`), `key` (icon: `default`, `landscape-tablets`, `portrait-tablets`, `landscape-smartphones` or `portrait-smartphones`), `device` (device key the entry edits: `xl`, `lg`, `md`, `sm` or `xs`), `min` and `max` (screen width range in px, `null` when open) and `active` on the default entry. |

## Usage

Expand All @@ -20,15 +20,15 @@ Filters the available screen sizes for the responsive preview control in the fro
add_filter( 'wpb_navbar_getControlScreenSize', 'my_custom_screen_sizes' );

function my_custom_screen_sizes( $screen_sizes ) {
// Add a custom screen size for ultra-wide monitors
$screen_sizes['ultrawide'] = [
'title' => 'Ultra Wide (2560px)',
'width' => '2560px',
];
return $screen_sizes;
// Remove the mobile horizontal preview from the dropdown.
return array_values( array_filter( $screen_sizes, function ( $screen ) {
return 'sm' !== $screen['device'];
} ) );
}
```

**Note:** when adding an entry, `key` must be one of the icon keys listed above, the navigation bar loads the icon template named after it.

## Source

File: `include/classes/editors/navbar/class-vc-navbar-frontend.php`
File: `include/classes/editors/navbar/class-vc-navbar.php`
8 changes: 8 additions & 0 deletions docs/building-with-wpbakery/element-design-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ Within Design Options it is possible to control:
- Background color
- Background image and position style

## Per device

Since the 9.1 update design options can be set for one device at a time: select a device in the navigation bar and enable "Apply styles only for selected device type". The device starts with a copy of the current values. Read more in [Responsive settings](/docs/building-with-wpbakery/responsive-settings).

## Hide element

"Hide element" toggle at the top of the tab hides the element on your site, or only on the selected device when you edit per device.

<div style={{textAlign: 'center'}}>
<iframe style={{maxWidth: '700px', width: '100%'}} height="450" src="https://www.youtube.com/embed/OoJF2jSKhVo?feature=oembed&modestbranding=1&showinfo=0&rel=0" title="Element Design Options" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</div>
Loading
Loading