| 1 |
<?php |
| 2 |
|
| 3 |
class WPPB_Register extends ET_Builder_Module { |
| 4 |
|
| 5 |
public $slug = 'wppb_register'; |
| 6 |
public $vb_support = 'on'; |
| 7 |
|
| 8 |
protected $module_credits = array( |
| 9 |
'module_uri' => 'https://wordpress.org/plugins/profile-builder/', |
| 10 |
'author' => 'Cozmoslabs', |
| 11 |
'author_uri' => 'https://www.cozmoslabs.com/', |
| 12 |
); |
| 13 |
|
| 14 |
public function init() { |
| 15 |
$this->name = esc_html__( 'PB Register', 'profile-builder' ); |
| 16 |
|
| 17 |
$this->settings_modal_toggles = array( |
| 18 |
'general' => array( |
| 19 |
'toggles' => array( |
| 20 |
'main_content' => esc_html__( 'Form Settings', 'profile-builder' ), |
| 21 |
), |
| 22 |
), |
| 23 |
); |
| 24 |
|
| 25 |
$this->advanced_fields = array( |
| 26 |
'link_options' => false, |
| 27 |
'background' => false, |
| 28 |
'admin_label' => false, |
| 29 |
); |
| 30 |
} |
| 31 |
|
| 32 |
public function get_fields() { |
| 33 |
$args = array( |
| 34 |
'post_type' => 'page', |
| 35 |
'posts_per_page' => -1 |
| 36 |
); |
| 37 |
|
| 38 |
if( function_exists( 'wc_get_page_id' ) ) |
| 39 |
$args['exclude'] = wc_get_page_id( 'shop' ); |
| 40 |
|
| 41 |
$all_pages = get_posts( $args ); |
| 42 |
$pages ['default'] = 'None'; |
| 43 |
|
| 44 |
if( !empty( $all_pages ) ){ |
| 45 |
foreach ( $all_pages as $page ){ |
| 46 |
$pages [ esc_url( get_page_link( $page->ID ) ) ] = esc_html( $page->post_title ); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
$wppb_module_settings = get_option( 'wppb_module_settings', 'not_found' ); |
| 51 |
|
| 52 |
$registration_forms ['default'] = esc_html__( 'Default' , 'profile-builder' ); |
| 53 |
|
| 54 |
if ( !( ( $wppb_module_settings !== 'not_found' && ( |
| 55 |
!isset( $wppb_module_settings['wppb_multipleRegistrationForms'] ) || |
| 56 |
$wppb_module_settings['wppb_multipleRegistrationForms'] !== 'show' |
| 57 |
) ) || |
| 58 |
$wppb_module_settings === 'not_found' ) ){ |
| 59 |
$args = array( |
| 60 |
'post_type' => 'wppb-rf-cpt', |
| 61 |
'posts_per_page' => -1 |
| 62 |
); |
| 63 |
|
| 64 |
$the_query = new WP_Query( $args ); |
| 65 |
|
| 66 |
if ( $the_query->have_posts() ) { |
| 67 |
foreach ( $the_query->posts as $post ) { |
| 68 |
$registration_forms [esc_attr( Wordpress_Creation_Kit_PB::wck_generate_slug( $post->post_title ) )] = esc_html( $post->post_title ); |
| 69 |
} |
| 70 |
wp_reset_postdata(); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
if (!function_exists('get_editable_roles')) { |
| 75 |
require_once ABSPATH . 'wp-admin/includes/user.php'; |
| 76 |
} |
| 77 |
$user_roles ['default'] = esc_html__( 'Default' , 'profile-builder' ); |
| 78 |
$editable_roles = get_editable_roles(); |
| 79 |
foreach ($editable_roles as $key => $role) { |
| 80 |
$user_roles [$key] = $role['name']; |
| 81 |
} |
| 82 |
|
| 83 |
$fields = array( |
| 84 |
'form_name' => array( |
| 85 |
'label' => esc_html__( 'Form', 'profile-builder' ), |
| 86 |
'type' => 'select', |
| 87 |
'options' => $registration_forms, |
| 88 |
'default' => 'default', |
| 89 |
'option_category' => 'basic_option', |
| 90 |
'description' => esc_html__( 'Select the desired Registration form.', 'profile-builder' ), |
| 91 |
'toggle_slug' => 'main_content', |
| 92 |
), |
| 93 |
'role' => array( |
| 94 |
'label' => esc_html__( 'Assigned Role', 'profile-builder' ), |
| 95 |
'type' => 'select', |
| 96 |
'options' => $user_roles, |
| 97 |
'default' => 'default', |
| 98 |
'option_category' => 'basic_option', |
| 99 |
'description' => esc_html__( 'Select a Role to be assigned to users that register via this form.', 'profile-builder' ), |
| 100 |
'toggle_slug' => 'main_content', |
| 101 |
'show_if' => array( |
| 102 |
'form_name' => 'default', |
| 103 |
), |
| 104 |
), |
| 105 |
'toggle_automatic_login' => array( |
| 106 |
'label' => esc_html__( 'Automatic Login', 'profile-builder' ), |
| 107 |
'type' => 'yes_no_button', |
| 108 |
'options' => array( |
| 109 |
'on' => esc_html__( 'Yes', 'profile-builder'), |
| 110 |
'off' => esc_html__( 'No', 'profile-builder'), |
| 111 |
), |
| 112 |
'option_category' => 'basic_option', |
| 113 |
'description' => esc_html__( 'Automatically log in users after they register.', 'profile-builder' ), |
| 114 |
'toggle_slug' => 'main_content', |
| 115 |
'show_if' => array( |
| 116 |
'form_name' => 'default', |
| 117 |
), |
| 118 |
), |
| 119 |
'redirect_url' => array( |
| 120 |
'label' => esc_html__( 'Redirect After Registration', 'profile-builder' ), |
| 121 |
'type' => 'select', |
| 122 |
'options' => $pages, |
| 123 |
'default' => 'default', |
| 124 |
'option_category' => 'basic_option', |
| 125 |
'description' => esc_html__( 'Select a page for an After Registration Redirect.', 'profile-builder' ), |
| 126 |
'toggle_slug' => 'main_content', |
| 127 |
'show_if' => array( |
| 128 |
'form_name' => 'default', |
| 129 |
), |
| 130 |
), |
| 131 |
'logout_redirect_url' => array( |
| 132 |
'label' => esc_html__( 'Redirect After Logout', 'profile-builder' ), |
| 133 |
'type' => 'select', |
| 134 |
'options' => $pages, |
| 135 |
'default' => 'default', |
| 136 |
'option_category' => 'basic_option', |
| 137 |
'description' => esc_html__( 'Select a page for an After Logout Redirect.', 'profile-builder' ), |
| 138 |
'toggle_slug' => 'main_content', |
| 139 |
), |
| 140 |
); |
| 141 |
|
| 142 |
if( defined( 'WPPB_PAID_PLUGIN_DIR' ) ) { |
| 143 |
$fields['toggle_ajax_validation'] = array( |
| 144 |
'label' => esc_html__( 'AJAX Validation', 'profile-builder' ), |
| 145 |
'type' => 'yes_no_button', |
| 146 |
'options' => array( |
| 147 |
'on' => esc_html__( 'Yes', 'profile-builder'), |
| 148 |
'off' => esc_html__( 'No', 'profile-builder'), |
| 149 |
), |
| 150 |
'option_category' => 'basic_option', |
| 151 |
'description' => esc_html__( 'Use AJAX to Validate the Register Form without reloading the page.', 'profile-builder' ), |
| 152 |
'toggle_slug' => 'main_content', |
| 153 |
'show_if' => array( |
| 154 |
'form_name' => 'default', |
| 155 |
), |
| 156 |
); |
| 157 |
} |
| 158 |
|
| 159 |
return $fields; |
| 160 |
} |
| 161 |
|
| 162 |
public function render( $attrs, $content, $render_slug ) { |
| 163 |
|
| 164 |
if ( !is_array( $attrs ) ) { |
| 165 |
return; |
| 166 |
} |
| 167 |
|
| 168 |
include_once(WPPB_PLUGIN_DIR . '/front-end/register.php'); |
| 169 |
include_once(WPPB_PLUGIN_DIR . '/front-end/class-formbuilder.php'); |
| 170 |
|
| 171 |
$form_name = 'unspecified'; |
| 172 |
if ( array_key_exists( 'form_name', $attrs ) ) { |
| 173 |
$form_name = sanitize_text_field($attrs['form_name']); |
| 174 |
if ( $form_name === 'default' ) { |
| 175 |
$form_name = 'unspecified'; |
| 176 |
} |
| 177 |
} |
| 178 |
if ( !$form_name || $form_name === 'unspecified' ) { |
| 179 |
$atts = [ |
| 180 |
'role' => array_key_exists( 'role', $attrs ) && $attrs['role'] !== '' ? sanitize_text_field( $attrs['role'] ) : '', |
| 181 |
'form_name' => '', |
| 182 |
'redirect_url' => array_key_exists( 'redirect_url', $attrs ) && $attrs['redirect_url'] !== '' ? pb_divi_parse_url( $attrs['redirect_url'] ) : '', |
| 183 |
'logout_redirect_url' => array_key_exists( 'logout_redirect_url', $attrs ) && $attrs['logout_redirect_url'] !== '' ? pb_divi_parse_url( $attrs['logout_redirect_url'] ) : '', |
| 184 |
'ajax' => array_key_exists( 'toggle_ajax_validation', $attrs ) && $attrs['toggle_ajax_validation'] === 'on' ? 'true' : false, |
| 185 |
'automatic_login' => array_key_exists( 'toggle_automatic_login', $attrs ) && $attrs['toggle_automatic_login'] ? 'yes' : '', |
| 186 |
|
| 187 |
]; |
| 188 |
} else { |
| 189 |
$atts = [ |
| 190 |
'role' => '', |
| 191 |
'form_name' => $form_name, |
| 192 |
'redirect_url' => '', |
| 193 |
'logout_redirect_url' => array_key_exists( 'logout_redirect_url', $attrs ) && $attrs['logout_redirect_url'] !== '' ? pb_divi_parse_url( $attrs['logout_redirect_url'] ) : '', |
| 194 |
'ajax' => false, |
| 195 |
'automatic_login' => '', |
| 196 |
|
| 197 |
]; |
| 198 |
} |
| 199 |
return '<div class="wppb-divi-front-end-container">' . wppb_front_end_register( $atts ) . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 200 |
} |
| 201 |
} |
| 202 |
|
| 203 |
new WPPB_Register; |
| 204 |
|