self::slug, 'description' => __('Social Profiles Widget.', self::locale), 'customize_selective_refresh' => true, ); // widget controls $control_ops = array( 'id_base' => 'am-social-widget', ); // load widget parent::__construct(self::slug, __(self::name, self::locale), $widget_ops, $control_ops ); } /** * Outputs the content of the widget on frontend * * @since 1.0.1 * * @param array $args array of standard parameters for widget area in active theme. * @param array $instance array of settings for this widget. */ public function widget( $args, $instance ) { // set widget id if ( ! isset( $args['widget_id'] ) ) { $args['widget_id'] = $this->id; } // widget title $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Social Profiles', self::locale ); // apply filter widget_title. $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); // link target $link_target = isset( $instance['link_target'] ) ? $instance['link_target'] : false; // before widget markup from widget area args. echo $args['before_widget']; // title of widget wrapped in before/after title from widget area args. if ( $title !== '' ) { echo $args['before_title'] . $title . $args['after_title']; } echo '

'; $social_profiles = array( 'facebook' => 'Facebook', 'twitter' => 'Twitter', 'linkedin' => 'LinkedIn', 'pinterest' => 'Pinterest', 'gplus' => 'Google Plus', 'youtube' => 'Youtube', 'rss' => 'RSS', ); foreach( $social_profiles as $social => $title ) { $url = esc_url( $instance[$social] ); $target = $link_target ? 'target="_blank"' : ''; if( $url ) { echo '' . $this->get_icon_svg($social) . '' . $title . ' '; } } echo '

'; // after widget markup from widget area args. echo $args['after_widget']; } /** * Saving & Updating of widget admin settings are handled here. * * @since 1.0.1 * * @param array $new_instance array of new settings submitted by admin * @param array $old_instance array of the old settings. * @return array Updated settings to save. */ public function update( $new_instance, $old_instance ) { $instance = $old_instance; // widget title $instance['title'] = sanitize_text_field( $new_instance['title'] ); // social profiles $social_profiles = array( 'facebook' => 'Facebook URL', 'twitter' => 'Twitter URL', 'linkedin' => 'LinkedIn URL', 'pinterest' => 'Pinterest URL', 'gplus' => 'Google Plus URL', 'youtube' => 'Youtube URL', 'rss' => 'RSS URL', ); foreach( $social_profiles as $social => $title ) { $instance[$social] = sanitize_text_field( $new_instance[$social] ); } // link target $instance['link_target'] = isset( $new_instance['link_target'] ) ? (bool) $new_instance['link_target'] : false; return $instance; } /** * Outputs the settings form of the widget on admin area. * * @since 1.0.1 * * @param array $instance array of current settings for this widget */ public function form( $instance ) { // widget title $title = isset( $instance['title'] ) ? $instance['title'] : ''; // social profiles for creating inputs. $social_profiles = array( 'facebook' => 'Facebook URL:', 'twitter' => 'Twitter URL:', 'linkedin' => 'LinkedIn URL:', 'pinterest' => 'Pinterest URL:', 'gplus' => 'Google Plus URL:', 'youtube' => 'Youtube URL:', 'rss' => 'RSS URL:', ); $link_target = isset( $instance['link_target'] ) ? (bool) $instance['link_target'] : false; ?>

$title ) { echo '

'; $social_val = isset( $instance[$social] ) ? $instance[$social] : ''; $html = ''; $html .= ''; echo $html; echo '

'; } // end foreach $social_profiles ?>

/>