| 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 | */ |
| 335 | class 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 | /** |