| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly |
| 4 |
if ( ! defined( 'ABSPATH' ) ) exit; |
| 5 |
|
| 6 |
use Elementor\Controls_Manager; |
| 7 |
use Elementor\Group_Control_Border; |
| 8 |
use Elementor\Group_Control_Typography; |
| 9 |
use Elementor\Scheme_Typography; |
| 10 |
|
| 11 |
/** |
| 12 |
* Base class for the Profile Builder Elementor widgets |
| 13 |
*/ |
| 14 |
abstract class PB_Elementor_Widget extends \Elementor\Widget_Base { |
| 15 |
|
| 16 |
/** |
| 17 |
* Get widget categories. |
| 18 |
* |
| 19 |
*/ |
| 20 |
public function get_categories() { |
| 21 |
return array( 'profile-builder' ); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Add styling control group and populate it. |
| 26 |
* @param $section_label |
| 27 |
* @param $condition |
| 28 |
* @param $id_prefix |
| 29 |
* @param $sections |
| 30 |
*/ |
| 31 |
protected function add_styling_control_group($section_label, $condition, $id_prefix, $sections ){ |
| 32 |
|
| 33 |
$this->start_controls_section( |
| 34 |
$id_prefix.'_style_section', |
| 35 |
[ |
| 36 |
'label' => $section_label === '' ? __( 'Unlabelled Field', 'profile-builder' ) : $section_label, |
| 37 |
'tab' => Controls_Manager::TAB_STYLE, |
| 38 |
'condition' => $condition, |
| 39 |
] |
| 40 |
); |
| 41 |
|
| 42 |
if ( count($sections) > 1 ) { |
| 43 |
foreach ( $sections as $target => $section ) { |
| 44 |
$this->add_control( |
| 45 |
$id_prefix.'_section_'.$target.'_div1', |
| 46 |
[ |
| 47 |
'type' => \Elementor\Controls_Manager::DIVIDER, |
| 48 |
] |
| 49 |
); |
| 50 |
|
| 51 |
$this->add_control( |
| 52 |
$id_prefix.'_target_'.$target, |
| 53 |
[ |
| 54 |
'label' => $section['section_name'], |
| 55 |
'type' => Controls_Manager::HEADING, |
| 56 |
] |
| 57 |
); |
| 58 |
|
| 59 |
$this->add_control( |
| 60 |
$id_prefix.'_section_'.$target.'_div2', |
| 61 |
[ |
| 62 |
'type' => \Elementor\Controls_Manager::DIVIDER, |
| 63 |
] |
| 64 |
); |
| 65 |
|
| 66 |
$this->add_styling_control_element($id_prefix . '_' . $target, $section['selector']); |
| 67 |
} |
| 68 |
} else { |
| 69 |
foreach ( $sections as $target => $section ) { |
| 70 |
$this->add_styling_control_element($id_prefix . '_' . $target, $section['selector']); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
$this->end_controls_section(); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Populate the control groups. |
| 79 |
* @param $id_prefix |
| 80 |
* @param $selector |
| 81 |
* @param array $condition |
| 82 |
*/ |
| 83 |
private function add_styling_control_element($id_prefix, $selector, $condition = [] ){ |
| 84 |
|
| 85 |
$wrapped_selector = ''; |
| 86 |
if ( is_array($selector )) { |
| 87 |
end($selector); |
| 88 |
$final_key = key($selector); |
| 89 |
reset($selector); |
| 90 |
foreach ($selector as $key => $individual_selector) { |
| 91 |
$wrapped_selector .= '{{WRAPPER}} ' . $individual_selector; |
| 92 |
if ($key !== $final_key) { |
| 93 |
$wrapped_selector .= ', '; |
| 94 |
} |
| 95 |
} |
| 96 |
} else { |
| 97 |
$wrapped_selector .= '{{WRAPPER}} ' . $selector; |
| 98 |
} |
| 99 |
|
| 100 |
$this->add_group_control( |
| 101 |
Group_Control_Typography::get_type(), |
| 102 |
[ |
| 103 |
'name' => $id_prefix.'_typography', |
| 104 |
'selector' => $wrapped_selector, |
| 105 |
'condition' => $condition, |
| 106 |
] |
| 107 |
); |
| 108 |
|
| 109 |
$this->add_control( |
| 110 |
$id_prefix.'_background', |
| 111 |
[ |
| 112 |
'label' => __( 'Background', 'profile-builder' ), |
| 113 |
'type' => Controls_Manager::COLOR, |
| 114 |
'selectors' => [ |
| 115 |
$wrapped_selector => 'background-color: {{VALUE}};', |
| 116 |
], |
| 117 |
'condition' => $condition, |
| 118 |
] |
| 119 |
); |
| 120 |
|
| 121 |
$this->add_control( |
| 122 |
$id_prefix.'_text_color', |
| 123 |
[ |
| 124 |
'label' => __( 'Color', 'profile-builder' ), |
| 125 |
'type' => Controls_Manager::COLOR, |
| 126 |
'selectors' => [ |
| 127 |
$wrapped_selector => 'color: {{VALUE}};', |
| 128 |
], |
| 129 |
'separator' => 'after', |
| 130 |
'condition' => $condition, |
| 131 |
] |
| 132 |
); |
| 133 |
|
| 134 |
$this->add_responsive_control( |
| 135 |
$id_prefix.'_width', |
| 136 |
[ |
| 137 |
'label' => __( 'Width', 'profile-builder' ), |
| 138 |
'type' => Controls_Manager::SLIDER, |
| 139 |
'range' => [ |
| 140 |
'px' => [ |
| 141 |
'max' => 1000, |
| 142 |
'step' => 1, |
| 143 |
], |
| 144 |
'%' => [ |
| 145 |
'max' => 100, |
| 146 |
'step' => 1, |
| 147 |
], |
| 148 |
], |
| 149 |
'size_units' => [ 'px', 'em', '%' ], |
| 150 |
'selectors' => [ |
| 151 |
$wrapped_selector => 'width: {{SIZE}}{{UNIT}}', |
| 152 |
], |
| 153 |
'condition' => $condition, |
| 154 |
] |
| 155 |
); |
| 156 |
|
| 157 |
$this->add_responsive_control( |
| 158 |
$id_prefix.'_height', |
| 159 |
[ |
| 160 |
'label' => __( 'Height', 'profile-builder' ), |
| 161 |
'type' => Controls_Manager::SLIDER, |
| 162 |
'range' => [ |
| 163 |
'px' => [ |
| 164 |
'max' => 1000, |
| 165 |
'step' => 1, |
| 166 |
], |
| 167 |
'%' => [ |
| 168 |
'max' => 100, |
| 169 |
'step' => 1, |
| 170 |
], |
| 171 |
], |
| 172 |
'size_units' => [ 'px', 'em', '%' ], |
| 173 |
'selectors' => [ |
| 174 |
$wrapped_selector => 'height: {{SIZE}}{{UNIT}}', |
| 175 |
], |
| 176 |
'separator' => 'after', |
| 177 |
'condition' => $condition, |
| 178 |
|
| 179 |
] |
| 180 |
); |
| 181 |
|
| 182 |
$this->add_responsive_control( |
| 183 |
$id_prefix.'_padding', |
| 184 |
[ |
| 185 |
'label' => __( 'Padding', 'profile-builder' ), |
| 186 |
'type' => Controls_Manager::DIMENSIONS, |
| 187 |
'size_units' => [ 'px', '%', 'em' ], |
| 188 |
'selectors' => [ |
| 189 |
$wrapped_selector => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 190 |
], |
| 191 |
'condition' => $condition, |
| 192 |
] |
| 193 |
); |
| 194 |
|
| 195 |
$this->add_responsive_control( |
| 196 |
$id_prefix.'_margin', |
| 197 |
[ |
| 198 |
'label' => __( 'Margin', 'profile-builder' ), |
| 199 |
'type' => Controls_Manager::DIMENSIONS, |
| 200 |
'size_units' => [ 'px', '%', 'em' ], |
| 201 |
'selectors' => [ |
| 202 |
$wrapped_selector => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 203 |
], |
| 204 |
'separator' => 'after', |
| 205 |
'condition' => $condition, |
| 206 |
] |
| 207 |
); |
| 208 |
|
| 209 |
$this->add_group_control( |
| 210 |
Group_Control_Border::get_type(), |
| 211 |
[ |
| 212 |
'name' => $id_prefix.'_border', |
| 213 |
'label' => __( 'Border', 'profile-builder' ), |
| 214 |
'selector' => $wrapped_selector, |
| 215 |
'condition' => $condition, |
| 216 |
] |
| 217 |
); |
| 218 |
|
| 219 |
$this->add_responsive_control( |
| 220 |
$id_prefix.'_border_radius', |
| 221 |
[ |
| 222 |
'label' => esc_html__( 'Radius', 'profile-builder' ), |
| 223 |
'type' => Controls_Manager::DIMENSIONS, |
| 224 |
'selectors' => [ |
| 225 |
$wrapped_selector => 'border-radius: {{TOP}}px {{RIGHT}}px {{BOTTOM}}px {{LEFT}}px;', |
| 226 |
], |
| 227 |
'condition' => [$id_prefix.'_border_border!' => ''], |
| 228 |
] |
| 229 |
); |
| 230 |
} |
| 231 |
|
| 232 |
/** |
| 233 |
* Check if Placeholder Labels is active. |
| 234 |
* @return bool |
| 235 |
*/ |
| 236 |
protected function is_placeholder_labels_active(){ |
| 237 |
$toolbox_forms_settings = get_option( 'wppb_toolbox_forms_settings', 'not_found' ); |
| 238 |
|
| 239 |
if ( $toolbox_forms_settings !== 'not_found' && $toolbox_forms_settings['placeholder-labels'] === 'yes' ){ |
| 240 |
return true; |
| 241 |
} |
| 242 |
|
| 243 |
return false; |
| 244 |
} |
| 245 |
|
| 246 |
/** |
| 247 |
* Check if 2FA is active. |
| 248 |
* @return bool |
| 249 |
*/ |
| 250 |
protected function is_2fa_active(){ |
| 251 |
return wppb_is_2fa_active(); |
| 252 |
} |
| 253 |
|
| 254 |
/** |
| 255 |
* Get an aray of page names. |
| 256 |
* @return array |
| 257 |
*/ |
| 258 |
protected function get_all_pages(){ |
| 259 |
$args = array( |
| 260 |
'post_type' => 'page', |
| 261 |
'posts_per_page' => -1 |
| 262 |
); |
| 263 |
|
| 264 |
$page_titles = array( |
| 265 |
'' => '' |
| 266 |
); |
| 267 |
|
| 268 |
if( function_exists( 'wc_get_page_id' ) ) |
| 269 |
$args['exclude'] = wc_get_page_id( 'shop' ); |
| 270 |
|
| 271 |
$all_pages = get_posts( $args ); |
| 272 |
if( !empty( $all_pages ) ){ |
| 273 |
foreach ( $all_pages as $page ){ |
| 274 |
$page_titles[$page->ID] = $page->post_title; |
| 275 |
} |
| 276 |
} |
| 277 |
return $page_titles; |
| 278 |
} |
| 279 |
|
| 280 |
/** |
| 281 |
* Render the four widget types. |
| 282 |
* @param $form_type |
| 283 |
* @return mixed|Profile_Builder_Form_Creator|string|void |
| 284 |
*/ |
| 285 |
protected function render_widget( $form_type ){ |
| 286 |
|
| 287 |
if (!($form_type === 'rf' || $form_type === 'epf' || $form_type === 'l' || $form_type === 'rp' || $form_type === 'ul')) { |
| 288 |
return; |
| 289 |
} |
| 290 |
|
| 291 |
$settings = $this->get_settings_for_display(); |
| 292 |
|
| 293 |
switch ( $form_type ){ |
| 294 |
case 'rf': |
| 295 |
include_once(WPPB_PLUGIN_DIR . '/front-end/register.php'); |
| 296 |
include_once(WPPB_PLUGIN_DIR . '/front-end/class-formbuilder.php'); |
| 297 |
$form_name = ''; |
| 298 |
if (array_key_exists('pb_form_name', $settings)) { |
| 299 |
$form_name = substr($settings['pb_form_name'], 1); |
| 300 |
} |
| 301 |
if (!$form_name || $form_name === ''){ |
| 302 |
$form_name = 'unspecified'; |
| 303 |
} |
| 304 |
$atts = [ |
| 305 |
'role' => $settings['pb_role'], |
| 306 |
'form_name' => $form_name, |
| 307 |
'redirect_url' => !empty( $settings['pb_redirect_url'] ) ? get_page_link( $settings['pb_redirect_url'] ) : "", |
| 308 |
'logout_redirect_url' => !empty( $settings['pb_logout_redirect_url'] ) ? get_page_link( $settings['pb_logout_redirect_url'] ) : "", |
| 309 |
'automatic_login' => $settings['pb_automatic_login'], |
| 310 |
]; |
| 311 |
return wppb_front_end_register( $atts ); |
| 312 |
case 'epf': |
| 313 |
include_once(WPPB_PLUGIN_DIR . '/front-end/edit-profile.php'); |
| 314 |
include_once(WPPB_PLUGIN_DIR . '/front-end/class-formbuilder.php'); |
| 315 |
$form_name = ''; |
| 316 |
if (array_key_exists('pb_form_name', $settings)) { |
| 317 |
$form_name = substr($settings['pb_form_name'], 1); |
| 318 |
} |
| 319 |
if (!$form_name || $form_name === ''){ |
| 320 |
$form_name = 'unspecified'; |
| 321 |
} |
| 322 |
$atts = [ |
| 323 |
'form_name' => $form_name, |
| 324 |
'redirect_url' => !empty( $settings['pb_redirect_url'] ) ? get_page_link( $settings['pb_redirect_url'] ) : "", |
| 325 |
]; |
| 326 |
return wppb_front_end_profile_info( $atts ); |
| 327 |
case 'l': |
| 328 |
include_once( WPPB_PLUGIN_DIR.'/front-end/login.php' ); |
| 329 |
$atts = [ |
| 330 |
'redirect_url' => !empty( $settings['pb_after_login_redirect_url'] ) ? get_page_link( $settings['pb_after_login_redirect_url'] ) : "", |
| 331 |
'logout_redirect_url' => !empty( $settings['pb_after_logout_redirect_url'] ) ? get_page_link( $settings['pb_after_logout_redirect_url'] ) : "", |
| 332 |
'register_url' => !empty( $settings['pb_register_url'] ) ? get_page_link( $settings['pb_register_url'] ) : "", |
| 333 |
'lostpassword_url' => !empty( $settings['pb_lostpassword_url'] ) ? get_page_link( $settings['pb_lostpassword_url'] ) : "", |
| 334 |
'show_2fa_field' => isset( $settings['pb_auth_field'] ) ? $settings['pb_auth_field'] : false, |
| 335 |
]; |
| 336 |
return wppb_front_end_login( $atts ); |
| 337 |
case 'rp': |
| 338 |
include_once( WPPB_PLUGIN_DIR.'/front-end/recover.php' ); |
| 339 |
return wppb_front_end_password_recovery( [] ); |
| 340 |
case 'ul': |
| 341 |
if( defined( 'WPPB_PAID_PLUGIN_DIR' ) ){ |
| 342 |
include_once( WPPB_PAID_PLUGIN_DIR.'/add-ons/user-listing/userlisting.php' ); |
| 343 |
$atts = [ |
| 344 |
'name' => $settings['pb_name'], |
| 345 |
'single' => $settings['pb_single'] === 'yes', |
| 346 |
'meta_key' => $settings['pb_meta_key'], |
| 347 |
'meta_value' => $settings['pb_meta_key'] ? $settings['pb_meta_value'] : '', |
| 348 |
'include' => $settings['pb_include'], |
| 349 |
'exclude' => $settings['pb_exclude'], |
| 350 |
'id' => $settings['pb_id'], |
| 351 |
]; |
| 352 |
return wppb_user_listing_shortcode( $atts ); |
| 353 |
} |
| 354 |
} |
| 355 |
} |
| 356 |
} |
| 357 |
|
| 358 |
|