'', 'form_fields' => array(), 'form_name' => '', 'role' => '', //used only for the register-form settings ); private $args; // Constructor method for the class function __construct( $args ) { // Merge the input arguments and the defaults $this->args = wp_parse_args( $args, $this->defaults ); global $wppb_shortcode_on_front; $wppb_shortcode_on_front = true; if( empty( $this->args['form_fields'] ) ) $this->args['form_fields'] = apply_filters( 'wppb_change_form_fields', get_option( 'wppb_manage_fields' ), $this->args ); if ( file_exists ( WPPB_PLUGIN_DIR.'/front-end/default-fields/default-fields.php' ) ) require_once( WPPB_PLUGIN_DIR.'/front-end/default-fields/default-fields.php' ); if ( file_exists ( WPPB_PLUGIN_DIR.'/front-end/extra-fields/extra-fields.php' ) ) require_once( WPPB_PLUGIN_DIR.'/front-end/extra-fields/extra-fields.php' ); $this->wppb_retrieve_custom_settings(); add_action( 'wp_footer', array( &$this, 'wppb_print_script' ) ); //print scripts } function wppb_retrieve_custom_settings(){ $this->args['login_after_register'] = apply_filters( 'wppb_automatically_login_after_register', 'No' ); //used only for the register-form settings $this->args['redirect_activated'] = apply_filters( 'wppb_redirect_default_setting', '' ); $this->args['redirect_url'] = apply_filters( 'wppb_redirect_default_location', wppb_curpageurl() ); /* for register forms check to see if we have a custom redirect "Redirect After Register" */ if( $this->args['form_type'] == 'register' ){ $wppb_module_settings = get_option( 'wppb_module_settings' ); if ( isset( $wppb_module_settings['wppb_customRedirect'] ) && ( $wppb_module_settings['wppb_customRedirect'] == 'show' ) ){ $custom_redirect = get_option( 'customRedirectSettings' ); if ( isset( $custom_redirect['afterRegister'] ) && ( $custom_redirect['afterRegister'] == 'yes' ) && ( trim( $custom_redirect['afterRegisterTarget'] ) != '' ) ){ $this->args['redirect_url'] = $this->args['custom_redirect_after_register_url'] = apply_filters( 'wppb_redirect_default_location', $custom_redirect['afterRegisterTarget'] ); } } } $this->args['redirect_delay'] = apply_filters( 'wppb_redirect_default_duration', 3 ); if ( $this->args['form_name'] != 'unspecified' ){ $post_type = ( ( $this->args['form_type'] == 'register' ) ? 'wppb-rf-cpt' : 'wppb-epf-cpt' ); $meta_name = ( ( $this->args['form_type'] == 'register' ) ? 'wppb_rf_page_settings' : 'wppb_epf_page_settings' ); $ep_r_posts = get_posts( array( 'posts_per_page' => -1, 'post_status' => apply_filters ( 'wppb_get_ep_r_posts_on_front_end', array( 'publish' ) ), 'post_type' => $post_type, 'orderby' => 'post_date', 'order' => 'ASC' ) ); foreach ( $ep_r_posts as $key => $value ){ if ( trim( Wordpress_Creation_Kit_PB::wck_generate_slug( $value->post_title ) ) == $this->args['form_name'] ){ $page_settings = get_post_meta( $value->ID, $meta_name, true ); if( !empty( $page_settings[0]['set-role'] ) ){ if( $page_settings[0]['set-role'] == 'default role' ){ $selected_role = trim( get_option( 'default_role' ) ); } else $selected_role = $page_settings[0]['set-role']; } $this->args['role'] = ( isset( $selected_role ) ? $selected_role : $this->args['role'] ); $this->args['login_after_register'] = ( isset( $page_settings[0]['automatically-log-in'] ) ? $page_settings[0]['automatically-log-in'] : $this->args['login_after_register'] ); $this->args['redirect_activated'] = ( isset( $page_settings[0]['redirect'] ) ? $page_settings[0]['redirect'] : $this->args['redirect_activated'] ); $this->args['redirect_url'] = ( isset( $page_settings[0]['url'] ) ? $page_settings[0]['url'] : $this->args['redirect_url'] ); $this->args['redirect_delay'] = ( isset( $page_settings[0]['display-messages'] ) ? $page_settings[0]['display-messages'] : $this->args['redirect_delay'] ); } } } } function wppb_form_logic() { if( $this->args['form_type'] == 'register' ){ $registration = apply_filters ( 'wppb_register_setting_override', get_option( 'users_can_register' ) ); if ( !is_user_logged_in() ){ if ( !$registration ) echo apply_filters( 'wppb_register_pre_form_message', '
'.__( 'Only an administrator can add new users.', 'profilebuilder').'
' ); elseif ( $registration ){ $this->wppb_form_content( apply_filters( 'wppb_register_pre_form_message', '' ) ); } }else{ $current_user_capability = apply_filters ( 'wppb_registration_user_capability', 'create_users' ); if ( current_user_can( $current_user_capability ) && $registration ) $this->wppb_form_content( apply_filters( 'wppb_register_pre_form_message', ''.__( 'Users can register themselves or you can manually create users here.', 'profilebuilder').'
' ) ); elseif ( current_user_can( $current_user_capability ) && !$registration ) $this->wppb_form_content( apply_filters( 'wppb_register_pre_form_message', ''.__( 'Users cannot currently register themselves, but you can manually create users here.', 'profilebuilder').'
' ) ); elseif ( !current_user_can( $current_user_capability ) ){ global $user_ID; $userdata = get_userdata( $user_ID ); $display_name = ( ( $userdata->data->display_name == '' ) ? $userdata->data->user_login : $userdata->data->display_name ); $wppb_general_settings = get_option( 'wppb_general_settings' ); if ( isset( $wppb_general_settings['loginWith'] ) && ( $wppb_general_settings['loginWith'] == 'email' ) ) $display_name = $userdata->data->user_email; echo apply_filters( 'wppb_register_pre_form_message', ''.sprintf( __( "You are currently logged in as %1s. You don't need another account. %2s", 'profilebuilder' ), ''.$display_name.'', ''.__( 'Logout', 'profilebuilder' ).' »' ).'
', $user_ID ); } } }elseif ( $this->args['form_type'] == 'edit_profile' ){ if ( !is_user_logged_in() ) echo apply_filters( 'wppb_edit_profile_user_not_logged_in_message', ''.__( 'You must be logged in to edit your profile.', 'profilebuilder' ) .'
' ); elseif ( is_user_logged_in() ) $this->wppb_form_content( apply_filters( 'wppb_edit_profile_logged_in_user_message', '' ) ); } } function wppb_get_redirect(){ if ( $this->args['login_after_register'] == 'Yes' ) return $this->wppb_log_in_user(); if ( $this->args['redirect_activated'] == 'No' || ( $this->args['form_type'] == 'edit_profile' && $this->args['form_name'] == 'unspecified' ) || ( $this->args['form_type'] == 'register' && $this->args['form_name'] == 'unspecified' && wppb_curpageurl() == $this->args['redirect_url'] ) ) return ''; /* if we don't have a preference on the form for redirect then if we have a custom redirect "after register redirect" option redirect to that if not don't do anything */ if ( $this->args['redirect_activated'] == '-' ){ if( !empty( $this->args['custom_redirect_after_register_url'] ) ) $this->args['redirect_url'] = $this->args['custom_redirect_after_register_url']; else return ''; } $redirect_location = ( wppb_check_missing_http( $this->args['redirect_url'] ) ? 'http://'.$this->args['redirect_url'] : $this->args['redirect_url'] ); $redirect_url = apply_filters( 'wppb_redirect_url', ''.__( 'here', 'profilebuilder' ).'' ); return apply_filters ( 'wppb_redirect_message_before_returning', '', $this->args ); } function wppb_log_in_user(){ if ( is_user_logged_in() ) return; $wppb_general_settings = get_option( 'wppb_general_settings' ); if ( isset( $wppb_general_settings['emailConfirmation'] ) && ( $wppb_general_settings['emailConfirmation'] == 'yes' ) ) return; if ( isset( $wppb_general_settings['adminApproval'] ) && ( $wppb_general_settings['adminApproval'] == 'yes' ) ) return; if( !empty( $_POST['username'] ) ) $username = trim( $_POST['username'] ); $password = trim( $_POST['passw1'] ); if( isset( $wppb_general_settings['loginWith'] ) && ( $wppb_general_settings['loginWith'] == 'email' ) ){ $username = apply_filters( 'wppb_generated_random_username', Wordpress_Creation_Kit_PB::wck_generate_slug( trim( $_POST['email'] ) ), $_POST['email'] ); } /* get user id */ $user = get_user_by( 'login', $username ); $nonce = wp_create_nonce( 'autologin-'.$user->ID.'-'.(int)( time() / 60 ) ); /* define redirect location */ if ( $this->args['redirect_activated'] == 'No' ){ $location = home_url(); }else if ( $this->args['redirect_activated'] == '-' ){ if( !empty( $this->args['custom_redirect_after_register_url'] ) ) $location = $this->args['custom_redirect_after_register_url']; else $location = home_url(); } else{ $location = ( wppb_check_missing_http( $this->args['redirect_url'] ) ? 'http://'.$this->args['redirect_url'] : $this->args['redirect_url'] ); } $location .= "/?autologin=true&uid=$user->ID&_wpnonce=$nonce"; return ""; } function wppb_form_content( $message ){ $field_check_errors = array(); if( isset( $_REQUEST['action'] ) ){ $field_check_errors = $this->wppb_test_required_form_values( $_REQUEST ); if( empty( $field_check_errors ) ){ // we only have a $user_id on default registration (no email confirmation, no multisite) $user_id = $this->wppb_save_form_values( $_REQUEST ); if ( ( 'POST' == $_SERVER['REQUEST_METHOD'] ) && ( $_POST['action'] == $this->args['form_type'] ) ){ $form_message_tpl_start = apply_filters( 'wppb_form_message_tpl_start', ''); $form_message_tpl_end = apply_filters( 'wppb_form_message_tpl_end', '
'); if( $this->args['form_type'] == 'register' ){ // ec = email confirmation setting // aa = admin approval setting $wppb_general_settings = get_option( 'wppb_general_settings', 'false' ); if ( $wppb_general_settings ){ if( !empty( $wppb_general_settings['emailConfirmation'] ) ) $wppb_email_confirmation = $wppb_general_settings['emailConfirmation']; else $wppb_email_confirmation = 'no'; if( !empty( $wppb_general_settings['adminApproval'] ) ) $wppb_admin_approval = $wppb_general_settings['adminApproval']; else $wppb_admin_approval = 'no'; $account_management_settings = 'ec-' . $wppb_email_confirmation . '_' . 'aa-' . $wppb_admin_approval; } else { $account_management_settings = 'ec-no_aa-no'; } if ( isset( $_POST['username'] ) && ( trim( $_POST['username'] ) != '' ) ){ $account_name = trim( $_POST['username'] ); } elseif( isset( $_POST['email'] ) && ( trim( $_POST['email'] ) != '' ) ) { $account_name = trim( $_POST['email'] ); } switch ( $account_management_settings ){ case 'ec-no_aa-no': $wppb_register_success_message = apply_filters( 'wppb_register_success_message', sprintf( __( "The account %1s has been successfully created!", 'profilebuilder' ), $account_name ) ); break; case 'ec-yes_aa-no': $wppb_register_success_message = apply_filters( 'wppb_register_success_message', sprintf( __( "Before you can access your account %1s, you need to confirm your email address. Please check your inbox and click the activation link.", 'profilebuilder' ), $account_name ) ); break; case 'ec-no_aa-yes': $wppb_register_success_message = apply_filters( 'wppb_register_success_message', sprintf( __( "Before you can access your account %1s, an administrator has to approve it. You will be notified via email.", 'profilebuilder' ), $account_name ) ); break; case 'ec-yes_aa-yes': $wppb_register_success_message = apply_filters( 'wppb_register_success_message', sprintf( __( "Before you can access your account %1s, you need to confirm your email address. Please check your inbox and click the activation link.", 'profilebuilder' ), $account_name ) ); break; } $redirect = apply_filters( 'wppb_register_redirect', $this->wppb_get_redirect() ); echo $form_message_tpl_start . $wppb_register_success_message . $form_message_tpl_end . $redirect; //action hook after registration success do_action('wppb_register_success', $_REQUEST, $this->args['form_name'], $user_id); return; } elseif ( $this->args['form_type'] == 'edit_profile' ){ $redirect = apply_filters( 'wppb_edit_profile_redirect', $this->wppb_get_redirect() ); echo $form_message_tpl_start . apply_filters( 'wppb_edit_profile_success_message', __( 'Your profile has been successfully updated!', 'profilebuilder' ) ) . $form_message_tpl_end . $redirect; //action hook after edit profile success do_action('wppb_edit_profile_success', $_REQUEST, $this->args['form_name'], $user_id); if ( apply_filters( 'wppb_no_form_after_profile_update', false ) ) return; } } }else echo $message.apply_filters( 'wppb_general_top_error_message', ''.__( 'There was an error in the submitted form', 'profilebuilder' ).'
' ); }else echo $message; // use this action hook to add extra content before the register form do_action( 'wppb_before_'.$this->args['form_type'].'_fields' ); ?> args['form_type'] .'_fields' ); } function wppb_output_form_fields( $global_request, $field_check_errors ){ $output_fields = ''; if( !empty( $this->args['form_fields'] ) ){ foreach( $this->args['form_fields'] as $field ){ $error_var = ( ( array_key_exists( $field['id'], $field_check_errors ) ) ? ' wppb-field-error' : '' ); $specific_message = ( ( array_key_exists( $field['id'], $field_check_errors ) ) ? $field_check_errors[$field['id']] : '' ); $output_fields .= apply_filters( 'wppb_output_before_form_field', '