class ET_Builder_Module_Sidebar extends ET_Builder_Module {
$this->name = esc_html__( 'Sidebar', 'et_builder' );
$this->plural = esc_html__( 'Sidebars', 'et_builder' );
$this->slug = 'et_pb_sidebar';
$this->vb_support = 'on';
$this->main_css_element = '%%order_class%%.et_pb_widget_area';
$this->settings_modal_toggles = array(
'main_content' => et_builder_i18n( 'Content' ),
'layout' => et_builder_i18n( 'Layout' ),
'title' => et_builder_i18n( 'Text' ),
$this->advanced_fields = array(
'label' => et_builder_i18n( 'Title' ),
'main' => "{$this->main_css_element} h3:first-of-type, {$this->main_css_element} h4:first-of-type, {$this->main_css_element} h5:first-of-type, {$this->main_css_element} h6:first-of-type, {$this->main_css_element} h2:first-of-type, {$this->main_css_element} h1:first-of-type, {$this->main_css_element} .widget-title, {$this->main_css_element} .widgettitle",
'label' => et_builder_i18n( 'Body' ),
'main' => "{$this->main_css_element}, {$this->main_css_element} li, {$this->main_css_element} li:before, {$this->main_css_element} a",
'line_height' => "{$this->main_css_element} p",
'margin_padding' => array(
'main' => '%%order_class%%',
'important' => array( 'custom_margin' ), // needed to overwrite last module margin-bottom styling
'use_background_layout' => true,
'background_layout' => array(
'main' => '%%order_class%%, %%order_class%% .widgettitle',
$this->custom_css_fields = array(
'label' => esc_html__( 'Widget', 'et_builder' ),
'selector' => '.et_pb_widget',
'label' => et_builder_i18n( 'Title' ),
'selector' => 'h4.widgettitle',
$this->help_videos = array(
'name' => esc_html__( 'An introduction to the Sidebar module', 'et_builder' ),
'label' => esc_html__( 'Alignment', 'et_builder' ),
'option_category' => 'layout',
'left' => et_builder_i18n( 'Left' ),
'right' => et_builder_i18n( 'Right' ),
'default_on_front' => 'left',
'tab_slug' => 'advanced',
'toggle_slug' => 'layout',
'description' => esc_html__( 'Choose which side of the page your sidebar will be on. This setting controls text orientation and border position.', 'et_builder' ),
'label' => esc_html__( 'Widget Area', 'et_builder' ),
'type' => 'select_sidebar',
'option_category' => 'basic_option',
'description' => esc_html__( 'Select a widget-area that you would like to display. You can create new widget areas within the Appearances > Widgets tab.', 'et_builder' ),
'toggle_slug' => 'main_content',
'computed_affects' => array(
'label' => esc_html__( 'Show Border Separator', 'et_builder' ),
'description' => esc_html__( 'Disabling the border separator will remove the solid line that appears to the left or right of sidebar widgets.', 'et_builder' ),
'type' => 'yes_no_button',
'option_category' => 'layout',
'on' => et_builder_i18n( 'Yes' ),
'off' => et_builder_i18n( 'No' ),
'default_on_front' => 'on',
'tab_slug' => 'advanced',
'toggle_slug' => 'layout',
'computed_callback' => array( 'ET_Builder_Module_Sidebar', 'get_sidebar' ),
'computed_depends_on' => array(
static function get_default_area() {
global $wp_registered_sidebars;
if ( ! empty( $wp_registered_sidebars ) ) {
$sidebar_ids = wp_list_pluck( $wp_registered_sidebars, 'id' );
// Return first sidebar id
return array_shift( $sidebar_ids );
* Get sidebar data for sidebar module
* @param string comma separated gallery ID
* @param string on|off to determine grid / slider layout
* @param array passed current page params
* @return string JSON encoded array of attachments data
static function get_sidebar( $args = array(), $conditional_tags = array(), $current_page = array() ) {
$args = wp_parse_args( $args, $defaults );
// Get any available widget areas so it isn't empty
if ( '' === $args['area'] ) {
$args['area'] = self::get_default_area();
if ( is_active_sidebar( $args['area'] ) ) {
dynamic_sidebar( $args['area'] );
$widgets = ob_get_contents();
* Renders the module output.
* @param array $attrs List of attributes.
* @param string $content Content being processed.
* @param string $render_slug Slug of module that is used for rendering output.
public function render( $attrs, $content, $render_slug ) {
$orientation = $this->props['orientation'];
$area = '' === $this->props['area'] ? self::get_default_area() : $this->props['area'];
$show_border = $this->props['show_border'];
$video_background = $this->video_background();
$parallax_image_background = $this->get_parallax_image_background();
if ( is_active_sidebar( $area ) ) {
dynamic_sidebar( $area );
$widgets = ob_get_contents();
"et_pb_widget_area_{$orientation}",
$this->get_text_orientation_classname(),
// Background layout class names.
$background_layout_class_names = et_pb_background_layout_options()->get_background_layout_class( $this->props );
$this->add_classname( $background_layout_class_names );
if ( 'on' !== $show_border ) {
$this->add_classname( 'et_pb_sidebar_no_border' );
// Remove automatically added classnames
// Background layout data attributes.
$data_background_layout = et_pb_background_layout_options()->get_background_layout_attrs( $this->props );
'<div%3$s class="%2$s"%6$s>
</div> <!-- .et_pb_widget_area -->',
$this->module_classname( $render_slug ),
$parallax_image_background, // #5
et_core_esc_previously( $data_background_layout )
new ET_Builder_Module_Sidebar();