| 1 |
<?php |
| 2 |
|
| 3 |
add_action('widgets_init', 'uwp_init_login_widget'); |
| 4 |
|
| 5 |
function uwp_init_login_widget() { |
| 6 |
|
| 7 |
register_widget("UWP_Login_Widget"); |
| 8 |
|
| 9 |
} |
| 10 |
|
| 11 |
class UWP_Login_Widget extends WP_Super_Duper { |
| 12 |
|
| 13 |
public function __construct() { |
| 14 |
|
| 15 |
$options = array( |
| 16 |
'textdomain' => 'userswp', |
| 17 |
'block-icon' => 'admin-site', |
| 18 |
'block-category'=> 'widgets', |
| 19 |
'block-keywords'=> "['userswp','login']", |
| 20 |
'class_name' => __CLASS__, |
| 21 |
'base_id' => 'uwp_login', |
| 22 |
'name' => __('UWP > Login','userswp'), |
| 23 |
'widget_ops' => array( |
| 24 |
'classname' => 'uwp-login-class', |
| 25 |
'description' => esc_html__('Displays login form or current logged in user.','userswp'), |
| 26 |
), |
| 27 |
'arguments' => array( |
| 28 |
'title' => array( |
| 29 |
'title' => __( 'Login widget title', 'userswp' ), |
| 30 |
'desc' => __( 'Enter login widget title', 'userswp' ), |
| 31 |
'type' => 'text', |
| 32 |
'desc_tip' => true, |
| 33 |
'default' => '', |
| 34 |
'advanced' => false |
| 35 |
), |
| 36 |
) |
| 37 |
|
| 38 |
); |
| 39 |
|
| 40 |
parent::__construct( $options ); |
| 41 |
} |
| 42 |
|
| 43 |
public function output( $args = array(), $widget_args = array(), $content = '' ) { |
| 44 |
|
| 45 |
ob_start(); |
| 46 |
|
| 47 |
echo '<div class="uwp_widgets uwp_widget_login">'; |
| 48 |
|
| 49 |
if(is_user_logged_in()) { |
| 50 |
|
| 51 |
global $current_user; |
| 52 |
|
| 53 |
$template = new UsersWP_Templates(); |
| 54 |
|
| 55 |
$logout_url = $template->uwp_logout_url(); |
| 56 |
|
| 57 |
echo '<div class="uwp-login-widget user-loggedin">'; |
| 58 |
|
| 59 |
echo '<p>'.__( 'Logged in as ', 'userswp' ); |
| 60 |
|
| 61 |
echo '<a href="'. apply_filters('uwp_profile_link', get_author_posts_url($current_user->ID), $current_user->ID).'">' . get_avatar( $current_user->ID, 35 ). '<strong>'. apply_filters('uwp_profile_display_name', $current_user->display_name).'</strong></a>'; |
| 62 |
|
| 63 |
echo '<span>'; |
| 64 |
|
| 65 |
printf(__( '<a href="%1$s">Log out</a>', 'userswp'), esc_url( $logout_url )); |
| 66 |
|
| 67 |
echo '</span>'; |
| 68 |
|
| 69 |
echo '</p>'; |
| 70 |
|
| 71 |
echo '</div>'; |
| 72 |
|
| 73 |
} else { |
| 74 |
|
| 75 |
$temp_obj = new UsersWP_Templates(); |
| 76 |
$template = $temp_obj->uwp_locate_template('login'); |
| 77 |
|
| 78 |
echo '<div class="uwp_page">'; |
| 79 |
|
| 80 |
if ($template) { |
| 81 |
include($template); |
| 82 |
} |
| 83 |
|
| 84 |
echo '</div>'; |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
echo '</div>'; |
| 89 |
|
| 90 |
$output = ob_get_contents(); |
| 91 |
|
| 92 |
ob_end_clean(); |
| 93 |
|
| 94 |
return trim($output); |
| 95 |
|
| 96 |
} |
| 97 |
} |