diff --git a/devs/developer-tutorials/add-design-options-tab.md b/devs/developer-tutorials/add-design-options-tab.md index 214204b..1724b4a 100644 --- a/devs/developer-tutorials/add-design-options-tab.md +++ b/devs/developer-tutorials/add-design-options-tab.md @@ -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). diff --git a/devs/developer-tutorials/editor-events.md b/devs/developer-tutorials/editor-events.md index ff911a0..19b9b7a 100644 --- a/devs/developer-tutorials/editor-events.md +++ b/devs/developer-tutorials/editor-events.md @@ -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 @@ -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 diff --git a/devs/developer-tutorials/make-a-param-responsive.md b/devs/developer-tutorials/make-a-param-responsive.md new file mode 100644 index 0000000..bb66145 --- /dev/null +++ b/devs/developer-tutorials/make-a-param-responsive.md @@ -0,0 +1,63 @@ +--- +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 + __( '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 + +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. diff --git a/devs/hooks/actions/overview.md b/devs/hooks/actions/overview.md index 3d9d15e..3dfadf4 100644 --- a/devs/hooks/actions/overview.md +++ b/devs/hooks/actions/overview.md @@ -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. | @@ -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. | diff --git a/devs/hooks/actions/vc_after_init_responsive.md b/devs/hooks/actions/vc_after_init_responsive.md new file mode 100644 index 0000000..2f623d2 --- /dev/null +++ b/devs/hooks/actions/vc_after_init_responsive.md @@ -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 +} +``` + +## Source + +File: `include/classes/core/class-vc-manager.php` diff --git a/devs/hooks/actions/vc_before_init_responsive.md b/devs/hooks/actions/vc_before_init_responsive.md new file mode 100644 index 0000000..eb51366 --- /dev/null +++ b/devs/hooks/actions/vc_before_init_responsive.md @@ -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 +} +``` + +## Source + +File: `include/classes/core/class-vc-manager.php` diff --git a/devs/hooks/filters/overview.md b/devs/hooks/filters/overview.md index 7f15134..19d143d 100644 --- a/devs/hooks/filters/overview.md +++ b/devs/hooks/filters/overview.md @@ -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. | @@ -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. | diff --git a/devs/hooks/filters/vc_edit_form_fields_attributes.md b/devs/hooks/filters/vc_edit_form_fields_attributes.md new file mode 100644 index 0000000..9b9a966 --- /dev/null +++ b/devs/hooks/filters/vc_edit_form_fields_attributes.md @@ -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 + '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` diff --git a/docs/building-with-wpbakery/element-design-options.md b/docs/building-with-wpbakery/element-design-options.md index 183a0cc..f2c35f0 100644 --- a/docs/building-with-wpbakery/element-design-options.md +++ b/docs/building-with-wpbakery/element-design-options.md @@ -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. +