Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Complete custom widget for footer left part
- <?php
- class footer_left extends WP_Widget {
- // widget init
- public function __construct() {
- parent::__construct(
- 'footer-left',
- 'Custom Widget: Footer Left',
- array('description' => __('Display a Single Footer Left Block', 'goo_garden')) //goo_garden text domain
- );
- }
- // output the widget options in the back-end
- public function form($instance) {
- $defaults = array(
- 'ad_img' => 'http://localhost/wp/goo_garden/wp-content/uploads/2018/05/footer-logo.png',
- 'address' => __('Aloimoon Tower, 1712 Pioneer Ave. Suit #548 Cheyenne, WY 82001', 'goo_garden'),
- 'ad_link' => 'http://localhost/wp/goo_garden/',
- 'phone_number' => '(307) 509-0188',
- // 'dsc' => __('Description', 'goo_garden'),
- 'facebook' => 'https://www.facebook.com/',
- 'twitter' => 'https://twitter.com/',
- 'instagram' => 'https://www.instagram.com/?hl=en',
- 'linkedin' => 'https://www.linkedin.com/',
- );
- $instance = wp_parse_args((array) $instance, $defaults);
- ?>
- <!-- ad image -->
- <p>
- <label for="<?php echo $this->get_field_id('ad_img') ?>"><?php _e('Ad Image', 'goo_garden'); ?></label>
- <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']); ?>">
- </p>
- <!-- ad link -->
- <p>
- <label for="<?php echo $this->get_field_id('ad_link') ?>"><?php _e('Ad Link', 'goo_garden'); ?></label>
- <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']); ?>">
- </p>
- <!-- address -->
- <p>
- <label for="<?php echo $this->get_field_id('address') ?>"><?php _e('Address', 'goo_garden'); ?></label>
- <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']); ?>">
- </p>
- <!-- Phone number -->
- <p>
- <label for="<?php echo $this->get_field_id('phone_number') ?>"><?php _e('Phone Number', 'goo_garden'); ?></label>
- <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']); ?>">
- </p>
- <!-- facebook link -->
- <p>
- <label for="<?php echo $this->get_field_id('facebook') ?>"><?php _e('Facebook Link', 'goo_garden'); ?></label>
- <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']); ?>">
- </p>
- <!-- twitter link -->
- <p>
- <label for="<?php echo $this->get_field_id('twitter') ?>"><?php _e('Twitter Link', 'goo_garden'); ?></label>
- <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']); ?>">
- </p>
- <!-- instagram link -->
- <p>
- <label for="<?php echo $this->get_field_id('instagram') ?>"><?php _e('Instagram Link', 'goo_garden'); ?></label>
- <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']); ?>">
- </p>
- <!-- linkeidn link -->
- <p>
- <label for="<?php echo $this->get_field_id('linkedin') ?>"><?php _e('Linkedin Link', 'goo_garden'); ?></label>
- <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']); ?>">
- </p>
- <?php
- }
- // Process widget options for saving
- public function update($new_instance, $old_instance) {
- $instance = $old_instance;
- // Ad image
- $instance['ad_img'] = strip_tags($new_instance['ad_img']);
- // Ad link
- $instance['ad_link'] = strip_tags($new_instance['ad_link']);
- // address
- $instance['address'] = strip_tags($new_instance['address']);
- //Phone number
- $instance['phone_number'] = strip_tags($new_instance['phone_number']);
- //Favebook link
- $instance['facebook'] = strip_tags($new_instance['facebook']);
- //Twitter link
- $instance['twitter'] = strip_tags($new_instance['twitter']);
- //Instagram link
- $instance['instagram'] = strip_tags($new_instance['instagram']);
- //Linkedin link
- $instance['linkedin'] = strip_tags($new_instance['linkedin']);
- return $instance;
- }
- // Display the widget on the page
- public function widget($args, $instance) {
- extract($args);
- $ad_img = $instance['ad_img'];
- $ad_link = $instance['ad_link'];
- $address = apply_filters('widget-address', $instance['address']);
- $phone_number = apply_filters('widget-phone', $instance['phone_number']);
- $facebook = $instance['facebook'];
- $twitter = $instance['twitter'];
- $instagram = $instance['instagram'];
- $linkedin = $instance['linkedin'];
- if($ad_img) : ?>
- <a href="<?php echo $ad_link; ?>"><img src="<?php echo $ad_img ?>" alt=""></a>
- <?php endif;
- echo $after_widget;
- if ($address) {
- echo "<address>" . $before_address . $address . $after_address . '</address>';
- }
- if ($phone_number) {
- echo "<div class='ic-phon'> Phone: " . $before_phonenumber . $phone_number . $before_phonenumber . "</div>";
- }
- ?>
- <div class="ic-follow">
- <ul>
- <li>Follow us:</li>
- <?php
- $social_medias= ['facebook','twitter','linkedin','instagram'];
- foreach ($social_medias as $social_media) {
- if (array_key_exists($social_media, $instance) && ($instance[$social_media] != null) ) {
- ?>
- <li>
- <a href="<?php echo $instance[$social_media]; ?>"><?php echo $social_media; ?></a>
- </li>
- <?php
- }
- }
- ?>
- </ul>
- </div>
- <?php
- }
- }
- register_widget('footer_left');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement