Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. <?php
  2. // Register and load the widget
  3. function appointment_info_callout() {
  4. register_widget( 'appointment_info_widget' );
  5. }
  6. add_action( 'widgets_init', 'appointment_info_callout' );
  7.  
  8. // Creating the widget
  9. class appointment_info_widget extends WP_Widget {
  10.  
  11. function __construct() {
  12. parent::__construct(
  13. 'appointment_info_callout', // Base ID
  14. 'Appointment Info Widget', // Widget Name
  15. array(
  16. 'classname' => 'appointment_info_widget',
  17. 'description' => 'Appointment theme information widget.',
  18. ),
  19. array(
  20. 'width' => 600,
  21. )
  22. );
  23.  
  24. }
  25.  
  26. public function widget( $args, $instance ) {
  27.  
  28. echo $args['before_widget']; ?>
  29. <div class="contact-area">
  30. <div class="media">
  31. <div class="contact-icon">
  32. <?php if(!empty($instance['fa_icon'])) { ?>
  33. <i class="fa <?php echo $instance['fa_icon']; ?>"></i>
  34. <?php } else { ?>
  35. <i class="fa fa-mobile"></i>
  36. <?php } ?>
  37. </div>
  38. <div class="media-body">
  39. <?php if(!empty($instance['title'])) { ?>
  40. <h6><?php echo $instance['title']; ?></h6>
  41. <?php } else { ?>
  42. <h6><?php echo "Have a question? Call us now"; ?></h6>
  43. <?php } ?>
  44. <?php if(!empty($instance['description'])) { ?>
  45. <h4><?php echo $instance['description']; ?></h4>
  46. <?php } else { ?>
  47. <h4><?php echo "+82 334 843 52"; ?></h4>
  48. <?php } ?>
  49. </div>
  50. </div>
  51. </div>
  52.  
  53. <?php
  54. echo $args['after_widget'];
  55. }
  56.  
  57. // Widget Backend
  58. public function form( $instance ) {
  59. if ( isset( $instance[ 'title' ])){
  60. $title = $instance[ 'title' ];
  61. }
  62. else {
  63. $title = __( 'Have a question? Call us now', 'appointment' );
  64. }
  65. if ( isset( $instance[ 'fa_icon' ])){
  66. $fa_icon = $instance[ 'fa_icon' ];
  67. }
  68. else {
  69. $fa_icon = __( 'fa fa-phone', 'appointment' );
  70. }
  71. if ( isset( $instance[ 'description' ])){
  72. $description = $instance[ 'description' ];
  73. }
  74. else {
  75. $description = __( '+82 334 843 52', 'appointment' );
  76. }
  77.  
  78. // Widget admin form
  79. ?>
  80.  
  81. <h4 for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></h4>
  82. <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php if($title) echo esc_attr( $title ); else _e( 'Have a question? Call us now', 'appointment' );?>" />
  83.  
  84. <h4 for="<?php echo $this->get_field_id( 'fa_icon' ); ?>"><?php _e( 'Fontawesome icon:' ); ?></h4>
  85. <input class="widefat" id="<?php echo $this->get_field_id( 'fa_icon' ); ?>" name="<?php echo $this->get_field_name( 'fa_icon' ); ?>" type="text" value="<?php if($fa_icon) echo esc_attr( $fa_icon ); else _e( 'fa fa-phone', 'appointment' );?>" />
  86. <span><?php _e('Link to get fa-icon ','appointment'); ?><a href="http://fortawesome.github.io/Font-Awesome/icons/" target="_blank" ><?php _e('fa-icon','appointment'); ?></a></span>
  87.  
  88. <h4 for="<?php echo $this->get_field_id( 'description' ); ?>"><?php _e( 'Description:' ); ?></h4>
  89. <input class="widefat" id="<?php echo $this->get_field_id( 'description' ); ?>" name="<?php echo $this->get_field_name( 'description' ); ?>" type="text" value="<?php if($description) echo esc_attr($description); else _e( '+82 334 843 52', 'appointment' );?>" /><br><br>
  90.  
  91. <?php
  92. }
  93.  
  94. // Updating widget replacing old instances with new
  95. public function update( $new_instance, $old_instance ) {
  96.  
  97. $instance = array();
  98. $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
  99. $instance['fa_icon'] = ( ! empty( $new_instance['fa_icon'] ) ) ? strip_tags( $new_instance['fa_icon'] ) : '';
  100. $instance['description'] = ( ! empty( $new_instance['description'] ) ) ? $new_instance['description'] : '';
  101.  
  102. return $instance;
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement