| 1 |
<?php |
| 2 |
add_action('widgets_init', 'uwp_init_login_widget'); |
| 3 |
function uwp_init_login_widget() { |
| 4 |
register_widget("UWP_Login_Widget"); |
| 5 |
} |
| 6 |
class UWP_Login_Widget extends WP_Widget |
| 7 |
{ |
| 8 |
|
| 9 |
/** |
| 10 |
* Class constructor. |
| 11 |
*/ |
| 12 |
function __construct() |
| 13 |
{ |
| 14 |
$widget_ops = array( |
| 15 |
'description' => __('Displays Login Form', 'userswp'), |
| 16 |
'classname' => 'uwp_progress_users', |
| 17 |
); |
| 18 |
parent::__construct(false, $name = _x('UWP > Login', 'widget name', 'userswp'), $widget_ops); |
| 19 |
|
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Display the widget. |
| 24 |
* |
| 25 |
* @param array $args Widget arguments. |
| 26 |
* @param array $instance The widget settings, as saved by the user. |
| 27 |
*/ |
| 28 |
function widget($args, $instance) |
| 29 |
{ |
| 30 |
extract($args, EXTR_SKIP); |
| 31 |
$title = empty($instance['title']) ? __('Login', 'userswp') : apply_filters('uwp_login_widget_title', $instance['title']); |
| 32 |
|
| 33 |
echo '<div class="uwp_widgets">'; |
| 34 |
echo $before_widget; |
| 35 |
if ($title) { |
| 36 |
echo $before_title . $title . $after_title; |
| 37 |
} |
| 38 |
if(is_user_logged_in()){ |
| 39 |
global $current_user; |
| 40 |
$template = new UsersWP_Templates(); |
| 41 |
$logout_url = $template->uwp_logout_url(); |
| 42 |
echo '<div class="uwp-login-widget user-loggedin">'; |
| 43 |
echo '<p>'.__( 'Logged in as ', 'userswp' ); |
| 44 |
echo '<a href="'. apply_filters('uwp_profile_link', get_author_posts_url($current_user->ID), $current_user->ID).'">' . get_avatar( $current_user->ID, 35, uwp_get_default_avatar_uri() ). '<strong>'. apply_filters('uwp_profile_display_name', $current_user->display_name).'</strong></a>'; |
| 45 |
echo '<span>'; |
| 46 |
printf(__( '<a href="%1$s">Log out</a>', 'userswp'), esc_url( $logout_url )); |
| 47 |
echo '</span></p>'; |
| 48 |
echo '</div>'; |
| 49 |
} else { |
| 50 |
echo do_shortcode('[uwp_login]'); |
| 51 |
} |
| 52 |
echo $after_widget; |
| 53 |
echo '</div>'; |
| 54 |
} |
| 55 |
|
| 56 |
function update($new_instance, $old_instance) |
| 57 |
{ |
| 58 |
//save the widget |
| 59 |
$instance = $old_instance; |
| 60 |
$instance['title'] = strip_tags($new_instance['title']); |
| 61 |
return $instance; |
| 62 |
} |
| 63 |
|
| 64 |
function form($instance) |
| 65 |
{ |
| 66 |
//widgetform in backend |
| 67 |
$instance = wp_parse_args((array)$instance, array( |
| 68 |
'title' => __('Login', 'userswp'), |
| 69 |
)); |
| 70 |
$title = strip_tags($instance['title']); |
| 71 |
?> |
| 72 |
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php echo __("Widget Title:", 'userswp'); ?> <input class="widefat" |
| 73 |
id="<?php echo $this->get_field_id('title'); ?>" |
| 74 |
name="<?php echo $this->get_field_name('title'); ?>" |
| 75 |
type="text" |
| 76 |
value="<?php echo esc_attr($title); ?>"/></label> |
| 77 |
</p> |
| 78 |
<?php |
| 79 |
} |
| 80 |
|
| 81 |
} |