esc_html__( 'Displays author information.', 'bloglex' ) ) ); $this->social_networks = apply_filters( 'bloglex_author_widget_social_networks', array( 'facebook', 'twitter', 'linkedin', 'instagram', 'pinterest', 'youtube', 'threads', 'tiktok', 'twitch', 'vk', 'whatsapp', 'amazon', 'codepen', 'dropbox', 'flickr', 'vimeo', 'spotify', 'github', 'reddit', 'skype', 'soundcloud', ) ); } /** * Outputs the content for the current widget instance. */ public function widget( $args, $instance ) { echo $args['before_widget']; if ( ! empty( $instance['title'] ) ) { echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title']; } $image_border_radius = ! empty( $instance['image_border_radius'] ) ? ' has-border-radius' : ''; echo '
'; if ( ! empty( $instance['author_img'] ) ) { echo '
'; echo wp_get_attachment_image( absint( $instance['author_img'] ), 'medium_large', '', array( 'class' => 'img-responsive' ) ); echo '
'; } if ( ! empty( $instance['author_name'] ) ) { echo '

' . esc_html( $instance['author_name'] ) . '

'; } if ( ! empty( $instance['author_pos'] ) ) { echo '

' . esc_html( $instance['author_pos'] ) . '

'; } $this->display_social_links( $instance ); if ( ! empty( $instance['author_desc'] ) ) { echo '
' . wpautop( wp_kses_post( $instance['author_desc'] ) ) . '
'; } echo '
'; echo $args['after_widget']; } /** * Display social links. */ private function display_social_links( $instance ) { $social_networks = $this->social_networks; if ( empty( $social_networks ) || ! is_array( $social_networks ) ) { return; } $social_links = ''; foreach ( $social_networks as $network ) { if ( ! empty( $instance[ $network ] ) ) { $svg = Bloglex_SVG_Icons::get_social_link_svg( $instance[ $network ] ); if ( $svg ) { $social_links .= '
  • ' . $svg . '
  • '; } } } if ( ! empty( $social_links ) ) { $social_link_class = 'reset-list-style social-icons ' . $this->get_social_link_class( $instance ); echo '
    '; } } /** * Get social link class based on instance settings. */ private function get_social_link_class( $instance ) { $social_border_radius = ! empty( $instance['social_border_radius'] ) ? ' has-border-radius' : ''; $color = ! empty( $instance['social_links_color'] ) ? $instance['social_links_color'] : 'has-brand-background'; return $social_border_radius . ' ' . $color; } /** * Back-end widget form. */ public function form( $instance ) { $fields = array( 'title' => esc_html__( 'Title:', 'bloglex' ), 'author_name' => esc_html__( 'Author Name:', 'bloglex' ), 'author_pos' => esc_html__( 'Author Position:', 'bloglex' ), 'author_desc' => esc_html__( 'Description:', 'bloglex' ), 'author_img' => esc_html__( 'Image:', 'bloglex' ), 'image_border_radius' => esc_html__( 'Enable Image Border Radius', 'bloglex' ), 'social_border_radius' => esc_html__( 'Circular Social Icon', 'bloglex' ), 'social_links_color' => esc_html__( 'Social Icon Color', 'bloglex' ), ); foreach ( $fields as $field => $label ) { $value = ! empty( $instance[ $field ] ) ? $instance[ $field ] : ''; $this->render_field( $field, $label, $value, $instance ); } $this->render_social_network_fields( $instance ); } /** * Render a field in the form. */ private function render_field( $field, $label, $value, $instance ) { $field_id = $this->get_field_id( $field ); $field_name = $this->get_field_name( $field ); switch ( $field ) { case 'author_desc': echo '

    '; echo '

    '; break; case 'author_img': ?>

    '; } } ?>

    '; echo '

    '; break; case 'social_border_radius': echo '

    '; echo '

    '; break; case 'social_links_color': $default_value = 'has-brand-background'; // Set your default value here $selected_value = empty($value) ? $default_value : $value; echo '

    '; echo '

    '; break; default: echo '

    '; echo '

    '; break; } } /** * Render social network fields in the form. */ private function render_social_network_fields( $instance ) { foreach ( $this->social_networks as $network ) { $value = ! empty( $instance[ $network ] ) ? $instance[ $network ] : ''; ?>

    esc_html__( 'Has Brand Background', 'bloglex' ), 'has-default-color' => esc_html__( 'Theme Color', 'bloglex' ), 'has-brand-color' => esc_html__( 'Has Brand Color', 'bloglex' ), ); default: return array(); } } /** * Sanitize widget form values as they are saved. */ public function update( $new_instance, $old_instance ) { $instance = array(); $fields = array( 'title', 'author_name', 'author_pos', 'author_desc', 'author_img', 'image_border_radius', 'social_border_radius', 'social_links_color', ); foreach ( $fields as $field ) { $instance[ $field ] = ! empty( $new_instance[ $field ] ) ? strip_tags( $new_instance[ $field ] ) : ''; } foreach ( $this->social_networks as $network ) { $instance[ $network ] = ! empty( $new_instance[ $network ] ) ? esc_url_raw( $new_instance[ $network ] ) : ''; } return $instance; } }