Make WordPress Core

Ticket #14132: Login widget using wp_login_form 20101125.patch

File Login widget using wp_login_form 20101125.patch, 3.2 KB (added by azizur, 14 years ago)

Updated patch with localization support

  • wp-content/themes/twentyten/style.css

     
    304304        top: .5ex;
    305305}
    306306input[type="text"],
     307input[type="password"],
    307308textarea {
    308309        background: #f9f9f9;
    309310        border: 1px solid #ccc;
  • wp-includes/default-widgets.php

     
    320320        }
    321321}
    322322
     323
    323324/**
     325 * User Authentication widget class
     326 *
     327 * Displays login form for visitors and once logged-in show profile, password change and logout links.
     328 *
     329 * @todo form for setting selection of $args for wp_login_form()
     330 * @todo allow user to register or request lostpassword.
     331 *
     332 * @version 0.0.1
     333 * @since 3.1.0
     334 */
     335class WP_Widget_Auth extends WP_Widget {
     336
     337        function WP_Widget_Auth() {
     338                $widget_ops = array('classname' => 'widget_auth', 'description' => __( "A login form for your site.") );
     339                $this->WP_Widget('authentication', __('Authentication'), $widget_ops);
     340        }
     341
     342        function widget( $args, $instance ) {
     343                extract($args);
     344                $title = apply_filters('widget_title', empty($instance['title']) ? __('Login') : $instance['title'], $instance, $this->id_base);
     345
     346                echo $before_widget;
     347                if ( $title )
     348                    if(!is_user_logged_in()) {
     349                        echo $before_title . $title . $after_title;
     350                        wp_login_form();
     351                    } else {
     352                        global $current_user;
     353                        echo $before_title . sprintf(_('Welcome, %s'), $current_user->display_name ) . $after_title;
     354                    }
     355                    ?>
     356                <ul>
     357                    <?php if(is_user_logged_in()) : ?>
     358                    <li><a href="<?php echo admin_url( 'profile.php', 'admin' ); ?>"><?php _e('View your profile'); ?></a></li>
     359                    <li><a href="<?php echo admin_url( 'profile.php#password', 'admin' ); ?>"><?php _e('Change Password'); ?></a></li>
     360                    <li><?php wp_loginout(); ?></li>
     361                    <?php else : wp_register();
     362                    endif; ?>
     363                </ul>
     364<?php
     365                echo $after_widget;
     366        }
     367
     368        function update( $new_instance, $old_instance ) {
     369                $instance = $old_instance;
     370                $instance['title'] = strip_tags($new_instance['title']);
     371
     372                return $instance;
     373        }
     374
     375        function form( $instance ) {
     376                $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
     377                $title = strip_tags($instance['title']);
     378?>
     379                <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <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); ?>" /></p>
     380<?php
     381        }
     382}
     383
     384
     385/**
    324386 * Calendar widget class
    325387 *
    326388 * @since 2.8.0
     
    11391201
    11401202        register_widget('WP_Widget_Links');
    11411203
     1204        register_widget('WP_Widget_Auth');
     1205       
    11421206        register_widget('WP_Widget_Meta');
    11431207
    11441208        register_widget('WP_Widget_Search');