Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function wpb_load_widget() {
- register_widget( 'wpb_widget' );
- }
- add_action( 'widgets_init', 'wpb_load_widget' );
- class wpb_widget extends WP_Widget {
- function __construct() {
- parent::__construct(
- // Base ID of your widget
- 'he_social_icons',
- // Widget name will appear in UI
- __('Helge social icons', 'he_social_icons'),
- // Widget description
- array( 'description' => __( 'Social icons', 'he_social_icons' ), )
- );
- }
- public function widget( $args, $instance ) {
- $facebook = apply_filters( 'widget_facebook', $instance['facebook'] );
- $linkedin = apply_filters( 'widget_linkedin', $instance['linkedin'] );
- $instagram = apply_filters( 'widget_instagram', $instance['instagram'] );
- $email = apply_filters( 'widget_email', $instance['email'] );
- // before and after widget arguments are defined by themes
- echo $args['before_widget'];
- echo '<div class="he_social_content">';
- if ( ! empty( $facebook ) ) {
- echo $args['before_facebook'] . '<a href="' .$facebook . '" class="he_social_icon facebook" target="_BLANK"></a>' . $args['after_facebook'];
- }
- if ( ! empty( $instagram ) ) {
- echo $args['before_instagram'] . '<a href="' .$instagram . '" class="he_social_icon instagram" target="_BLANK"></a>' . $args['after_instagram'];
- }
- if ( ! empty( $linkedin ) ) {
- echo $args['before_linkedin'] . '<a href="' .$linkedin . '" class="he_social_icon linkedin" target="_BLANK"></a>' . $args['after_linkedin'];
- }
- if ( ! empty( $email ) ) {
- echo $args['before_email'] . '<a href="mailto:' .$email . '" class="he_social_icon email" target="_BLANK"></a>' . $args['after_email'];
- }
- echo '</div>';
- echo $args['after_widget'];
- }
- // Widget Backend
- public function form( $instance ) {
- // Facebook
- if ( isset( $instance[ 'facebook' ] ) ) {
- $facebook = $instance[ 'facebook' ];
- } else {
- $facebook = __( '#', 'he_social_icons' );
- }
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'facebook' ); ?>"><?php _e( 'Facebook:' ); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id( 'facebook' ); ?>" name="<?php echo $this->get_field_name( 'facebook' ); ?>" type="text" value="<?php echo esc_attr( $facebook ); ?>" />
- </p>
- <?php
- // LinkedIn
- if ( isset( $instance[ 'linkedin' ] ) ) {
- $linkedin = $instance[ 'linkedin' ];
- } else {
- $linkedin = __( '#', 'he_social_icons' );
- }
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'linkedin' ); ?>"><?php _e( 'Linkedin:' ); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id( 'linkedin' ); ?>" name="<?php echo $this->get_field_name( 'linkedin' ); ?>" type="text" value="<?php echo esc_attr( $linkedin ); ?>" />
- </p>
- <?php
- // Email
- if ( isset( $instance[ 'email' ] ) ) {
- $email = $instance[ 'email' ];
- } else {
- $email = __( '#', 'he_social_icons' );
- }
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'email' ); ?>"><?php _e( 'Email:' ); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id( 'email' ); ?>" name="<?php echo $this->get_field_name( 'email' ); ?>" type="text" value="<?php echo esc_attr( $email ); ?>" />
- </p>
- <?php
- // Instagram
- if ( isset( $instance[ 'instagram' ] ) ) {
- $instagram = $instance[ 'instagram' ];
- } else {
- $instagram = __( '#', 'he_social_icons' );
- }
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'instagram' ); ?>"><?php _e( 'Instagram:' ); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id( 'instagram' ); ?>" name="<?php echo $this->get_field_name( 'instagram' ); ?>" type="text" value="<?php echo esc_attr( $instagram ); ?>" />
- </p>
- <?php
- }
- // Updating widget replacing old instances with new
- public function update( $new_instance, $old_instance ) {
- $instance = array();
- $instance['facebook'] = ( ! empty( $new_instance['facebook'] ) ) ? strip_tags( $new_instance['facebook'] ) : '';
- $instance['instagram'] = ( ! empty( $new_instance['instagram'] ) ) ? strip_tags( $new_instance['instagram'] ) : '';
- $instance['linkedin'] = ( ! empty( $new_instance['linkedin'] ) ) ? strip_tags( $new_instance['linkedin'] ) : '';
- $instance['email'] = ( ! empty( $new_instance['email'] ) ) ? strip_tags( $new_instance['email'] ) : '';
- return $instance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement