| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* UsersWP forgot password widget. |
| 9 |
* |
| 10 |
* @since 1.0.22 |
| 11 |
*/ |
| 12 |
|
| 13 |
class UWP_Login_Widget extends WP_Super_Duper { |
| 14 |
|
| 15 |
public function __construct() { |
| 16 |
|
| 17 |
$options = array( |
| 18 |
'textdomain' => 'userswp', |
| 19 |
'block-icon' => 'admin-site', |
| 20 |
'block-category'=> 'widgets', |
| 21 |
'block-keywords'=> "['userswp','login']", |
| 22 |
'class_name' => __CLASS__, |
| 23 |
'base_id' => 'uwp_login', |
| 24 |
'name' => __('UWP > Login','userswp'), |
| 25 |
'widget_ops' => array( |
| 26 |
'classname' => 'uwp-login-class', |
| 27 |
'description' => esc_html__('Displays login form or current logged in user.','userswp'), |
| 28 |
), |
| 29 |
'arguments' => array( |
| 30 |
'title' => array( |
| 31 |
'title' => __( 'Widget title', 'userswp' ), |
| 32 |
'desc' => __( 'Enter widget title', 'userswp' ), |
| 33 |
'type' => 'text', |
| 34 |
'desc_tip' => true, |
| 35 |
'default' => '', |
| 36 |
'advanced' => false |
| 37 |
), |
| 38 |
'login_text' => array( |
| 39 |
'title' => __( 'Login text', 'userswp' ), |
| 40 |
'desc' => __( 'Enter the login text', 'userswp' ), |
| 41 |
'type' => 'text', |
| 42 |
'desc_tip' => true, |
| 43 |
'default' => '', |
| 44 |
'placeholder' => __('Login','userswp'), |
| 45 |
'advanced' => true |
| 46 |
), |
| 47 |
'form_padding' => array( |
| 48 |
'title' => __( 'Form padding', 'userswp' ), |
| 49 |
'desc' => __( 'Enter the px value for the form padding, default is 40, 10 looks better in sidbars.', 'userswp' ), |
| 50 |
'type' => 'number', |
| 51 |
'desc_tip' => true, |
| 52 |
'default' => '', |
| 53 |
'placeholder' => __('default 40, 10 is better in sidebars','userswp'), |
| 54 |
'advanced' => true |
| 55 |
), |
| 56 |
'logged_in_show' => array( |
| 57 |
'title' => __('Logged in show', 'userswp'), |
| 58 |
'desc' => __('Wha to show when logged in.', 'userswp'), |
| 59 |
'type' => 'select', |
| 60 |
'options' => array( |
| 61 |
"" => __('User Dashboard (default)', 'userswp'), |
| 62 |
"simple" => __('Simple username and logout link', 'userswp'), |
| 63 |
"empty" => __('Nothing', 'userswp'), |
| 64 |
), |
| 65 |
'default' => '', |
| 66 |
'desc_tip' => true, |
| 67 |
'advanced' => true |
| 68 |
) |
| 69 |
|
| 70 |
) |
| 71 |
|
| 72 |
); |
| 73 |
|
| 74 |
// add intigrations by default and add option to remove |
| 75 |
|
| 76 |
// GD |
| 77 |
if(class_exists( 'GeoDirectory' )){ |
| 78 |
$options['arguments']['disable_gd'] = array( |
| 79 |
'title' => __("Disable GeoDirectory links from the user dashboard.", 'userswp'), |
| 80 |
'type' => 'checkbox', |
| 81 |
'desc_tip' => true, |
| 82 |
'value' => '1', |
| 83 |
'default' => '', |
| 84 |
'advanced' => true, |
| 85 |
'element_require' => '[%logged_in_show%]==""', |
| 86 |
); |
| 87 |
} |
| 88 |
|
| 89 |
// WPI |
| 90 |
if(class_exists( 'WPInv_Plugin' )){ |
| 91 |
$options['arguments']['disable_wpi'] = array( |
| 92 |
'title' => __("Disable WP Invoicing links from the user dashboard.", 'userswp'), |
| 93 |
'type' => 'checkbox', |
| 94 |
'desc_tip' => true, |
| 95 |
'value' => '1', |
| 96 |
'default' => '', |
| 97 |
'advanced' => true, |
| 98 |
'element_require' => '[%logged_in_show%]==""', |
| 99 |
); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
parent::__construct( $options ); |
| 105 |
} |
| 106 |
|
| 107 |
public function output( $args = array(), $widget_args = array(), $content = '' ) { |
| 108 |
|
| 109 |
$defaults = array( |
| 110 |
'login_title' => __('Login','userswp'), |
| 111 |
'form_padding' => '', |
| 112 |
'logged_in_show' => '', |
| 113 |
); |
| 114 |
|
| 115 |
/** |
| 116 |
* Parse incoming $args into an array and merge it with $defaults |
| 117 |
*/ |
| 118 |
$args = wp_parse_args( $args, $defaults ); |
| 119 |
|
| 120 |
//print_r($args); |
| 121 |
|
| 122 |
// if logged in and set to show nothing then bail. |
| 123 |
if(is_user_logged_in() && $args['logged_in_show']=='empty'){ |
| 124 |
return ''; |
| 125 |
} |
| 126 |
|
| 127 |
ob_start(); |
| 128 |
|
| 129 |
echo '<div class="uwp_widgets uwp_widget_login">'; |
| 130 |
|
| 131 |
if(is_user_logged_in()) { |
| 132 |
|
| 133 |
if($args['logged_in_show']=='simple'){ |
| 134 |
self::simple_output($args); |
| 135 |
}else{ |
| 136 |
self::advanced_output($args); |
| 137 |
} |
| 138 |
|
| 139 |
} else { |
| 140 |
|
| 141 |
global $uwp_login_widget_args; |
| 142 |
$uwp_login_widget_args = $args; |
| 143 |
$temp_obj = new UsersWP_Templates(); |
| 144 |
$template = $temp_obj->uwp_locate_template('login'); |
| 145 |
|
| 146 |
echo '<div class="uwp_page">'; |
| 147 |
|
| 148 |
if ($template) { |
| 149 |
include($template); |
| 150 |
} |
| 151 |
|
| 152 |
echo '</div>'; |
| 153 |
|
| 154 |
} |
| 155 |
|
| 156 |
echo '</div>'; |
| 157 |
|
| 158 |
$output = ob_get_contents(); |
| 159 |
|
| 160 |
ob_end_clean(); |
| 161 |
|
| 162 |
return trim($output); |
| 163 |
|
| 164 |
} |
| 165 |
|
| 166 |
public static function advanced_output($args){ |
| 167 |
global $uwp_login_widget_args; |
| 168 |
$uwp_login_widget_args = $args; |
| 169 |
$temp_obj = new UsersWP_Templates(); |
| 170 |
$template = $temp_obj->uwp_locate_template('dashboard'); |
| 171 |
|
| 172 |
echo '<div class="uwp_page">'; |
| 173 |
|
| 174 |
if ($template) { |
| 175 |
include($template); |
| 176 |
} |
| 177 |
|
| 178 |
echo '</div>'; |
| 179 |
} |
| 180 |
|
| 181 |
public static function simple_output($args){ |
| 182 |
global $current_user; |
| 183 |
|
| 184 |
$template = new UsersWP_Templates(); |
| 185 |
|
| 186 |
$logout_url = $template->uwp_logout_url(); |
| 187 |
|
| 188 |
echo '<div class="uwp-login-widget user-loggedin">'; |
| 189 |
|
| 190 |
echo '<p>'.__( 'Logged in as ', 'userswp' ); |
| 191 |
|
| 192 |
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>'; |
| 193 |
|
| 194 |
echo '<span>'; |
| 195 |
|
| 196 |
printf(__( '<a href="%1$s">Log out</a>', 'userswp'), esc_url( $logout_url )); |
| 197 |
|
| 198 |
echo '</span>'; |
| 199 |
|
| 200 |
echo '</p>'; |
| 201 |
|
| 202 |
echo '</div>'; |
| 203 |
} |
| 204 |
} |