esc_html__('Displays author information.', 'bloggerpress')) ); $this->social_networks = apply_filters( 'bloggerpress_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']; echo '
'; if (!empty($instance['author_img'])) { echo '
'; echo wp_get_attachment_image(absint($instance['author_img']), 'medium_large', '', array('class' => 'img-responsive')); echo '
'; } echo '
'; if (!empty($instance['title'])) { echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']; } if (!empty($instance['author_name'])) { echo '
' . esc_html($instance['author_name']) . '
'; } if (!empty($instance['author_pos'])) { echo '
' . esc_html($instance['author_pos']) . '
'; } if (!empty($instance['author_desc'])) { echo '
' . wpautop(wp_kses_post($instance['author_desc'])) . '
'; } $this->display_social_links($instance); echo '
'; // Closing wpmotif-author-description echo '
'; // Closing wpmotif-author-widget 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 = BloggerPress_SVG_Icons::get_social_link_svg($instance[$network]); if ($svg) { $social_links .= sprintf( '
  • %s
  • ', esc_url($instance[$network]), esc_attr(ucwords($network) . ' Profile'), $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:', 'bloggerpress'), 'author_name' => esc_html__('Author Name:', 'bloggerpress'), 'author_pos' => esc_html__('Author Position:', 'bloggerpress'), 'author_desc' => esc_html__('Description:', 'bloggerpress'), 'author_img' => esc_html__('Image:', 'bloggerpress'), 'social_border_radius' => esc_html__('Circular Social Icon', 'bloggerpress'), 'social_links_color' => esc_html__('Social Icon Color', 'bloggerpress'), ); 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_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', 'bloggerpress'), 'has-default-color' => esc_html__('Theme Color', 'bloggerpress'), 'has-brand-color' => esc_html__('Has Brand Color', 'bloggerpress'), ); 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', ); 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; } }