Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.49 KB | None | 0 0
  1. <?php
  2.     function wpb_load_widget() {
  3.         register_widget( 'wpb_widget' );
  4.     }
  5.     add_action( 'widgets_init', 'wpb_load_widget' );
  6.  
  7.     class wpb_widget extends WP_Widget {
  8.         function __construct() {
  9.             parent::__construct(
  10.                 // Base ID of your widget
  11.                 'he_social_icons',
  12.                
  13.                 // Widget name will appear in UI
  14.                 __('Helge social icons', 'he_social_icons'),
  15.                
  16.                 // Widget description
  17.                 array( 'description' => __( 'Social icons', 'he_social_icons' ), )
  18.             );
  19.         }
  20.  
  21.         public function widget( $args, $instance ) {
  22.             $facebook = apply_filters( 'widget_facebook', $instance['facebook'] );
  23.             $linkedin = apply_filters( 'widget_linkedin', $instance['linkedin'] );
  24.             $instagram = apply_filters( 'widget_instagram', $instance['instagram'] );
  25.             $email = apply_filters( 'widget_email', $instance['email'] );
  26.              
  27.             // before and after widget arguments are defined by themes
  28.             echo $args['before_widget'];
  29.                 echo '<div class="he_social_content">';
  30.                     if ( ! empty( $facebook ) ) {
  31.                         echo $args['before_facebook'] . '<a href="' .$facebook . '" class="he_social_icon facebook" target="_BLANK"></a>' . $args['after_facebook'];
  32.                     }
  33.  
  34.                     if ( ! empty( $instagram ) ) {
  35.                         echo $args['before_instagram'] . '<a href="' .$instagram . '" class="he_social_icon instagram" target="_BLANK"></a>' . $args['after_instagram'];
  36.                     }
  37.  
  38.                     if ( ! empty( $linkedin ) ) {
  39.                         echo $args['before_linkedin'] . '<a href="' .$linkedin . '" class="he_social_icon linkedin" target="_BLANK"></a>' . $args['after_linkedin'];
  40.                     }
  41.  
  42.                     if ( ! empty( $email ) ) {
  43.                         echo $args['before_email'] . '<a href="mailto:' .$email . '" class="he_social_icon email" target="_BLANK"></a>' . $args['after_email'];
  44.                     }
  45.                 echo '</div>';
  46.             echo $args['after_widget'];
  47.         }
  48.                      
  49.         // Widget Backend
  50.         public function form( $instance ) {
  51.             // Facebook
  52.             if ( isset( $instance[ 'facebook' ] ) ) {
  53.                 $facebook = $instance[ 'facebook' ];
  54.             } else {
  55.                 $facebook = __( '#', 'he_social_icons' );
  56.             }
  57.             ?>
  58.                 <p>
  59.                 <label for="<?php echo $this->get_field_id( 'facebook' ); ?>"><?php _e( 'Facebook:' ); ?></label>
  60.                 <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 ); ?>" />
  61.                 </p>
  62.             <?php
  63.  
  64.             // LinkedIn
  65.             if ( isset( $instance[ 'linkedin' ] ) ) {
  66.                 $linkedin = $instance[ 'linkedin' ];
  67.             } else {
  68.                 $linkedin = __( '#', 'he_social_icons' );
  69.             }
  70.             ?>
  71.                 <p>
  72.                 <label for="<?php echo $this->get_field_id( 'linkedin' ); ?>"><?php _e( 'Linkedin:' ); ?></label>
  73.                 <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 ); ?>" />
  74.                 </p>
  75.             <?php
  76.  
  77.              // Email
  78.             if ( isset( $instance[ 'email' ] ) ) {
  79.                 $email = $instance[ 'email' ];
  80.             } else {
  81.                 $email = __( '#', 'he_social_icons' );
  82.             }
  83.             ?>
  84.                 <p>
  85.                 <label for="<?php echo $this->get_field_id( 'email' ); ?>"><?php _e( 'Email:' ); ?></label>
  86.                 <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 ); ?>" />
  87.                 </p>
  88.             <?php
  89.  
  90.             // Instagram
  91.             if ( isset( $instance[ 'instagram' ] ) ) {
  92.                 $instagram = $instance[ 'instagram' ];
  93.             } else {
  94.                 $instagram = __( '#', 'he_social_icons' );
  95.             }
  96.             ?>
  97.                 <p>
  98.                 <label for="<?php echo $this->get_field_id( 'instagram' ); ?>"><?php _e( 'Instagram:' ); ?></label>
  99.                 <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 ); ?>" />
  100.                 </p>
  101.             <?php
  102.         }
  103.                  
  104.         // Updating widget replacing old instances with new
  105.         public function update( $new_instance, $old_instance ) {
  106.             $instance = array();
  107.             $instance['facebook'] = ( ! empty( $new_instance['facebook'] ) ) ? strip_tags( $new_instance['facebook'] ) : '';
  108.             $instance['instagram'] = ( ! empty( $new_instance['instagram'] ) ) ? strip_tags( $new_instance['instagram'] ) : '';
  109.             $instance['linkedin'] = ( ! empty( $new_instance['linkedin'] ) ) ? strip_tags( $new_instance['linkedin'] ) : '';
  110.             $instance['email'] = ( ! empty( $new_instance['email'] ) ) ? strip_tags( $new_instance['email'] ) : '';
  111.             return $instance;
  112.         }
  113.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement