set_settings(); $this->set_custom_icons(); $widget_ops = [ 'classname' => 'social_links', 'description' => __( 'Adds social media icons with custom links.', 'Avada' ), ]; $control_ops = [ 'id_base' => 'social_links-widget', ]; parent::__construct( 'social_links-widget', __( 'Avada: Social Links', 'Avada' ), $widget_ops, $control_ops ); } /** * Set settings for this widget, * with a fallback to some sane defaults if no customized settings are saved in the database. * * @access public * @since 4.0 * @return void */ public function set_settings() { $fusion_settings = class_exists( 'Fusion_Settings' ) ? awb_get_fusion_settings() : false; if ( $fusion_settings ) { $this->settings = [ 'social_media_icons' => $fusion_settings->get( 'social_media_icons' ), 'nofollow_social_links' => $fusion_settings->get( 'nofollow_social_links' ), ]; } else { $this->settings = [ 'social_media_icons' => [], 'nofollow_social_links' => '0', ]; } } /** * Sets custom icons array variable. * * @static * @access public * @since 5.0.0 * @return void */ public function set_custom_icons() { $theme_options_array = $this->settings['social_media_icons']; $custom_icons = []; if ( is_array( $theme_options_array ) && array_key_exists( 'icon', $theme_options_array ) && is_array( $theme_options_array['icon'] ) ) { $custom_icon_indices = array_keys( $theme_options_array['icon'], 'custom', true ); $i = 0; if ( isset( $custom_icon_indices ) && is_array( $custom_icon_indices ) ) { foreach ( $custom_icon_indices as $name => $index ) { $icon_key = 'custom_' . $index; $i++; $custom_icons[ $icon_key ] = [ 'label' => $theme_options_array['custom_title'][ $index ], 'color' => '', ]; } } } self::$custom_icons = $custom_icons; } /** * Echoes the widget content. * * @access public * @param array $args Display arguments including 'before_title', 'after_title', * 'before_widget', and 'after_widget'. * @param array $instance The settings for the particular instance of the widget. */ public function widget( $args, $instance ) { extract( $args ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract if ( ! is_array( $instance ) ) { $instance = []; } $title = apply_filters( 'widget_title', isset( $instance['title'] ) ? $instance['title'] : '', $instance, $this->id_base ); $add_class = ''; $style = ''; $nofollow = ( $this->settings['nofollow_social_links'] ) ? 'nofollow noopener noreferrer' : 'noopener noreferrer'; $to_social_networks = $this->settings['social_media_icons']; if ( ! isset( $instance['tooltip_pos'] ) || '' === $instance['tooltip_pos'] ) { $instance['tooltip_pos'] = 'top'; } if ( ! isset( $instance['icon_color'] ) || '' === $instance['icon_color'] ) { $instance['icon_color'] = '#bebdbd'; } if ( ! isset( $instance['boxed_icon'] ) || '' === $instance['boxed_icon'] ) { $instance['boxed_icon'] = 'Yes'; } if ( ! isset( $instance['boxed_color'] ) || '' === $instance['boxed_color'] ) { $instance['boxed_color'] = '#e8e8e8'; } if ( ! isset( $instance['boxed_icon_radius'] ) || '' === $instance['boxed_icon_radius'] ) { $instance['boxed_icon_radius'] = '4px'; } if ( ! isset( $instance['linktarget'] ) || '' === $instance['linktarget'] ) { $instance['linktarget'] = '_self'; } if ( ! isset( $instance['color_type'] ) || '' === $instance['color_type'] ) { $instance['color_type'] = 'custom'; } if ( isset( $instance['boxed_icon'] ) && isset( $instance['boxed_icon_radius'] ) && 'Yes' === $instance['boxed_icon'] && ( $instance['boxed_icon_radius'] || '0' === $instance['boxed_icon_radius'] ) ) { $instance['boxed_icon_radius'] = ( 'round' === $instance['boxed_icon_radius'] ) ? '50%' : $instance['boxed_icon_radius']; $style .= 'border-radius:' . $instance['boxed_icon_radius'] . ';'; } if ( isset( $instance['boxed_icon'] ) && 'Yes' === $instance['boxed_icon'] && isset( $instance['boxed_icon_padding'] ) && isset( $instance['boxed_icon_padding'] ) ) { $style .= 'padding:' . $instance['boxed_icon_padding'] . ';'; } if ( isset( $instance['boxed_icon'] ) && 'Yes' === $instance['boxed_icon'] ) { $add_class .= ' boxed-icons'; } if ( ! isset( $instance['icons_font_size'] ) || '' === $instance['icons_font_size'] ) { $instance['icons_font_size'] = '16px'; } $style .= 'font-size:' . $instance['icons_font_size'] . ';'; $social_networks = []; foreach ( $instance as $name => $value ) { if ( false !== strpos( $name, '_link' ) && $value ) { $new_value = str_replace( '_link', '', $name ); $new_value = ( 'facebook' === $new_value ) ? 'fb' : $new_value; $social_networks[ $name ] = $new_value; } } $social_networks_ordered = []; // Check TO Social Links, if not in $social_networks and use_to option is yes, then add. if ( isset( $instance['use_to'] ) && 'Yes' === $instance['use_to'] && isset( $to_social_networks ) && is_array( $to_social_networks ) ) { foreach ( $to_social_networks['icon'] as $key => $value ) { if ( empty( $value ) ) { continue; } $new_value = $value; $new_value = ( 'facebook' === $new_value ) ? 'fb' : $new_value; if ( ! in_array( $new_value, $social_networks, true ) && 'custom' !== $value ) { $social_networks[ $new_value . '_link' ] = $value; $instance[ $new_value . '_link' ] = $to_social_networks['url'][ $key ]; } } } if ( isset( $to_social_networks['fusionredux_repeater_data'] ) && $to_social_networks && 0 < count( $to_social_networks['fusionredux_repeater_data'] ) ) { // Loop through the set of social networks and order them // according to the Global Options > Social Media tab ordering. // Append those icons that are not set in Global Options at the end. foreach ( $social_networks as $name => $value ) { $compare_value = ( 'fb' === $value ) ? 'facebook' : $value; $social_network_position = array_search( $compare_value, $to_social_networks['icon'], true ); if ( $social_network_position || 0 === $social_network_position ) { $social_networks_ordered[ $social_network_position ] = $name; unset( $social_networks[ $name ] ); } else { $social_networks[ $name ] = $value . '_link'; } } // Make sure all custom icons from Global Options > Social Media tab are included, if the widget option is set. if ( isset( $instance['show_custom'] ) && 'Yes' === $instance['show_custom'] ) { $custom_icon_indices = array_keys( $to_social_networks['icon'], 'custom', true ); foreach ( $custom_icon_indices as $name => $index ) { $network_icon_height = $to_social_networks['custom_source'][ $index ]['height']; $network_icon_width = $to_social_networks['custom_source'][ $index ]['width']; $network_link = $to_social_networks['url'][ $index ]; // Check if different URL is set for this custom icon in the widget. If so, use that instead. $instance_key = 'custom_' . $index . '_link'; if ( isset( $instance[ $instance_key ] ) && '' !== $instance[ $instance_key ] ) { $network_link = $instance[ $instance_key ]; } $social_networks_ordered[ $index ] = [ 'network_name' => $to_social_networks['custom_title'][ $index ], 'network_icon' => $to_social_networks['custom_source'][ $index ]['url'], 'network_icon_height' => $network_icon_height, 'network_icon_width' => $network_icon_width, 'network_icon_mark' => isset( $to_social_networks['icon_mark'][ $index ] ) ? $to_social_networks['icon_mark'][ $index ] : '', 'network_link' => $network_link, ]; } foreach ( $social_networks_ordered as $index => $value ) { if ( is_integer( $index ) ) { unset( $social_networks[ 'custom_' . $index . '_link' ] ); } } } } ksort( $social_networks_ordered ); $social_networks_ordered = array_merge( $social_networks_ordered, $social_networks ); $icon_colors = []; $icon_colors_max = 1; if ( isset( $instance['icon_color'] ) && $instance['icon_color'] ) { $icon_colors = explode( '|', $instance['icon_color'] ); $icon_colors_max = count( $icon_colors ); } $box_colors = []; $box_colors_max = 1; if ( isset( $instance['boxed_color'] ) && $instance['boxed_color'] ) { $box_colors = explode( '|', $instance['boxed_color'] ); $box_colors_max = count( $box_colors ); } echo $before_widget; // phpcs:ignore WordPress.Security.EscapeOutput if ( $title ) { echo $before_title . $title . $after_title; // phpcs:ignore WordPress.Security.EscapeOutput } ?>
$value ) { $instance[ $key . '_link' ] = isset( $new_instance[ $key . '_link' ] ) ? $new_instance[ $key . '_link' ] : ''; } } return $instance; } /** * Outputs the settings update form. * * @access public * @param array $instance Current settings. * @return void */ public function form( $instance ) { $defaults = [ 'title' => __( 'Get Social', 'Avada' ), 'linktarget' => '', 'icons_font_size' => '16px', 'icon_color' => '', 'boxed_icon' => 'No', 'boxed_color' => '', 'color_type' => 'custom', 'boxed_icon_radius' => '4px', 'boxed_icon_padding' => '8px', 'tooltip_pos' => 'top', 'blogger_link' => '', 'bluesky_link' => '', 'deviantart_link' => '', 'discord_link' => '', 'digg_link' => '', 'dribbble_link' => '', 'dropbox_link' => '', 'email_link' => '', 'phone_link' => '', 'fb_link' => '', 'flickr_link' => '', 'forrst_link' => '', 'github_link' => '', 'instagram_link' => '', 'linkedin_link' => '', 'mastodon_link' => '', 'myspace_link' => '', 'paypal_link' => '', 'pinterest_link' => '', 'reddit_link' => '', 'rss_link' => '', 'skype_link' => '', 'snapchat_link' => '', 'teams_link' => '', 'soundcloud_link' => '', 'spotify_link' => '', 'telegram_link' => '', 'threads_link' => '', 'tiktok_link' => '', 'tumblr_link' => '', 'twitter_link' => '', 'twitch_link' => '', 'vimeo_link' => '', 'vk_link' => '', 'whatsapp_link' => '', 'wechat_link' => '', 'xing_link' => '', 'yahoo_link' => '', 'yelp_link' => '', 'youtube_link' => '', 'show_custom' => 'No', 'use_to' => 'No', ]; if ( 0 < count( self::$custom_icons ) ) { foreach ( self::$custom_icons as $key => $value ) { $defaults[ $key . '_link' ] = ''; } } $instance = wp_parse_args( (array) $instance, $defaults ); ?>
$value ) { $key = ( 'facebook' === $key ) ? 'fb' : $key; echo '
'; /* translators: The social-network label. */ echo ''; echo ''; echo '
'; } ?>