| @@ -11,20 +11,27 @@ | ||
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | 13 | class UWP_Login_Widget extends WP_Super_Duper { |
| 14 | 14 | |
| 15 | + /** | |
| 16 | + * Register the login widget with WordPress. | |
| 17 | + * | |
| 18 | + */ | |
| 15 | 19 | public function __construct() { |
| 16 | 20 | |
| 17 | 21 | $options = array( |
| 18 | 22 | 'textdomain' => 'userswp', |
| 19 | - 'block-icon' => 'admin-site', | |
| 23 | + 'block-icon' => 'fas fa-user', | |
| 20 | 24 | 'block-category'=> 'widgets', |
| 21 | 25 | 'block-keywords'=> "['userswp','login']", |
| 26 | + 'block-supports'=> array( | |
| 27 | + 'customClassName' => false | |
| 28 | + ), | |
| 22 | 29 | 'class_name' => __CLASS__, |
| 23 | 30 | 'base_id' => 'uwp_login', |
| 24 | 31 | 'name' => __('UWP > Login','userswp'), |
| 25 | 32 | 'widget_ops' => array( |
| 26 | - 'classname' => 'uwp-login-class', | |
| 33 | + 'classname' => 'uwp-login-class bsui', | |
| 27 | 34 | 'description' => esc_html__('Displays login form or current logged in user.','userswp'), |
| 28 | 35 | ), |
| 29 | 36 | 'arguments' => array( |
| 30 | 37 | 'title' => array( |
| @@ -32,13 +39,12 @@ | ||
| 32 | 39 | 'desc' => __( 'Enter widget title', 'userswp' ), |
| 33 | 40 | 'type' => 'text', |
| 34 | 41 | 'desc_tip' => true, |
| 35 | 42 | 'default' => '', |
| 36 | - 'advanced' => false | |
| 37 | 43 | ), |
| 38 | - 'login_text' => array( | |
| 39 | - 'title' => __( 'Login text', 'userswp' ), | |
| 40 | - 'desc' => __( 'Enter the login text', 'userswp' ), | |
| 44 | + 'form_title' => array( | |
| 45 | + 'title' => __( 'Form title', 'userswp' ), | |
| 46 | + 'desc' => __( 'Enter the form title (or `0` for no title)', 'userswp' ), | |
| 41 | 47 | 'type' => 'text', |
| 42 | 48 | 'desc_tip' => true, |
| 43 | 49 | 'default' => '', |
| 44 | 50 | 'placeholder' => __('Login','userswp'), |
| @@ -43,20 +49,11 @@ | ||
| 43 | 49 | 'default' => '', |
| 44 | 50 | 'placeholder' => __('Login','userswp'), |
| 45 | 51 | 'advanced' => true |
| 46 | 52 | ), |
| 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 | 53 | 'logged_in_show' => array( |
| 57 | 54 | 'title' => __('Logged in show', 'userswp'), |
| 58 | - 'desc' => __('Wha to show when logged in.', 'userswp'), | |
| 55 | + 'desc' => __('What to show when logged in.', 'userswp'), | |
| 59 | 56 | 'type' => 'select', |
| 60 | 57 | 'options' => array( |
| 61 | 58 | "" => __('User Dashboard (default)', 'userswp'), |
| 62 | 59 | "simple" => __('Simple username and logout link', 'userswp'), |
| @@ -63,18 +60,45 @@ | ||
| 63 | 60 | "empty" => __('Nothing', 'userswp'), |
| 64 | 61 | ), |
| 65 | 62 | 'default' => '', |
| 66 | 63 | 'desc_tip' => true, |
| 67 | - 'advanced' => true | |
| 68 | - ) | |
| 69 | - | |
| 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 | + ), | |
| 70 | 96 | ) |
| 71 | 97 | |
| 72 | 98 | ); |
| 73 | 99 | |
| 74 | - // add intigrations by default and add option to remove | |
| 75 | - | |
| 76 | - // GD | |
| 100 | + // GD options | |
| 77 | 101 | if(class_exists( 'GeoDirectory' )){ |
| 78 | 102 | $options['arguments']['disable_gd'] = array( |
| 79 | 103 | 'title' => __("Disable GeoDirectory links from the user dashboard.", 'userswp'), |
| 80 | 104 | 'type' => 'checkbox', |
| @@ -80,14 +104,14 @@ | ||
| 80 | 104 | 'type' => 'checkbox', |
| 81 | 105 | 'desc_tip' => true, |
| 82 | 106 | 'value' => '1', |
| 83 | 107 | 'default' => '', |
| 84 | - 'advanced' => true, | |
| 108 | + 'group' => __("Addons","userswp"), | |
| 85 | 109 | 'element_require' => '[%logged_in_show%]==""', |
| 86 | 110 | ); |
| 87 | 111 | } |
| 88 | 112 | |
| 89 | - // WPI | |
| 113 | + // WPI options | |
| 90 | 114 | if(class_exists( 'WPInv_Plugin' )){ |
| 91 | 115 | $options['arguments']['disable_wpi'] = array( |
| 92 | 116 | 'title' => __("Disable WP Invoicing links from the user dashboard.", 'userswp'), |
| 93 | 117 | 'type' => 'checkbox', |
| @@ -93,112 +117,111 @@ | ||
| 93 | 117 | 'type' => 'checkbox', |
| 94 | 118 | 'desc_tip' => true, |
| 95 | 119 | 'value' => '1', |
| 96 | 120 | 'default' => '', |
| 97 | - 'advanced' => true, | |
| 121 | + 'group' => __("Addons","userswp"), | |
| 98 | 122 | 'element_require' => '[%logged_in_show%]==""', |
| 99 | 123 | ); |
| 100 | 124 | } |
| 101 | 125 | |
| 102 | - | |
| 103 | - | |
| 104 | 126 | parent::__construct( $options ); |
| 105 | 127 | } |
| 106 | 128 | |
| 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 | + */ | |
| 107 | 138 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
| 108 | 139 | |
| 109 | 140 | $defaults = array( |
| 110 | - 'login_title' => __('Login','userswp'), | |
| 111 | - 'form_padding' => '', | |
| 141 | + 'form_title' => __('Login','userswp'), | |
| 112 | 142 | 'logged_in_show' => '', |
| 143 | + 'css_class' => 'border-0', | |
| 144 | + 'redirect_to' => '', | |
| 113 | 145 | ); |
| 114 | 146 | |
| 147 | + if ( $this->is_preview() ) { | |
| 148 | + return; | |
| 149 | + } | |
| 150 | + | |
| 115 | 151 | /** |
| 116 | 152 | * Parse incoming $args into an array and merge it with $defaults |
| 117 | 153 | */ |
| 118 | 154 | $args = wp_parse_args( $args, $defaults ); |
| 119 | 155 | |
| 120 | - //print_r($args); | |
| 121 | - | |
| 122 | 156 | // if logged in and set to show nothing then bail. |
| 123 | 157 | if(is_user_logged_in() && $args['logged_in_show']=='empty'){ |
| 124 | 158 | return ''; |
| 125 | 159 | } |
| 126 | 160 | |
| 161 | + $design_style = !empty($args['design_style']) ? esc_attr($args['design_style']) : uwp_get_option("design_style",'bootstrap'); | |
| 162 | + | |
| 127 | 163 | ob_start(); |
| 128 | - | |
| 129 | - echo '<div class="uwp_widgets uwp_widget_login">'; | |
| 130 | - | |
| 164 | + | |
| 131 | 165 | if(is_user_logged_in()) { |
| 132 | 166 | |
| 133 | 167 | if($args['logged_in_show']=='simple'){ |
| 134 | - self::simple_output($args); | |
| 168 | + $template = $design_style ? $design_style."/dashboard-simple.php" : "dashboard-simple.php"; | |
| 135 | 169 | }else{ |
| 136 | - self::advanced_output($args); | |
| 137 | - } | |
| 138 | 170 | |
| 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'); | |
| 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 | + ); | |
| 145 | 182 | |
| 146 | - echo '<div class="uwp_page">'; | |
| 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 | + } | |
| 147 | 199 | |
| 148 | - if ($template) { | |
| 149 | - include($template); | |
| 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"; | |
| 150 | 211 | } |
| 151 | 212 | |
| 152 | - echo '</div>'; | |
| 153 | - | |
| 213 | + } else { | |
| 214 | + $template = $design_style ? $design_style."/login.php" : "login.php"; | |
| 154 | 215 | } |
| 155 | 216 | |
| 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 | 217 | echo '<div class="uwp_page">'; |
| 173 | 218 | |
| 174 | - if ($template) { | |
| 175 | - include($template); | |
| 176 | - } | |
| 219 | + uwp_get_template($template, $args); | |
| 177 | 220 | |
| 178 | 221 | echo '</div>'; |
| 179 | - } | |
| 180 | 222 | |
| 181 | - public static function simple_output($args){ | |
| 182 | - global $current_user; | |
| 223 | + return ob_get_clean(); | |
| 183 | 224 | |
| 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 | 225 | } |
| 226 | + | |
| 204 | 227 | } |