Advertisement
Guest User

Untitled

a guest
Sep 16th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.35 KB | None | 0 0
  1. <?php
  2. if( !defined('ABSPATH') ) exit;
  3. if( !function_exists('Mars_LoginForm_Widget') ){
  4.     function Mars_LoginForm_Widget() {
  5.         register_widget('Mars_LoginForm_Widget_Class');
  6.     }
  7.     add_action('widgets_init', 'Mars_LoginForm_Widget');
  8. }
  9. class Mars_LoginForm_Widget_Class extends WP_Widget{
  10.    
  11.     function __construct(){
  12.         $widget_ops = array( 'classname' => 'mars-loginform-widget', 'description' => __('VT Login/Profile Widget', 'mars') );
  13.    
  14.         parent::__construct( 'mars-loginform-widget' , __('VT Login/Profile Widget', 'mars') , $widget_ops);
  15.     }  
  16.    
  17.     function widget($args, $instance){
  18.         global $videotube, $post;
  19.         $html = null;
  20.         extract( $args );
  21.         $title = apply_filters('widget_title', isset( $instance['title'] ) ? $instance['title'] : null );
  22.         $uploader_url = ( !empty( $instance['uploader_url'] ) && $instance['uploader_url'] != -1 ) ? get_permalink( $instance['uploader_url'] )  : '#';
  23.         $profile_url = ( !empty( $instance['profile_url'] ) && $instance['profile_url'] != -1 ) ? get_permalink( $instance['profile_url'] )  : '#';
  24.         $el_class = !empty( $instance['el_class'] ) ? esc_attr( $instance['el_class'] ) : null;
  25.         $html .=  $before_widget;
  26.         if( !empty( $title ) ){
  27.             $html .= $args['before_title'] . $title . $args['after_title'];
  28.         }
  29.        
  30.         $args = array(
  31.             'echo'           => false,
  32.             'form_id'        => 'vt_loginform',
  33.             'label_username' => __( 'Username','mars' ),
  34.             'label_password' => __( 'Password','mars' ),
  35.             'label_remember' => __( 'Remember Me','mars' ),
  36.             'label_log_in'   => __( 'Log In','mars' ),
  37.             'id_username'    => 'user_login',
  38.             'id_password'    => 'user_pass',
  39.             'id_remember'    => 'rememberme',
  40.             'id_submit'      => 'wp-submit',
  41.             'remember'       => true,
  42.             'value_username' => NULL,
  43.             'value_remember' => false
  44.         );
  45.         if( ! get_current_user_id() ){
  46.             $html .= '<div class="alert alert-danger" style="display:none;"></div>';
  47.             $html .= wp_login_form( apply_filters( 'mars_loginform_args' , $args) );
  48.            
  49.             if( shortcode_exists( 'wordpress_social_login' ) ){
  50.                 $html .= do_shortcode( '[wordpress_social_login]' );
  51.             }
  52.  
  53.         }
  54.         else{
  55.             $user_data = get_user_by('id', get_current_user_id());
  56.             $html .= '
  57.                 <div class="profile-widget-header '.$el_class.'">
  58.                     <div class="profile-widget-image">
  59.                         <a href="'.get_author_posts_url(get_current_user_id()).'">'.get_avatar( get_current_user_id(), 80 ).'</a>
  60.                     </div>                 
  61.                     <div class="profile-widget-info">
  62.                         <h3>'.$user_data->display_name.'</h3>';
  63.                         if( $uploader_url != '#' ){
  64.                             $html .= '<span class="profile-widget-info-item"><i class="fa fa-cloud"></i> <a href="'.$uploader_url.'">'.__('Upload','mars').'</a></span>';
  65.                         }
  66.                         $html .= '<span class="profile-widget-info-item"><i class="fa fa-star"></i> <a href="'.get_author_posts_url(get_current_user_id()).'">'.__('Channel','mars').'</a></span>';
  67.                         if( $profile_url != '#' ){
  68.                             $html .= '<span class="profile-widget-info-item"><i class="fa fa-user"></i> <a href="'.$profile_url.'">'.__('Profile','mars').'</a></span>';
  69.                         }
  70.                         $html .= '<span class="profile-widget-info-item"><i class="fa fa-sign-out"></i> <a href="'.wp_logout_url( home_url() ).'">'.__('Sign out','mars').'</a></span>
  71.                     </div>
  72.                 </div>
  73.             ';
  74.         }
  75.         $html .= $after_widget;
  76.         print $html;
  77.     }
  78.     function update( $new_instance, $old_instance ) {
  79.         $instance = $old_instance;
  80.         $instance['title'] = strip_tags( $new_instance['title'] );
  81.         $instance['uploader_url'] = strip_tags( $new_instance['uploader_url'] );
  82.         $instance['profile_url'] = strip_tags( $new_instance['profile_url'] );
  83.         return $instance;      
  84.        
  85.     }
  86.     function form( $instance ){
  87.         $defaults = array( 'title' => __('Login Form', 'mars'));
  88.         $instance = wp_parse_args( (array) $instance, $defaults );
  89.         $pages = get_pages(array('showposts'=>-1));
  90.         ?>
  91.         <p>
  92.             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'mars'); ?></label>
  93.             <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" style="width:100%;" />
  94.         </p>
  95.         <p>
  96.             <label for="<?php echo $this->get_field_id( 'uploader_url' ); ?>"><?php _e('Uploader URL:', 'mars'); ?></label>
  97.             <?php
  98.                 if( $pages ){
  99.                     print '<select id="'.$this->get_field_id( 'uploader_url' ).'" name="'.$this->get_field_name( 'uploader_url' ).'" class="regular-text mars-dropdown">';
  100.                     print '<option value="-1">'.__('Choose One ...','mars').'</option>';
  101.                     foreach ( $pages as $page ){
  102.                         print '<option '.selected($page->ID, $instance['uploader_url']).' value="'.$page->ID.'">'.$page->post_title.'</option>';
  103.                     }
  104.                     print '</select>';
  105.                 }
  106.                    
  107.             ?>
  108.         </p>
  109.         <p>
  110.             <label for="<?php echo $this->get_field_id( 'profile_url' ); ?>"><?php _e('Profile URL:', 'mars'); ?></label>
  111.             <?php
  112.                 if( $pages ){
  113.                     print '<select id="'.$this->get_field_id( 'profile_url' ).'" name="'.$this->get_field_name( 'profile_url' ).'" class="regular-text mars-dropdown">';
  114.                     print '<option value="-1">'.__('Choose One ...','mars').'</option>';
  115.                     foreach ( $pages as $page ){
  116.                         print '<option '.selected($page->ID, $instance['profile_url']).' value="'.$page->ID.'">'.$page->post_title.'</option>';
  117.                     }
  118.                     print '</select>';
  119.                 }
  120.                    
  121.             ?>
  122.         </p>
  123.     <?php      
  124.     }  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement