Advertisement
Guest User

about-widgets.php

a guest
Jan 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.82 KB | None | 0 0
  1. <?php
  2.  
  3. add_action('widgets_init','register_themeum_about_widget');
  4.  
  5. function register_themeum_about_widget()
  6. {
  7.     register_widget('Themeum_About_Widget');
  8. }
  9.  
  10. class Themeum_About_Widget extends WP_Widget{
  11.  
  12.     public function __construct() {
  13.         parent::__construct( 'Themeum_About_Widget', esc_html__("Themeum About Us Widgets",'personalblog'), array('description' => esc_html__("This About Us Widgets",'personalblog')) );
  14.     }
  15.  
  16.  
  17.     /*-------------------------------------------------------
  18.      *              Front-end display of widget
  19.      *-------------------------------------------------------*/
  20.  
  21.     public function widget( $args, $instance ) {
  22.         extract( $args );
  23.  
  24.         # Our variables from the widget settings.
  25.         $title = apply_filters('widget_title', $instance['title'] );
  26.  
  27.         echo $before_widget;
  28.  
  29.         if($instance['about_img1']) {
  30.             echo '<img src="'. esc_url(get_site_url()) . $instance['about_img1'].'" class="img-responsive" alt="'.esc_html__('image','personalblog').'">';
  31.         }
  32.  
  33.         if ( $title ) {
  34.             echo $before_title . $title . $after_title;
  35.         }
  36.  
  37.         if( isset($instance['about_text']) && $instance['about_text'] ) {
  38.             echo '<div class="about-desc">'.$instance['about_text'].'</div>';
  39.         }
  40.  
  41.         ?> 
  42.  
  43.         <?php
  44.  
  45.         echo $after_widget;
  46.     }
  47.  
  48.  
  49.     /*-------------------------------------------------------
  50.      *              Sanitize data, save and retrive
  51.      *-------------------------------------------------------*/
  52.  
  53.     public function update( $new_instance, $old_instance ) {
  54.         $instance = $old_instance;
  55.  
  56.         # Strip tags from title and name to remove HTML
  57.         $instance['title']              = strip_tags( $new_instance['title'] );
  58.         $instance['about_img1']         = $new_instance['about_img1'];
  59.         $instance['about_text']         = $new_instance['about_text'];
  60.  
  61.         return $instance;
  62.     }
  63.  
  64.  
  65.     /*-------------------------------------------------------
  66.      *              Back-End display of widget
  67.      *-------------------------------------------------------*/
  68.    
  69.     public function form( $instance )
  70.     {
  71.  
  72.         $defaults = array(  
  73.                 'title'             => '',
  74.                 'about_img1'        => '',
  75.                 'about_text'        => '',
  76.             );
  77.  
  78.         $instance = wp_parse_args( (array) $instance, $defaults );
  79.        ?>
  80.  
  81.         <p>
  82.             <label for="<?php echo esc_attr($this->get_field_id( 'about_img1' )); ?>"><?php esc_html_e( 'About Image URL', 'personalblog' ); ?></label>
  83.  
  84.             <input type="hidden" id="<?php echo $this->get_field_id('about_img1');?>" name="<?php echo $this->get_field_name('about_img1');?>" class="<?php echo $this->get_field_id('about_img1');?>" value="<?php echo $instance['about_img1']; ?>"/>
  85.             <button id="<?php echo $this->get_field_id('about_img1');?>" class="custom-upload button" data-url="<?php echo esc_url(get_site_url()); ?>"><?php echo esc_html__('Upload image','personalblog'); ?></button>
  86.             <img class="<?php echo $this->get_field_id('about_img1');?>" src="<?php echo esc_url(get_site_url()) . $instance['about_img1']; ?> "/>
  87.         </p>
  88.  
  89.         <p>
  90.             <label for="<?php echo esc_attr($this->get_field_id( 'title' )); ?>"><?php _e('Title :', 'personalblog'); ?></label>
  91.             <input id="<?php echo esc_attr($this->get_field_id( 'title' )); ?>" name="<?php echo esc_attr($this->get_field_name( 'title' )); ?>" value="<?php echo esc_attr($instance['title']); ?>" style="width:100%;" />
  92.         </p>
  93.        
  94.         <p>
  95.             <label for="<?php echo esc_attr($this->get_field_id( 'about_text' )); ?>"><?php esc_html_e('About Text :', 'personalblog'); ?></label>
  96.             <textarea class="widefat" id="<?php echo esc_attr($this->get_field_id('about_text'));?>" name="<?php echo esc_attr($this->get_field_name('about_text')); ?>" style="height:150px;"><?php echo esc_attr($instance['about_text']); ?></textarea>
  97.         </p>
  98.            
  99.  
  100.     <?php
  101.     }
  102. }
  103.  
  104. // .widget_themeum_about_widget img {
  105. //     width: 146px;
  106. //     height: 146px;
  107. //     border-radius: 50%;
  108. //     display: inline-block;
  109. // }
  110.  
  111. // .widget_themeum_about_widget {
  112. //     text-align: center;
  113. // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement