Plugin Directory

Changeset 597170


Ignore:
Timestamp:
09/10/2012 09:21:25 PM (14 years ago)
Author:
graphical_force
Message:

Added a title field in the widget.
Added some formating and cleaned up the code a bit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • get-user-info/trunk/getUserInfo.php

    r596814 r597170  
    22/*
    33Plugin Name: Get user info
     4Plugin URI: http://wordpress.org/extend/plugins/get-user-info/
    45Description: A way to get the avatar, name, and description using a shortcode : use [authorinfo user="User Name"] and/or use a widget in the sidebar. Just enter the username of the user you want to display.
    5 Version: 1.0
     6Version: 1.0.1
    67Author: Jeff Freeman
    78Author URI: http://graphicalforce.com
     
    1920        parent::__construct(
    2021            'featured_widget', // Base ID
    21             'Featured User', // Name
     22            'Get User Info', // Name
    2223            array( 'description' => __( 'Display the name, description, and avatar of any user. Just enter the username.', 'text_domain' ), ) // Args
    2324        );
     
    3435    public function widget( $args, $instance ) {
    3536        extract( $args );
    36         $title = "Featured User of the Day";
    37         $user = apply_filters( 'widget_title', $instance['title'] );
     37        $title = apply_filters( 'widget_title', $instance['title'] );
     38        $user = apply_filters( 'widget_title', $instance['userName'] );
    3839
    3940        $user = get_userdatabylogin($user);
     
    4546       
    4647        echo $before_widget;
    47         if ( ! empty( $title ) )
    48             echo $before_title . $title . $after_title;
    49             echo "{$user_first} {$user_last}";
    50             echo "<br/>";
     48        if ( ! empty( $userName ) )
     49            echo $before_title . $userName . $after_title;
     50            echo "<h3 class=\"widget-title\">{$title}</h3>";
     51            echo "<h4>{$user_first} {$user_last}</h4>";
    5152            echo "{$user_avatar}";
    52             echo "<br/>";
    53             echo "{$user_description}";
     53            echo "<p>{$user_description}</p>";
    5454        echo $after_widget;
    5555    }
     
    6767    public function update( $new_instance, $old_instance ) {
    6868        $instance = array();
    69         $instance['title'] = strip_tags( $new_instance['title'] );
     69        $instance['userName'] = strip_tags( $new_instance['userName'] );
     70        $instance['title'] = strip_tags($new_instance['title']);
    7071
    7172        return $instance;
     
    8081     */
    8182    public function form( $instance ) {
    82         if ( isset( $instance[ 'title' ] ) ) {
    83             $title = $instance[ 'title' ];
     83        if ( isset( $instance[ 'userName' ] ) ) {
     84            $userName = $instance[ 'userName' ];
     85            $title = $instance['title'];
    8486        }
    8587        else {
    86             $title = __( 'New title', 'text_domain' );
     88            $userName = __( 'New Name', 'text_domain' );
    8789        }
    8890        ?>
    8991        <p>
    90         <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'User Name' ); ?></label>
     92        <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
    9193        <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
     94        </p>
     95        <p>
     96        <label for="<?php echo $this->get_field_id( 'userName' ); ?>"><?php _e( 'User Name' ); ?></label>
     97        <input class="widefat" id="<?php echo $this->get_field_id( 'userName' ); ?>" name="<?php echo $this->get_field_name( 'userName' ); ?>" type="text" value="<?php echo esc_attr( $userName ); ?>" />
    9298        </p>
    9399        <?php
     
    96102} // class Featured_User
    97103
    98 // register Foo_Widget widget
     104// register Get User Info widget
    99105add_action( 'widgets_init', create_function( '', 'register_widget( "featured_widget" );' ) );
    100106
Note: See TracChangeset for help on using the changeset viewer.