| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly |
| 4 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 5 |
|
| 6 |
require_once "class-pb-widget-base.php"; |
| 7 |
|
| 8 |
/** |
| 9 |
* Elementor widget for our wppb-login shortcode |
| 10 |
*/ |
| 11 |
class PB_Elementor_Login_Widget extends PB_Elementor_Widget { |
| 12 |
|
| 13 |
/** |
| 14 |
* Get widget name. |
| 15 |
* |
| 16 |
*/ |
| 17 |
public function get_name() { |
| 18 |
return 'wppb-login'; |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Get widget title. |
| 23 |
* |
| 24 |
*/ |
| 25 |
public function get_title() { |
| 26 |
return __( 'Login', 'profile-builder' ); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Get widget icon. |
| 31 |
* |
| 32 |
*/ |
| 33 |
public function get_icon() { |
| 34 |
return 'eicon-lock-user'; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Register widget controls. |
| 39 |
* |
| 40 |
*/ |
| 41 |
protected function register_controls() { |
| 42 |
|
| 43 |
$page_titles = $this->get_all_pages(); |
| 44 |
|
| 45 |
$this->start_controls_section( |
| 46 |
'pb_login_links', |
| 47 |
array( |
| 48 |
'label' => __( 'Form Settings', 'profile-builder' ), |
| 49 |
'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 50 |
) |
| 51 |
); |
| 52 |
|
| 53 |
$this->add_control( |
| 54 |
'pb_register_url', |
| 55 |
array( |
| 56 |
'label' => __( 'Registration', 'profile-builder' ), |
| 57 |
'type' => \Elementor\Controls_Manager::SELECT, |
| 58 |
'options' => $page_titles, |
| 59 |
'default' => '', |
| 60 |
) |
| 61 |
); |
| 62 |
|
| 63 |
$this->add_control( |
| 64 |
'pb_lostpassword_url', |
| 65 |
array( |
| 66 |
'label' => __( 'Recover Password', 'profile-builder' ), |
| 67 |
'type' => \Elementor\Controls_Manager::SELECT, |
| 68 |
'options' => $page_titles, |
| 69 |
'default' => '', |
| 70 |
) |
| 71 |
); |
| 72 |
|
| 73 |
if ( $this->is_2fa_active() ) { |
| 74 |
$this->add_control( |
| 75 |
'pb_auth_field', |
| 76 |
array( |
| 77 |
'label' => __('Show Authenticator Code Field', 'profile-builder'), |
| 78 |
'type' => \Elementor\Controls_Manager::SWITCHER, |
| 79 |
'label_on' => __('Yes', 'profile-builder'), |
| 80 |
'label_off' => __('No', 'profile-builder'), |
| 81 |
'return_value' => 'yes', |
| 82 |
'default' => '', |
| 83 |
) |
| 84 |
); |
| 85 |
} |
| 86 |
|
| 87 |
$this->end_controls_section(); |
| 88 |
|
| 89 |
$this->start_controls_section( |
| 90 |
'pb_login_redirects', |
| 91 |
array( |
| 92 |
'label' => __( 'Redirects', 'profile-builder' ), |
| 93 |
'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 94 |
) |
| 95 |
); |
| 96 |
|
| 97 |
$this->add_control( |
| 98 |
'pb_after_login_redirect_url', |
| 99 |
array( |
| 100 |
'label' => __( 'After Login', 'profile-builder' ), |
| 101 |
'type' => \Elementor\Controls_Manager::SELECT, |
| 102 |
'options' => $page_titles, |
| 103 |
'default' => '', |
| 104 |
) |
| 105 |
); |
| 106 |
|
| 107 |
$this->add_control( |
| 108 |
'pb_after_logout_redirect_url', |
| 109 |
array( |
| 110 |
'label' => __( 'After Logout', 'profile-builder' ), |
| 111 |
'type' => \Elementor\Controls_Manager::SELECT, |
| 112 |
'options' => $page_titles, |
| 113 |
'default' => '', |
| 114 |
) |
| 115 |
); |
| 116 |
|
| 117 |
$this->end_controls_section(); |
| 118 |
|
| 119 |
// User Login Style tab |
| 120 |
if( !$this->is_placeholder_labels_active() ) { |
| 121 |
$sections['label'] = [ |
| 122 |
'selector' => '#wppb-login-wrap .login-username label[for=user_login]', |
| 123 |
'section_name' => 'Label', |
| 124 |
]; |
| 125 |
} |
| 126 |
$sections['input'] = [ |
| 127 |
'selector' => '#wppb-login-wrap .login-username input#user_login', |
| 128 |
'section_name' => 'Input', |
| 129 |
]; |
| 130 |
$this->add_styling_control_group( |
| 131 |
'User Login', |
| 132 |
'', |
| 133 |
'pb_user_login_username', |
| 134 |
$sections |
| 135 |
); |
| 136 |
unset($sections); |
| 137 |
|
| 138 |
// Password Style tab |
| 139 |
if( !$this->is_placeholder_labels_active() ) { |
| 140 |
$sections['label'] = [ |
| 141 |
'selector' => '#wppb-login-wrap .login-password label[for=user_pass]', |
| 142 |
'section_name' => 'Label', |
| 143 |
]; |
| 144 |
} |
| 145 |
$sections['input'] = [ |
| 146 |
'selector' => '#wppb-login-wrap .login-password input#user_pass', |
| 147 |
'section_name' => 'Input', |
| 148 |
]; |
| 149 |
$this->add_styling_control_group( |
| 150 |
'Password', |
| 151 |
'', |
| 152 |
'pb_user_login_password', |
| 153 |
$sections |
| 154 |
); |
| 155 |
unset($sections); |
| 156 |
|
| 157 |
if ( $this->is_2fa_active() ) { |
| 158 |
// Authenticator Code Style tab |
| 159 |
if (!$this->is_placeholder_labels_active()) { |
| 160 |
$sections['label'] = [ |
| 161 |
'selector' => '#wppb-login-wrap .login-auth label[for=login_auth]', |
| 162 |
'section_name' => 'Label', |
| 163 |
]; |
| 164 |
} |
| 165 |
$sections['input'] = [ |
| 166 |
'selector' => '#wppb-login-wrap .login-auth input#login_auth', |
| 167 |
'section_name' => 'Input', |
| 168 |
]; |
| 169 |
$this->add_styling_control_group( |
| 170 |
'Authenticator Code', |
| 171 |
'', |
| 172 |
'pb_user_auth_code', |
| 173 |
$sections |
| 174 |
); |
| 175 |
unset($sections); |
| 176 |
} |
| 177 |
|
| 178 |
// reCAPTCHA Style tab |
| 179 |
if( !$this->is_placeholder_labels_active() ) { |
| 180 |
include_once(WPPB_PLUGIN_DIR . '/front-end/default-fields/recaptcha/recaptcha.php'); |
| 181 |
$field = wppb_get_recaptcha_field(); |
| 182 |
if (!empty($field) && isset($field['captcha-pb-forms']) && (strpos($field['captcha-pb-forms'], 'pb_recover_password') !== false)) { |
| 183 |
$this->add_styling_control_group( |
| 184 |
'reCAPTCHA', |
| 185 |
'', |
| 186 |
'pb_user_login_recaptcha', |
| 187 |
[ |
| 188 |
'label' => [ |
| 189 |
'selector' => '#wppb-login-wrap .wppb-form-field.wppb-recaptcha label[for=recaptcha_response_field]', |
| 190 |
'section_name' => 'Label', |
| 191 |
] |
| 192 |
] |
| 193 |
); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
// Remember Checkbox Style tab |
| 198 |
$this->add_styling_control_group( |
| 199 |
'Remember Me Checkbox', |
| 200 |
'', |
| 201 |
'pb_user_login_remember', |
| 202 |
[ |
| 203 |
'label' => [ |
| 204 |
'selector' => '#wppb-login-wrap .login-remember label', |
| 205 |
'section_name' => 'Label', |
| 206 |
], |
| 207 |
'input' => [ |
| 208 |
'selector' => '#wppb-login-wrap .login-remember input', |
| 209 |
'section_name' => 'Input', |
| 210 |
] |
| 211 |
] |
| 212 |
); |
| 213 |
|
| 214 |
// Submit Button Style tab |
| 215 |
$this->add_styling_control_group( |
| 216 |
'Login Button', |
| 217 |
'', |
| 218 |
'pb_user_login_button', |
| 219 |
[ |
| 220 |
'input' => [ |
| 221 |
'selector' => '#wppb-login-wrap .login-submit input#wppb-submit', |
| 222 |
'section_name' => 'Input', |
| 223 |
] |
| 224 |
] |
| 225 |
); |
| 226 |
|
| 227 |
// Social Connect Style tab |
| 228 |
$social_connect_settings = get_option( 'wppb_social_connect_settings' ); |
| 229 |
if ( is_array($social_connect_settings) ) { |
| 230 |
$social_connect_settings = reset($social_connect_settings); |
| 231 |
} |
| 232 |
|
| 233 |
if ( $social_connect_settings && strpos($social_connect_settings['display-on-the-following-forms'], 'pb-login' ) !== false ) { |
| 234 |
$this->add_styling_control_group( |
| 235 |
'Social Connect', |
| 236 |
'', |
| 237 |
'pb_user_login_social_connect', |
| 238 |
[ |
| 239 |
'sc_heading' => [ |
| 240 |
'selector' => '.wppb-sc-buttons-container .wppb-sc-heading-before-reg-buttons h3', |
| 241 |
'section_name' => 'Heading', |
| 242 |
], |
| 243 |
'sc_buttons' => [ |
| 244 |
'selector' => '.wppb-sc-buttons-container a.wppb-sc-button', |
| 245 |
'section_name' => 'Buttons', |
| 246 |
] |
| 247 |
] |
| 248 |
); |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
/** |
| 253 |
* Render widget output in the front-end. |
| 254 |
* |
| 255 |
*/ |
| 256 |
protected function render() { |
| 257 |
$output = $this->render_widget( 'l' ); |
| 258 |
echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 259 |
|
| 260 |
// check if the form is being displayed in the Elementor editor |
| 261 |
$is_elementor_edit_mode = false; |
| 262 |
if( class_exists ( '\Elementor\Plugin' ) ){ |
| 263 |
$is_elementor_edit_mode = \Elementor\Plugin::$instance->editor->is_edit_mode(); |
| 264 |
$message= ""; |
| 265 |
} |
| 266 |
|
| 267 |
if ($is_elementor_edit_mode && !empty($output) && $this->is_placeholder_labels_active()) { |
| 268 |
echo ' |
| 269 |
<script id="wppb_elementor_login_pbpl_init"> |
| 270 |
jQuery(".login-username input, .login-password input").each( function ( index, elem ) { |
| 271 |
var element_id = jQuery( elem ).attr( "id" ); |
| 272 |
if( element_id && ( label = jQuery( elem ).parents( "#wppb-login-wrap" ).find( "label[for=" + element_id + "]" ) ).length === 1 ) { |
| 273 |
jQuery( elem ).attr( "placeholder", jQuery( label ).text() ); |
| 274 |
} |
| 275 |
}); |
| 276 |
</script> |
| 277 |
'; |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
} |
| 282 |
|