Advertisement
Konark

Untitled

May 29th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.43 KB | None | 0 0
  1. class Bottom_Widget extends WP_Widget {
  2.  
  3. function __construct() {
  4. parent::__construct(
  5. // Выбираем ID для своего виджета
  6. 'bottom_top',
  7.  
  8. // Название виджета, показано в консоли
  9. __('Bottom Widget', 'bottom_widget_domain'),
  10.  
  11. // Описание виджета
  12. array( 'description' => __( 'Latest Project SLIDER', 'bottom_widget_domain' ), )
  13. );
  14. }
  15.  
  16. // Обновление виджета
  17. public function update( $new_instance, $old_instance ) {
  18. $instance = array();
  19. $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
  20. $instance['show_logo'] = !empty($new_instance['show_logo']) ? 1 : 0;
  21. $instance['soc_ico'] = !empty($new_instance['soc_ico']) ? 1 : 0;
  22. $instance['show_search'] = !empty($new_instance['show_search']) ? 1 : 0;
  23. $instance['twitter_url'] = ( ! empty( $new_instance['twitter_url'] ) ) ? strip_tags( $new_instance['twitter_url'] ) : '';
  24. $instance['facebook_url'] = ( ! empty( $new_instance['facebook_url'] ) ) ? strip_tags( $new_instance['facebook_url'] ) : '';
  25. $instance['rss_url'] = ( ! empty( $new_instance['rss_url'] ) ) ? strip_tags( $new_instance['rss_url'] ) : '';
  26. $instance['linked_url'] = ( ! empty( $new_instance['linked_url'] ) ) ? strip_tags( $new_instance['linked_url'] ) : '';
  27. $instance['skype_url'] = ( ! empty( $new_instance['skype_url'] ) ) ? strip_tags( $new_instance['skype_url'] ) : '';
  28. return $instance;
  29. }
  30.  
  31. // Создаем код для виджета -
  32. // сначала небольшая идентификация
  33. public function widget( $args, $instance ) {
  34. $title = apply_filters( 'widget_title', $instance['title'] );
  35. $show_logo = isset( $instance['show_logo'] ) ? (bool) $instance['show_logo'] : true;
  36. $soc_ico = isset( $instance['soc_ico'] ) ? (bool) $instance['soc_ico'] : true;
  37. $show_search = isset( $instance['show_search'] ) ? (bool) $instance['show_search'] : true;
  38. $twitter_url = $instance['twitter_url'];
  39. $facebook_url = $instance['facebook_url'];
  40. $rss_url = $instance['rss_url'];
  41. $linked_url = $instance['linked_url'];
  42. $skype_url = $instance['skype_url'];
  43.  
  44.  
  45. // до и после идентификации переменных темой
  46. echo $args['before_widget'];
  47. if ( ! empty( $title ) )
  48. echo $args['before_title'] . $title . $args['after_title'];
  49.     if($show_logo == true) {
  50.         echo '<div class="logo_sidebar">
  51.             <a href="http://vlad.net/"><img src="http://vlad.net/wp-content/themes/buildhome/img/logo-bottom.png" alt="logo"></a>
  52.         </div>';
  53.     }
  54.  
  55.     if($soc_ico == true) {
  56.          echo '<div class="soc_ico_sidebar">
  57.                     <ul>';
  58.                         if($facebook_url != '') {
  59.                             echo '<li><a href="'.$facebook_url.'"><span class="icon icon-facebook"></span></a></li>';
  60.                         }
  61.                         if($twitter_url != '') {
  62.                             echo '<li><a href="'.$twitter_url.'"><span class="icon icon-twitter"></span></a></li>';
  63.                         }
  64.                         if($rss_url != '') {
  65.                             echo '<li><a href="'.$rss_url.'"><span class="icon icon-rss"></span></a></li>';
  66.                         }
  67.                         if($linked_url != '') {
  68.                             echo '<li><a href="'.$linked_url.'"><span class="icon icon-linked"></span></a></li>';
  69.                         }
  70.                         if($skype_url != '') {
  71.                             echo '<li><a href="'.$skype_url.'"><span class="icon icon-skype"></span></a></li>';
  72.                         }
  73.                         echo '</ul>
  74.                 </div>';
  75.     }
  76.  
  77.     if($show_search == true) {
  78.          echo '<div class="search_bottom">
  79.                     <input type="text" placeholder="Search...">
  80.                     <button></button>
  81.                 </div>';
  82.     }                            
  83.     echo $args['after_widget'];
  84. }
  85.        
  86.  
  87. public function form( $instance ) {
  88. $defaults = array( 'title' => __('', 'example'));
  89. $instance = wp_parse_args( (array) $instance, $defaults );
  90. $show_logo = isset( $instance['show_logo'] ) ? (bool) $instance['show_logo'] : true;
  91. $soc_ico = isset( $instance['soc_ico'] ) ? (bool) $instance['soc_ico'] : true;
  92. $show_search = isset( $instance['show_search'] ) ? (bool) $instance['show_search'] : true;
  93. if ( isset( $instance[ 'twitter_url' ] ) ) {
  94.     $twitter_url = $instance[ 'twitter_url' ];
  95. }else {
  96.     $twitter_url = __( '', 'bottom_widget_domain' );
  97. }
  98. if ( isset( $instance[ 'facebook_url' ] ) ) {
  99.     $facebook_url = $instance[ 'facebook_url' ];
  100. }else {
  101.     $facebook_url = __( '', 'bottom_widget_domain' );
  102. }
  103. if ( isset( $instance[ 'rss_url' ] ) ) {
  104.     $rss_url = $instance[ 'rss_url' ];
  105. }else {
  106.     $rss_url = __( '', 'bottom_widget_domain' );
  107. }
  108. if ( isset( $instance[ 'linked_url' ] ) ) {
  109.     $linked_url = $instance[ 'linked_url' ];
  110. }else {
  111.     $linked_url = __( '', 'bottom_widget_domain' );
  112. }
  113. if ( isset( $instance[ 'skype_url' ] ) ) {
  114.     $skype_url = $instance[ 'skype_url' ];
  115. }else {
  116.     $skype_url = __( '', 'bottom_widget_domain' );
  117. }
  118.  
  119. ?>
  120. <p>
  121. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_logo'); ?>" name="<?php echo $this->get_field_name('show_logo'); ?>"<?php checked( $show_logo ); ?> />
  122. <label for="<?php echo $this->get_field_id('show_logo'); ?>"><?php _e( 'Display logo block?' ); ?></label></p>
  123. </p>
  124. <p>
  125. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('soc_ico'); ?>" name="<?php echo $this->get_field_name('soc_ico'); ?>"<?php checked( $soc_ico ); ?> />
  126. <label for="<?php echo $this->get_field_id('soc_ico'); ?>"><?php _e( 'Display socials block?' ); ?></label></p>
  127. </p>
  128. <p>
  129. <label for="<?php echo $this->get_field_id( 'facebook_url' ); ?>">Facebook Url</label>
  130. <input class="widefat" id="<?php echo $this->get_field_id( 'facebook_url' ); ?>"name="<?php echo $this->get_field_name( 'facebook_url' ); ?>" type="text" value="<?php echo esc_attr( $facebook_url ); ?>" />
  131. </p>
  132. <p>
  133. <label for="<?php echo $this->get_field_id( 'twitter_url' ); ?>">Twitter Url</label>
  134. <input class="widefat" id="<?php echo $this->get_field_id( 'twitter_url' ); ?>"name="<?php echo $this->get_field_name( 'twitter_url' ); ?>" type="text" value="<?php echo esc_attr( $twitter_url ); ?>" />
  135. </p>
  136. <p>
  137. <label for="<?php echo $this->get_field_id( 'rss_url' ); ?>">RSS Url</label>
  138. <input class="widefat" id="<?php echo $this->get_field_id( 'rss_url' ); ?>"name="<?php echo $this->get_field_name( 'rss_url' ); ?>" type="text" value="<?php echo esc_attr( $rss_url ); ?>" />
  139. </p>
  140. <p>
  141. <label for="<?php echo $this->get_field_id( 'linked_url' ); ?>">Linked Url</label>
  142. <input class="widefat" id="<?php echo $this->get_field_id( 'linked_url' ); ?>"name="<?php echo $this->get_field_name( 'linked_url' ); ?>" type="text" value="<?php echo esc_attr( $linked_url ); ?>" />
  143. </p>
  144. <p>
  145. <label for="<?php echo $this->get_field_id( 'skype_url' ); ?>">Skype Url</label>
  146. <input class="widefat" id="<?php echo $this->get_field_id( 'skype_url' ); ?>"name="<?php echo $this->get_field_name( 'skype_url' ); ?>" type="text" value="<?php echo esc_attr( $skype_url ); ?>" />
  147. </p>
  148. <p>
  149. <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_search'); ?>" name="<?php echo $this->get_field_name('show_search'); ?>"<?php checked( $show_search ); ?> />
  150. <label for="<?php echo $this->get_field_id('show_search'); ?>"><?php _e( 'Display search block?' ); ?></label></p>
  151. </p>
  152. <?php
  153. }
  154.    
  155.  
  156. }
  157.  
  158.  
  159. function bottom_widget() {
  160.     register_widget( 'Bottom_Widget' );
  161. }
  162.  
  163. add_action( 'widgets_init', 'bottom_widget' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement