darshan_saroya

new contact widget updated

Feb 20th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.72 KB | None | 0 0
  1. add_action( 'widgets_init','new_widget_contact');
  2.    function new_widget_contact() { return   register_widget( 'new_widget_contact' ); }
  3. /**
  4. * Adds footer contact  widget.
  5. */
  6. class new_widget_contact extends WP_Widget {
  7.  
  8.     /**
  9.      * Register widget with WordPress.
  10.      */
  11.     function __construct() {
  12.         parent::__construct(
  13.             'new_widget_contact', // Base ID
  14.             __('Enigma New Contact Widget', 'weblizar'), // Name
  15.             array( 'description' => __( 'Your contact details display', 'weblizar' ), ) // Args
  16.         );
  17.     }
  18.  
  19.     /**
  20.      * Front-end display of widget.
  21.      *
  22.      * @see WP_Widget::widget()
  23.      *
  24.      * @param array $args     Widget arguments.
  25.      * @param array $instance Saved values from database.
  26.      */
  27.     public function widget( $args, $instance ) {
  28.         $title = apply_filters( 'widget_title', $instance['title'] );
  29.         $Contact_address = apply_filters( 'widget_title', $instance['Contact_address'] );
  30.         $Contact_phone_number = apply_filters( 'widget_title', $instance['Contact_phone_number'] );
  31.         $Contact_phone_number2 = apply_filters( 'widget_title', $instance['Contact_phone_number2'] );
  32.         $Contact_phone_number3 = apply_filters( 'widget_title', $instance['Contact_phone_number3'] );
  33.         $website_add = apply_filters( 'widget_title', $instance['website_add'] );
  34.         $Contact_email_address = apply_filters( 'widget_title', $instance['Contact_email_address'] );  
  35.        
  36.         echo $args['before_widget'];
  37.         if ( ! empty( $title ) )
  38.         echo $args['before_title'] . $title . $args['after_title'];
  39.        
  40.         ?>
  41.         <address>
  42.             <?php if($Contact_address) { ?><p><i class="fa fa-map-marker"></i><?php  echo $Contact_address; ?></p><?php } ?>
  43.             <?php if($Contact_phone_number) { ?><p><i class="fa fa-phone"></i><a href="tel:<?php echo $Contact_phone_number; ?>"><?php  echo $Contact_phone_number;  ?></a></p><?php } ?>
  44.             <?php if($Contact_phone_number2) { ?><p><i class="fa fa-map-marker"></i>BTW nr.:<?php  echo $Contact_phone_number2;  ?></p><?php } ?>
  45.             <?php if($Contact_phone_number3) { ?><p><i class="fa fa-map-marker"></i>KVK nr.:<?php  echo $Contact_phone_number3;  ?></p><?php } ?>
  46.             <?php if($Contact_email_address) { ?><p><i class="fa fa-envelope"></i><a href="mailto:<?php  echo $Contact_email_address; ?>"><?php echo $Contact_email_address; ?></a></p><?php } ?>
  47.             <?php if($website_add) { ?><p><i class="fa fa-globe"></i><?php echo $website_add; ?></p><?php } ?>
  48.         </address>
  49.         <?php      
  50.         echo $args['after_widget']; // end of footer usefull links widget      
  51.     }
  52.  
  53.     /**
  54.      * Back-end widget form.
  55.      *
  56.      * @see WP_Widget::form()
  57.      *
  58.      * @param array $instance Previously saved values from database.
  59.      */
  60.     public function form( $instance ) {
  61.         if ( isset( $instance[ 'title' ] )) { $title = $instance[ 'title' ];    }
  62.         else {  $title = __( 'Contact Info', 'weblizar' );      }
  63.        
  64.         if ( isset( $instance[ 'Contact_phone_number' ] )) { $Contact_phone_number = $instance[ 'Contact_phone_number' ];   }
  65.         else {  $Contact_phone_number = __( '987-654-321', 'weblizar' );        }
  66.         if ( isset( $instance[ 'Contact_phone_number2' ] )) { $Contact_phone_number2 = $instance[ 'Contact_phone_number2' ];    }
  67.         else {  $Contact_phone_number2 = __( '987-654-321', 'weblizar' );       }
  68.         if ( isset( $instance[ 'Contact_phone_number3' ] )) { $Contact_phone_number3 = $instance[ 'Contact_phone_number3' ];    }
  69.         else {  $Contact_phone_number3 = __( '987-654-321', 'weblizar' );       }
  70.         if ( isset( $instance[ 'Contact_email_address' ] )) { $Contact_email_address = $instance[ 'Contact_email_address' ];    }
  71.         else {  $Contact_email_address = __( 'help@me.com ', 'weblizar' );      }
  72.        
  73.         if ( isset( $instance[ 'website_add' ] )) { $website_add = $instance[ 'website_add' ];  }
  74.         else {  $website_add = __( 'weblizar.com', 'weblizar' );        }
  75.        
  76.         if ( isset( $instance[ 'Contact_address' ] )) { $Contact_address = $instance[ 'Contact_address' ];  }
  77.         else {  $Contact_address = __( 'Auckland, NZ ', 'weblizar' );       }
  78.                
  79.         ?>
  80.         <p>
  81.         <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:','weblizar' ); ?></label>
  82.         <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
  83.         </p>
  84.         <p> <label for="<?php echo $this->get_field_id( 'Contact_phone_number' ); ?>"><?php _e( 'Contact phone number:','weblizar' ); ?></label>
  85.             <input class="widefat" id="<?php echo $this->get_field_id( 'Contact_phone_number' ); ?>" name="<?php echo $this->get_field_name( 'Contact_phone_number' ); ?>" type="text" value="<?php echo $Contact_phone_number ; ?>" />
  86.         </p>
  87.         <p> <label for="<?php echo $this->get_field_id( 'Contact_phone_number2' ); ?>"><?php _e( 'BTW nr.:','weblizar' ); ?></label>
  88.             <input class="widefat" id="<?php echo $this->get_field_id( 'Contact_phone_number2' ); ?>" name="<?php echo $this->get_field_name( 'Contact_phone_number2' ); ?>" type="text" value="<?php echo $Contact_phone_number2 ; ?>" />
  89.         </p>
  90.         <p> <label for="<?php echo $this->get_field_id( 'Contact_phone_number3' ); ?>"><?php _e( 'KVK nr.:','weblizar' ); ?></label>
  91.             <input class="widefat" id="<?php echo $this->get_field_id( 'Contact_phone_number3' ); ?>" name="<?php echo $this->get_field_name( 'Contact_phone_number3' ); ?>" type="text" value="<?php echo $Contact_phone_number3 ; ?>" />
  92.         </p>
  93.         <p>
  94.         <label for="<?php echo $this->get_field_id( 'Contact_email_address' ); ?>"><?php _e( 'E-mail address:','weblizar' ); ?></label>
  95.         <input class="widefat" id="<?php echo $this->get_field_id( 'Contact_email_address' ); ?>" name="<?php echo $this->get_field_name( 'Contact_email_address' ); ?>" type="text" value="<?php echo $Contact_email_address; ?>" />
  96.         </p>       
  97.         <p><label for="<?php echo $this->get_field_id( 'website_add' ); ?>"><?php _e( 'Website :','weblizar' ); ?></label>
  98.             <input class="widefat" id="<?php echo $this->get_field_id( 'website_add' ); ?>" name="<?php echo $this->get_field_name( 'website_add' ); ?>" type="text" value="<?php echo $website_add ; ?>" />
  99.         </p>       
  100.         <p>
  101.         <label for="<?php echo $this->get_field_id( 'Contact_address' ); ?>"><?php _e( 'Contact address:','weblizar' ); ?></label>
  102.         <input class="widefat" id="<?php echo $this->get_field_id( 'Contact_address' ); ?>" name="<?php echo $this->get_field_name( 'Contact_address' ); ?>" type="text" value="<?php echo $Contact_address; ?>" />
  103.         </p>
  104.        
  105.        
  106.        
  107.         <?php
  108.     }
  109.  
  110.     /**
  111.      * Sanitize widget form values as they are saved.
  112.      *
  113.      * @see WP_Widget::update()
  114.      *
  115.      * @param array $new_instance Values just sent to be saved.
  116.      * @param array $old_instance Previously saved values from database.
  117.      *
  118.      * @return array Updated safe values to be saved.
  119.      */
  120.     public function update( $new_instance, $old_instance ) {
  121.         $instance = array();
  122.         $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
  123.         $instance['Contact_address'] = ( ! empty( $new_instance['Contact_address'] ) ) ? strip_tags( $new_instance['Contact_address'] ) : '';$instance['timings'] = ( ! empty( $new_instance['timings'] ) ) ? strip_tags( $new_instance['timings'] ) : '';
  124.         $instance['website_add'] = ( ! empty( $new_instance['website_add'] ) ) ? strip_tags( $new_instance['website_add'] ) : '';
  125.         $instance['Contact_phone_number'] = ( ! empty( $new_instance['Contact_phone_number'] ) ) ? strip_tags( $new_instance['Contact_phone_number'] ) : '';
  126.         $instance['Contact_phone_number2'] = ( ! empty( $new_instance['Contact_phone_number2'] ) ) ? strip_tags( $new_instance['Contact_phone_number2'] ) : '';
  127.         $instance['Contact_phone_number3'] = ( ! empty( $new_instance['Contact_phone_number3'] ) ) ? strip_tags( $new_instance['Contact_phone_number3'] ) : '';    
  128.         $instance['Contact_email_address'] = ( ! empty( $new_instance['Contact_email_address'] ) ) ? strip_tags( $new_instance['Contact_email_address'] ) : '';
  129.         return $instance;
  130.     }
  131. }
Add Comment
Please, Sign In to add comment