Advertisement
afsarwebdev

WP Custom widget 2 Complete for footer left part

May 14th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.01 KB | None | 0 0
  1. //Complete custom widget for footer left part
  2.  
  3. <?php
  4. class footer_left extends WP_Widget {
  5. // widget init
  6. public function __construct() {
  7. parent::__construct(
  8. 'footer-left',
  9. 'Custom Widget: Footer Left',
  10. array('description' => __('Display a Single Footer Left Block', 'goo_garden')) //goo_garden text domain
  11. );
  12. }
  13. // output the widget options in the back-end
  14. public function form($instance) {
  15. $defaults = array(
  16. 'ad_img' => 'http://localhost/wp/goo_garden/wp-content/uploads/2018/05/footer-logo.png',
  17. 'address' => __('Aloimoon Tower, 1712 Pioneer Ave. Suit #548 Cheyenne, WY 82001', 'goo_garden'),
  18. 'ad_link' => 'http://localhost/wp/goo_garden/',
  19. 'phone_number' => '(307) 509-0188',
  20. // 'dsc' => __('Description', 'goo_garden'),
  21. 'facebook' => 'https://www.facebook.com/',
  22. 'twitter' => 'https://twitter.com/',
  23. 'instagram' => 'https://www.instagram.com/?hl=en',
  24. 'linkedin' => 'https://www.linkedin.com/',
  25. );
  26.  
  27. $instance = wp_parse_args((array) $instance, $defaults);
  28.  
  29. ?>
  30.  
  31. <!-- ad image -->
  32. <p>
  33. <label for="<?php echo $this->get_field_id('ad_img') ?>"><?php _e('Ad Image', 'goo_garden'); ?></label>
  34. <input type="text" id="<?php echo $this->get_field_id('ad_img') ?>" name="<?php echo $this->get_field_name('ad_img') ?>" class="widefat" value="<?php echo esc_attr($instance['ad_img']); ?>">
  35. </p>
  36.  
  37. <!-- ad link -->
  38. <p>
  39. <label for="<?php echo $this->get_field_id('ad_link') ?>"><?php _e('Ad Link', 'goo_garden'); ?></label>
  40. <input type="text" id="<?php echo $this->get_field_id('ad_link') ?>" name="<?php echo $this->get_field_name('ad_link') ?>" class="widefat" value="<?php echo esc_attr($instance['ad_link']); ?>">
  41. </p>
  42.  
  43. <!-- address -->
  44. <p>
  45. <label for="<?php echo $this->get_field_id('address') ?>"><?php _e('Address', 'goo_garden'); ?></label>
  46. <input type="text" id="<?php echo $this->get_field_id('address') ?>" name="<?php echo $this->get_field_name('address') ?>" class="widefat" value="<?php echo esc_attr($instance['address']); ?>">
  47. </p>
  48.  
  49. <!-- Phone number -->
  50. <p>
  51. <label for="<?php echo $this->get_field_id('phone_number') ?>"><?php _e('Phone Number', 'goo_garden'); ?></label>
  52. <input type="text" id="<?php echo $this->get_field_id('phone_number') ?>" name="<?php echo $this->get_field_name('phone_number') ?>" class="widefat" value="<?php echo esc_attr($instance['phone_number']); ?>">
  53. </p>
  54.  
  55. <!-- facebook link -->
  56. <p>
  57. <label for="<?php echo $this->get_field_id('facebook') ?>"><?php _e('Facebook Link', 'goo_garden'); ?></label>
  58. <input type="text" id="<?php echo $this->get_field_id('facebook') ?>" name="<?php echo $this->get_field_name('facebook') ?>" class="widefat" value="<?php echo esc_attr($instance['facebook']); ?>">
  59. </p>
  60.  
  61. <!-- twitter link -->
  62. <p>
  63. <label for="<?php echo $this->get_field_id('twitter') ?>"><?php _e('Twitter Link', 'goo_garden'); ?></label>
  64. <input type="text" id="<?php echo $this->get_field_id('twitter') ?>" name="<?php echo $this->get_field_name('twitter') ?>" class="widefat" value="<?php echo esc_attr($instance['twitter']); ?>">
  65. </p>
  66.  
  67. <!-- instagram link -->
  68. <p>
  69. <label for="<?php echo $this->get_field_id('instagram') ?>"><?php _e('Instagram Link', 'goo_garden'); ?></label>
  70. <input type="text" id="<?php echo $this->get_field_id('instagram') ?>" name="<?php echo $this->get_field_name('instagram') ?>" class="widefat" value="<?php echo esc_attr($instance['instagram']); ?>">
  71. </p>
  72.  
  73. <!-- linkeidn link -->
  74. <p>
  75. <label for="<?php echo $this->get_field_id('linkedin') ?>"><?php _e('Linkedin Link', 'goo_garden'); ?></label>
  76. <input type="text" id="<?php echo $this->get_field_id('linkedin') ?>" name="<?php echo $this->get_field_name('linkedin') ?>" class="widefat" value="<?php echo esc_attr($instance['linkedin']); ?>">
  77. </p>
  78.  
  79.  
  80.  
  81. <?php
  82. }
  83.  
  84. // Process widget options for saving
  85. public function update($new_instance, $old_instance) {
  86. $instance = $old_instance;
  87.  
  88. // Ad image
  89. $instance['ad_img'] = strip_tags($new_instance['ad_img']);
  90.  
  91. // Ad link
  92. $instance['ad_link'] = strip_tags($new_instance['ad_link']);
  93.  
  94. // address
  95. $instance['address'] = strip_tags($new_instance['address']);
  96.  
  97. //Phone number
  98. $instance['phone_number'] = strip_tags($new_instance['phone_number']);
  99.  
  100. //Favebook link
  101. $instance['facebook'] = strip_tags($new_instance['facebook']);
  102.  
  103. //Twitter link
  104. $instance['twitter'] = strip_tags($new_instance['twitter']);
  105.  
  106. //Instagram link
  107. $instance['instagram'] = strip_tags($new_instance['instagram']);
  108.  
  109. //Linkedin link
  110. $instance['linkedin'] = strip_tags($new_instance['linkedin']);
  111.  
  112. return $instance;
  113. }
  114.  
  115. // Display the widget on the page
  116. public function widget($args, $instance) {
  117. extract($args);
  118.  
  119. $ad_img = $instance['ad_img'];
  120. $ad_link = $instance['ad_link'];
  121. $address = apply_filters('widget-address', $instance['address']);
  122. $phone_number = apply_filters('widget-phone', $instance['phone_number']);
  123. $facebook = $instance['facebook'];
  124. $twitter = $instance['twitter'];
  125. $instagram = $instance['instagram'];
  126. $linkedin = $instance['linkedin'];
  127.  
  128.  
  129. if($ad_img) : ?>
  130. <a href="<?php echo $ad_link; ?>"><img src="<?php echo $ad_img ?>" alt=""></a>
  131.  
  132. <?php endif;
  133.  
  134. echo $after_widget;
  135.  
  136. if ($address) {
  137. echo "<address>" . $before_address . $address . $after_address . '</address>';
  138. }
  139.  
  140. if ($phone_number) {
  141. echo "<div class='ic-phon'> Phone: " . $before_phonenumber . $phone_number . $before_phonenumber . "</div>";
  142. }
  143.  
  144. ?>
  145. <div class="ic-follow">
  146. <ul>
  147. <li>Follow us:</li>
  148. <?php
  149.  
  150. $social_medias= ['facebook','twitter','linkedin','instagram'];
  151. foreach ($social_medias as $social_media) {
  152. if (array_key_exists($social_media, $instance) && ($instance[$social_media] != null) ) {
  153. ?>
  154. <li>
  155. <a href="<?php echo $instance[$social_media]; ?>"><?php echo $social_media; ?></a>
  156. </li>
  157. <?php
  158. }
  159. }
  160. ?>
  161. </ul>
  162. </div>
  163. <?php
  164.  
  165. }
  166. }
  167. register_widget('footer_left');
  168.  
  169. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement