get_builder_status() ) { add_action( 'wp_footer', [ $this, 'widget_options_object' ], 999 ); } } $is_builder = ( function_exists( 'fusion_is_preview_frame' ) && fusion_is_preview_frame() ) || ( function_exists( 'fusion_is_builder_frame' ) && fusion_is_builder_frame() ); if ( ! $is_builder ) { add_filter( 'widget_title', [ $this, 'filter_widget_title' ], 10, 3 ); add_filter( 'tribe_widget_arguments', [ $this, 'filter_tec_widget_title' ], 10 ); } } /** * Add styles and scripts. * * @access public * @since 6.2.1 * @return void */ public function add_scripts_styles() { $theme_info = wp_get_theme(); $screen = get_current_screen(); // General JS for fields. if ( 'widgets' === $screen->base && current_user_can( 'switch_themes' ) ) { if ( function_exists( 'AWB_Global_Colors' ) ) { AWB_Global_Colors()->enqueue(); } wp_enqueue_script( 'avada-fusion-options', Avada::$template_dir_url . '/assets/admin/js/avada-fusion-options.js', [ 'jquery', 'jquery-ui-sortable' ], $theme_info->get( 'Version' ), false ); } } /** * Hides the widget title if title option is set to "no". * * @since 6.2.1 * @access public * @param string $title The widget title. Default 'Pages'. * @param array $instance Array of settings for the current widget. * @param mixed $base_id The widget ID. * @return string The widget title. */ public function filter_widget_title( $title = '', $instance = [], $base_id = false ) { if ( isset( $instance['fusion_display_title'] ) && 'no' === $instance['fusion_display_title'] ) { return ''; } return $title; } /** * Hides the TEC widget title if title option is set to "no". * * @since 7.6.1 * @access public * @param array $updated_instance The widget options. * @return array The updated widget options. */ public function filter_tec_widget_title( $updated_instance ) { if ( isset( $updated_instance['fusion_display_title'] ) && 'no' === $updated_instance['fusion_display_title'] ) { $updated_instance['title'] = ''; } return $updated_instance; } /** * Init all options that we're going to add. * * @since 5.3.0 * @access public * @return void */ public function init_options() { $this->widget_options = [ 'fusion_display_title' => [ 'key' => 'fusion_display_title', 'title' => esc_html__( 'Display Widget Title', 'Avada' ), 'description' => esc_html__( 'Choose to enable or disable the widget title. Specifically useful for WP\'s default widget titles.', 'Avada' ), 'default' => 'yes', 'choices' => [ 'yes' => esc_html__( 'Yes', 'Avada' ), 'no' => esc_html__( 'No', 'Avada' ), ], 'type' => 'radio_button_set', ], 'fusion_padding_color' => [ 'key' => 'fusion_padding_color', 'title' => esc_html__( 'Padding', 'Avada' ), 'description' => esc_html__( 'Controls the padding for this widget container. Enter value including any valid CSS unit, ex: 10px.', 'Avada' ), 'css_property' => 'padding', 'type' => 'text', ], 'fusion_margin' => [ 'key' => 'fusion_margin', 'title' => esc_html__( 'Margin', 'Avada' ), 'description' => esc_html__( 'Controls the margin for this widget container. Enter value including any valid CSS unit, ex: 10px.', 'Avada' ), 'css_property' => 'margin', 'type' => 'text', ], 'fusion_bg_color' => [ 'key' => 'fusion_bg_color', 'title' => esc_html__( 'Background Color', 'Avada' ), 'description' => esc_html__( 'Controls the background color for this widget container.', 'Avada' ), 'css_property' => 'background-color', 'type' => 'colorpickeralpha', ], 'fusion_bg_radius_size' => [ 'key' => 'fusion_bg_radius_size', 'title' => esc_html__( 'Background Border Radius', 'Avada' ), 'description' => esc_html__( 'Controls the background border radius for this widget container.', 'Avada' ), 'css_property' => 'border-radius', 'type' => 'text', ], 'fusion_border_size' => [ 'key' => 'fusion_border_size', 'title' => esc_html__( 'Border Size', 'Avada' ), 'description' => esc_html__( 'Controls the border size for this widget container.', 'Avada' ), 'css_property' => 'border-width', 'type' => 'range', 'min' => 0, 'max' => 50, 'step' => 1, 'value' => 0, ], 'fusion_border_style' => [ 'key' => 'fusion_border_style', 'title' => esc_html__( 'Border Style', 'Avada' ), 'description' => esc_html__( 'Controls the border style for this widget container.', 'Avada' ), 'css_property' => 'border-style', 'type' => 'select', 'default' => 'solid', 'dependency' => [ [ 'element' => 'fusion_border_size', 'value' => '0', 'operator' => '!=', ], ], 'choices' => [ 'solid' => esc_html__( 'Solid', 'Avada' ), 'dotted' => esc_html__( 'Dotted', 'Avada' ), 'dashed' => esc_html__( 'Dashed', 'Avada' ), ], ], 'fusion_border_color' => [ 'key' => 'fusion_border_color', 'title' => esc_html__( 'Border Color', 'Avada' ), 'description' => esc_html__( 'Controls the border color for this widget container.', 'Avada' ), 'css_property' => 'border-color', 'type' => 'colorpickeralpha', 'dependency' => [ [ 'element' => 'fusion_border_size', 'value' => '0', 'operator' => '!=', ], ], ], 'fusion_divider_color' => [ 'key' => 'fusion_divider_color', 'title' => esc_html__( 'Divider Color', 'Avada' ), 'description' => esc_html__( 'Controls the color of dividers in this widget container. Leave empty for the Global Options default value or no dividers when using the vertical menu widget.', 'Avada' ), 'css_property' => 'border-color', 'type' => 'colorpickeralpha', ], 'fusion_align' => [ 'key' => 'fusion_align', 'title' => esc_html__( 'Content Align', 'Avada' ), 'description' => esc_html__( 'Controls content alignment for this widget container. Inherit means it will inherit alignment from its parent element.', 'Avada' ), 'css_property' => 'text-align', 'type' => 'select', 'choices' => [ '' => esc_html__( 'Inherit', 'Avada' ), 'left' => esc_html__( 'Left', 'Avada' ), 'right' => esc_html__( 'Right', 'Avada' ), 'center' => esc_html__( 'Center', 'Avada' ), ], ], 'fusion_align_mobile' => [ 'key' => 'fusion_align_mobile', 'title' => esc_html__( 'Mobile Content Align', 'Avada' ), 'description' => esc_html__( 'Controls mobile content alignment for this widget container. Inherit means it will inherit alignment from its parent element.', 'Avada' ), 'css_property' => 'text-align', 'type' => 'select', 'choices' => [ '' => esc_html__( 'Inherit', 'Avada' ), 'left' => esc_html__( 'Left', 'Avada' ), 'right' => esc_html__( 'Right', 'Avada' ), 'center' => esc_html__( 'Center', 'Avada' ), ], ], ]; } /** * Add widget options to form * * @since 5.3.0 * @access public * @param object $widget WP_Widget object, passed by reference. * @param null|string $return Return null if new fields are added. * @param array $instance An array of the widget's settings. */ public function add_widget_styling_options( $widget, $return, $instance ) { $this->start_widget_options(); ?> widget_options as $option ) : ?>
  • ' . esc_attr__( 'Reset to default.', 'Avada' ) . '' . esc_attr__( 'Using default value.', 'Avada' ) . ''; } ?>

    $title ) : ?>
  • end_widget_options(); } /** * Open widget options container. * * @since 5.3.0 * @access private * @return void */ private function start_widget_options() { ?>
    widget_options as $option ) { // For vertical menu widget, convert the old border_color option to the new fusion_divider_color one. if ( 'fusion_divider_color' === $option['key'] && empty( $new_instance['fusion_divider_color'] ) && ! isset( $old_instance['fusion_divider_color'] ) && ! empty( $new_instance['border_color'] ) ) { $new_instance['fusion_divider_color'] = $new_instance['border_color']; unset( $new_instance['border_color'] ); } $instance[ $option['key'] ] = ! empty( $new_instance[ $option['key'] ] ) ? sanitize_text_field( $new_instance[ $option['key'] ] ) : ''; } return $instance; } /** * Prints widget styles based on options. * Desktop styles are printed using style element attribute. * Mobile styles are printed inline. * * @since 5.3.0 * @access public * @param array $params Widget params. * @return mixed */ public function add_widget_styles( $params ) { global $wp_registered_widgets; if ( ! isset( $params[0] ) ) { return $params; } $sidebar_id = $params[0]['id']; // Get the id for the current sidebar we're processing. $widget_id = $params[0]['widget_id']; $widget_obj = $wp_registered_widgets[ $widget_id ]; $widget_num = $widget_obj['params'][0]['number']; $widget_opt = $this->get_widget_opt( $widget_obj ); $style = ''; $style_mobile = ''; $divider_styles = ''; // If calendar and no alignment set, set to default. if ( isset( $widget_opt[ $widget_num ] ) && ! isset( $widget_opt[ $widget_num ]['fusion_align'] ) && false !== strpos( $widget_id, 'calendar' ) ) { $widget_opt[ $widget_num ]['fusion_align'] = ''; } foreach ( $this->widget_options as $option ) { if ( isset( $widget_opt[ $widget_num ][ $option['key'] ] ) ) { if ( 'fusion_align' === $option['key'] && false !== strpos( $widget_id, 'calendar' ) ) { $alignment = ( '' === $widget_opt[ $widget_num ][ $option['key'] ] ) ? 'default' : $widget_opt[ $widget_num ][ $option['key'] ]; $params[0]['before_widget'] = str_replace( 'class="', 'class="fusion-widget-align-' . $alignment . ' ', $params[0]['before_widget'] ); } if ( 'fusion_align' === $option['key'] || 'fusion_align_mobile' === $option['key'] ) { if ( 'fusion_align_mobile' === $option['key'] && '' === $widget_opt[ $widget_num ][ $option['key'] ] && '' !== $widget_opt[ $widget_num ]['fusion_align'] ) { if ( false !== strpos( $sidebar_id, 'avada-footer-widget-' ) && Avada()->settings->get( 'footer_widgets_center_content' ) ) { $widget_opt[ $widget_num ][ $option['key'] ] = 'center'; } else { $widget_opt[ $widget_num ][ $option['key'] ] = 'initial'; } } if ( '' !== $widget_opt[ $widget_num ][ $option['key'] ] ) { $alignment = ( '' === $widget_opt[ $widget_num ][ $option['key'] ] ) ? 'default' : $widget_opt[ $widget_num ][ $option['key'] ]; $css_class = ( 'fusion_align' === $option['key'] ? 'fusion-widget-align-' : 'fusion-widget-mobile-align-' ) . $alignment; $params[0]['before_widget'] = str_replace( 'class="', 'class="' . esc_attr( $css_class ) . ' ', $params[0]['before_widget'] ); } } if ( '' !== $widget_opt[ $widget_num ][ $option['key'] ] && isset( $option['css_property'] ) ) { if ( false === strpos( $option['key'], 'mobile' ) ) { if ( 'border-width' === $option['css_property'] ) { $widget_opt[ $widget_num ][ $option['key'] ] = (int) $widget_opt[ $widget_num ][ $option['key'] ] . 'px'; } $style .= $option['css_property'] . ': ' . $widget_opt[ $widget_num ][ $option['key'] ] . ';'; if ( 'border-radius' === $option['css_property'] ) { $style .= 'overflow:hidden;'; } } else { $style_mobile .= '#' . $widget_id . '{' . $option['css_property'] . ':' . $widget_opt[ $widget_num ][ $option['key'] ] . ' !important;}'; } } } } // Set border color to transparent and border size to 0px it those field were left empty, but border style isn't. if ( isset( $widget_opt[ $widget_num ]['fusion_border_style'] ) && '' !== $widget_opt[ $widget_num ]['fusion_border_style'] ) { if ( ! isset( $widget_opt[ $widget_num ]['fusion_border_color'] ) || '' === $widget_opt[ $widget_num ]['fusion_border_color'] ) { $style .= 'border-color:transparent;'; } if ( ! isset( $widget_opt[ $widget_num ]['fusion_border_size'] ) || '' === $widget_opt[ $widget_num ]['fusion_border_size'] ) { $style .= 'border-width:0px;'; } } if ( ! empty( $style ) ) { $params[0]['before_widget'] = str_replace( '>', ' style="' . esc_attr( $style ) . '">', $params[0]['before_widget'] ); } if ( isset( $widget_opt[ $widget_num ]['fusion_divider_color'] ) && '' !== $widget_opt[ $widget_num ]['fusion_divider_color'] ) { $fusion_divider_color = Fusion_Sanitize::color( $widget_opt[ $widget_num ]['fusion_divider_color'] ); $divider_styles = '#' . $widget_id . ' li { border-color:' . $fusion_divider_color . ';}'; if ( false !== strpos( $params[0]['widget_id'], 'tag_cloud' ) ) { $divider_styles .= '#' . $widget_id . ' .tagcloud a { border-color:' . $fusion_divider_color . ';}'; } elseif ( false !== strpos( $params[0]['widget_id'], 'menu-widget' ) ) { $divider_styles .= '#' . $widget_id . ' .fusion-widget-menu ul li a:after { color:' . $fusion_divider_color . ';}'; } } // Special handling for vertical menu widget, to take into account the deprecated border_color option. if ( false !== strpos( $params[0]['widget_id'], 'avada-vertical-menu-widget' ) ) { if ( isset( $widget_opt[ $widget_num ]['border_color'] ) && ! isset( $widget_opt[ $widget_num ]['fusion_divider_color'] ) ) { $widget_opt[ $widget_num ]['fusion_divider_color'] = $widget_opt[ $widget_num ]['border_color']; } if ( '' !== $widget_opt[ $widget_num ]['fusion_divider_color'] ) { $fusion_divider_color = Fusion_Sanitize::color( $widget_opt[ $widget_num ]['fusion_divider_color'] ); $divider_styles .= '#' . $widget_id . ' .menu { border-right-color:' . $fusion_divider_color . ' !important;border-top-color:' . $fusion_divider_color . ' !important;}'; $divider_styles .= '#' . $widget_id . ' .menu li a { border-bottom-color:' . $fusion_divider_color . ' !important; }'; $divider_styles .= '#' . $widget_id . ' .right .menu { border-left-color:' . $fusion_divider_color . ' !important; }'; } else { $divider_styles .= '#' . $widget_id . ' > ul.menu { margin-top: -8px; }'; // phpcs:ignore WordPress.Security.EscapeOutput } } if ( ! empty( $style_mobile ) ) { $style_mobile = '@media (max-width: ' . Avada()->settings->get( 'content_break_point' ) . 'px){' . $style_mobile . '}'; } if ( ! empty( $style_mobile ) || ! empty( $divider_styles ) ) { $params[0]['before_widget'] = '' . $params[0]['before_widget']; } return $params; } /** * Get widget options. * * @since 5.3.0 * @access private * @param object $widget WP_Widget object. * @return mixed|void */ private function get_widget_opt( $widget ) { $widget_opt = get_option( $widget['callback'][0]->option_name ); return $widget_opt; } /** * Creates the JS object for widget options. * * @since 6.0.0 * @access public * @return void. */ public function widget_options_object() { echo ''; } } /* Omit closing PHP tag to avoid "Headers already sent" issues. */