| @@ -1,71 +1,227 @@ | ||
| 1 | 1 | <?php |
| 2 | -add_action('widgets_init', 'uwp_init_login_widget'); | |
| 3 | -function uwp_init_login_widget() { | |
| 4 | - register_widget("UWP_Login_Widget"); | |
| 2 | + | |
| 3 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 4 | + exit; | |
| 5 | 5 | } |
| 6 | -class UWP_Login_Widget extends WP_Widget | |
| 7 | -{ | |
| 8 | 6 | |
| 9 | - /** | |
| 10 | - * Class constructor. | |
| 11 | - */ | |
| 12 | - function __construct() | |
| 13 | - { | |
| 14 | - $widget_ops = array( | |
| 15 | - 'description' => __('Displays Login Form', 'userswp'), | |
| 16 | - 'classname' => 'uwp_progress_users', | |
| 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 | + /** | |
| 16 | + * Register the login widget with WordPress. | |
| 17 | + * | |
| 18 | + */ | |
| 19 | + public function __construct() { | |
| 20 | + | |
| 21 | + $options = array( | |
| 22 | + 'textdomain' => 'userswp', | |
| 23 | + 'block-icon' => 'fas fa-user', | |
| 24 | + 'block-category'=> 'widgets', | |
| 25 | + 'block-keywords'=> "['userswp','login']", | |
| 26 | + 'block-supports'=> array( | |
| 27 | + 'customClassName' => false | |
| 28 | + ), | |
| 29 | + 'class_name' => __CLASS__, | |
| 30 | + 'base_id' => 'uwp_login', | |
| 31 | + 'name' => __('UWP > Login','userswp'), | |
| 32 | + 'widget_ops' => array( | |
| 33 | + 'classname' => 'uwp-login-class bsui', | |
| 34 | + 'description' => esc_html__('Displays login form or current logged in user.','userswp'), | |
| 35 | + ), | |
| 36 | + 'arguments' => array( | |
| 37 | + 'title' => array( | |
| 38 | + 'title' => __( 'Widget title', 'userswp' ), | |
| 39 | + 'desc' => __( 'Enter widget title', 'userswp' ), | |
| 40 | + 'type' => 'text', | |
| 41 | + 'desc_tip' => true, | |
| 42 | + 'default' => '', | |
| 43 | + ), | |
| 44 | + 'form_title' => array( | |
| 45 | + 'title' => __( 'Form title', 'userswp' ), | |
| 46 | + 'desc' => __( 'Enter the form title (or `0` for no title)', 'userswp' ), | |
| 47 | + 'type' => 'text', | |
| 48 | + 'desc_tip' => true, | |
| 49 | + 'default' => '', | |
| 50 | + 'placeholder' => __('Login','userswp'), | |
| 51 | + 'advanced' => true | |
| 52 | + ), | |
| 53 | + 'logged_in_show' => array( | |
| 54 | + 'title' => __('Logged in show', 'userswp'), | |
| 55 | + 'desc' => __('What to show when logged in.', 'userswp'), | |
| 56 | + 'type' => 'select', | |
| 57 | + 'options' => array( | |
| 58 | + "" => __('User Dashboard (default)', 'userswp'), | |
| 59 | + "simple" => __('Simple username and logout link', 'userswp'), | |
| 60 | + "empty" => __('Nothing', 'userswp'), | |
| 61 | + ), | |
| 62 | + 'default' => '', | |
| 63 | + 'desc_tip' => true, | |
| 64 | + 'advanced' => true | |
| 65 | + ), | |
| 66 | + 'redirect_to' => array( | |
| 67 | + 'type' => 'text', | |
| 68 | + 'title' => __('Redirect to:', 'userswp'), | |
| 69 | + 'desc' => __('Enter the url you want to redirect after login.', 'userswp'), | |
| 70 | + 'placeholder' => '', | |
| 71 | + 'default' => '', | |
| 72 | + 'desc_tip' => true, | |
| 73 | + 'advanced' => true | |
| 74 | + ), | |
| 75 | + 'design_style' => array( | |
| 76 | + 'title' => __('Design Style', 'userswp'), | |
| 77 | + 'desc' => __('The design style to use.', 'userswp'), | |
| 78 | + 'type' => 'select', | |
| 79 | + 'options' => array( | |
| 80 | + "" => __('default', 'userswp'), | |
| 81 | + "bootstrap" => __('Style 1', 'userswp'), | |
| 82 | + ), | |
| 83 | + 'default' => '', | |
| 84 | + 'desc_tip' => true, | |
| 85 | + 'group' => __("Design","userswp") | |
| 86 | + ), | |
| 87 | + 'css_class' => array( | |
| 88 | + 'type' => 'text', | |
| 89 | + 'title' => __('Extra class:', 'userswp'), | |
| 90 | + 'desc' => __('Give the wrapper an extra class so you can style things as you want.', 'userswp'), | |
| 91 | + 'placeholder' => '', | |
| 92 | + 'default' => '', | |
| 93 | + 'desc_tip' => true, | |
| 94 | + 'group' => __("Design","userswp") | |
| 95 | + ), | |
| 96 | + ) | |
| 97 | + | |
| 17 | 98 | ); |
| 18 | - parent::__construct(false, $name = _x('UWP > Login', 'widget name', 'userswp'), $widget_ops); | |
| 19 | 99 | |
| 100 | + // GD options | |
| 101 | + if(class_exists( 'GeoDirectory' )){ | |
| 102 | + $options['arguments']['disable_gd'] = array( | |
| 103 | + 'title' => __("Disable GeoDirectory links from the user dashboard.", 'userswp'), | |
| 104 | + 'type' => 'checkbox', | |
| 105 | + 'desc_tip' => true, | |
| 106 | + 'value' => '1', | |
| 107 | + 'default' => '', | |
| 108 | + 'group' => __("Addons","userswp"), | |
| 109 | + 'element_require' => '[%logged_in_show%]==""', | |
| 110 | + ); | |
| 111 | + } | |
| 112 | + | |
| 113 | + // WPI options | |
| 114 | + if(class_exists( 'WPInv_Plugin' )){ | |
| 115 | + $options['arguments']['disable_wpi'] = array( | |
| 116 | + 'title' => __("Disable WP Invoicing links from the user dashboard.", 'userswp'), | |
| 117 | + 'type' => 'checkbox', | |
| 118 | + 'desc_tip' => true, | |
| 119 | + 'value' => '1', | |
| 120 | + 'default' => '', | |
| 121 | + 'group' => __("Addons","userswp"), | |
| 122 | + 'element_require' => '[%logged_in_show%]==""', | |
| 123 | + ); | |
| 124 | + } | |
| 125 | + | |
| 126 | + parent::__construct( $options ); | |
| 20 | 127 | } |
| 21 | 128 | |
| 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 | - if (is_user_logged_in()) { | |
| 129 | + /** | |
| 130 | + * The Super block output function. | |
| 131 | + * | |
| 132 | + * @param array $args | |
| 133 | + * @param array $widget_args | |
| 134 | + * @param string $content | |
| 135 | + * | |
| 136 | + * @return mixed|string | |
| 137 | + */ | |
| 138 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { | |
| 139 | + | |
| 140 | + $defaults = array( | |
| 141 | + 'form_title' => __('Login','userswp'), | |
| 142 | + 'logged_in_show' => '', | |
| 143 | + 'css_class' => 'border-0', | |
| 144 | + 'redirect_to' => '', | |
| 145 | + ); | |
| 146 | + | |
| 147 | + if ( $this->is_preview() ) { | |
| 31 | 148 | return; |
| 32 | 149 | } |
| 33 | - extract($args, EXTR_SKIP); | |
| 34 | - $title = empty($instance['title']) ? __('Login', 'userswp') : apply_filters('uwp_login_widget_title', $instance['title']); | |
| 35 | 150 | |
| 36 | - echo '<div class="uwp_widgets">'; | |
| 37 | - echo $before_widget; | |
| 38 | - if ($title) { | |
| 39 | - echo $before_title . $title . $after_title; | |
| 151 | + /** | |
| 152 | + * Parse incoming $args into an array and merge it with $defaults | |
| 153 | + */ | |
| 154 | + $args = wp_parse_args( $args, $defaults ); | |
| 155 | + | |
| 156 | + // if logged in and set to show nothing then bail. | |
| 157 | + if(is_user_logged_in() && $args['logged_in_show']=='empty'){ | |
| 158 | + return ''; | |
| 40 | 159 | } |
| 41 | - echo do_shortcode('[uwp_login]'); | |
| 42 | - echo $after_widget; | |
| 160 | + | |
| 161 | + $design_style = !empty($args['design_style']) ? esc_attr($args['design_style']) : uwp_get_option("design_style",'bootstrap'); | |
| 162 | + | |
| 163 | + ob_start(); | |
| 164 | + | |
| 165 | + if(is_user_logged_in()) { | |
| 166 | + | |
| 167 | + if($args['logged_in_show']=='simple'){ | |
| 168 | + $template = $design_style ? $design_style."/dashboard-simple.php" : "dashboard-simple.php"; | |
| 169 | + }else{ | |
| 170 | + | |
| 171 | + $user_id = get_current_user_id(); | |
| 172 | + | |
| 173 | + $dashboard_links = array( | |
| 174 | + 'placeholder' => array( | |
| 175 | + 'url' => '', | |
| 176 | + 'text' => __('Select an action','userswp'), | |
| 177 | + 'disabled' => true, | |
| 178 | + 'selected' => true, | |
| 179 | + 'display_none' => true | |
| 180 | + ) | |
| 181 | + ); | |
| 182 | + | |
| 183 | + $dashboard_links['uwp_profile'][] = array( | |
| 184 | + 'optgroup' => 'open', | |
| 185 | + 'text' => esc_attr( __( 'My Profile', 'userswp' ) ) | |
| 186 | + ); | |
| 187 | + $dashboard_links['uwp_profile'][] = array( | |
| 188 | + 'url' => uwp_build_profile_tab_url( $user_id ), | |
| 189 | + 'text' => esc_attr( __( 'View Profile', 'userswp' ) ) | |
| 190 | + ); | |
| 191 | + $account_page = uwp_get_page_id('account_page', false); | |
| 192 | + $account_link = get_permalink( $account_page ); | |
| 193 | + if($account_link){ | |
| 194 | + $dashboard_links['uwp_profile'][] = array( | |
| 195 | + 'url' => $account_link, | |
| 196 | + 'text' => esc_attr( __( 'Edit Profile', 'userswp' ) ) | |
| 197 | + ); | |
| 198 | + } | |
| 199 | + | |
| 200 | + $dashboard_links['uwp_profile'][] = array( | |
| 201 | + 'optgroup' => 'close', | |
| 202 | + ); | |
| 203 | + | |
| 204 | + $dashboard_links = apply_filters( 'uwp_dashboard_links',$dashboard_links,$args); | |
| 205 | + | |
| 206 | + $args['template_args']= array( | |
| 207 | + 'dashboard_links' => $dashboard_links | |
| 208 | + ); | |
| 209 | + | |
| 210 | + $template = $design_style ? $design_style."/dashboard.php" : "dashboard.php"; | |
| 211 | + } | |
| 212 | + | |
| 213 | + } else { | |
| 214 | + $template = $design_style ? $design_style."/login.php" : "login.php"; | |
| 215 | + } | |
| 216 | + | |
| 217 | + echo '<div class="uwp_page">'; | |
| 218 | + | |
| 219 | + uwp_get_template($template, $args); | |
| 220 | + | |
| 43 | 221 | echo '</div>'; |
| 44 | - } | |
| 45 | 222 | |
| 46 | - function update($new_instance, $old_instance) | |
| 47 | - { | |
| 48 | - //save the widget | |
| 49 | - $instance = $old_instance; | |
| 50 | - $instance['title'] = strip_tags($new_instance['title']); | |
| 51 | - return $instance; | |
| 52 | - } | |
| 223 | + return ob_get_clean(); | |
| 53 | 224 | |
| 54 | - function form($instance) | |
| 55 | - { | |
| 56 | - //widgetform in backend | |
| 57 | - $instance = wp_parse_args((array)$instance, array( | |
| 58 | - 'title' => __('Login', 'userswp'), | |
| 59 | - )); | |
| 60 | - $title = strip_tags($instance['title']); | |
| 61 | - ?> | |
| 62 | - <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php echo __("Widget Title:", 'userswp'); ?> <input class="widefat" | |
| 63 | - id="<?php echo $this->get_field_id('title'); ?>" | |
| 64 | - name="<?php echo $this->get_field_name('title'); ?>" | |
| 65 | - type="text" | |
| 66 | - value="<?php echo esc_attr($title); ?>"/></label> | |
| 67 | - </p> | |
| 68 | - <?php | |
| 69 | 225 | } |
| 70 | - | |
| 226 | + | |
| 71 | 227 | } |