wordpress/wp-content/themes/basic/themify/themify-builder/modules/module-signup-form.php
/**
	 * Actions to perform when sign up via Sign Up module is sent
	 *
	 */
Actions to perform when sign up via Sign Up module is sent
Actions to perform when sign up via Sign Up module is sent
public static function signup_process() {
		if ( empty( $_POST['data'] ) || !wp_verify_nonce( $_POST['nonce'], 'tb_signup_nonce' ) ) {
			die( -1 );
		}
		$data = urldecode($_POST['data']);
		$data = explode('&',$data);
		foreach ( $data as $input ) {
		    $input = explode( '=', $input );
		    if ( ! empty( $input[1] ) ) {
		        $params[ $input[0] ] = $input[1];
            }
        }
		$data = $input = null;
		$errs = array();
		if ( false === ( $role = get_transient( 'tb_signup_' . $_POST['nonce'] ) ) ) {
			$errs[] = __( 'User role is not valid.', 'themify' );
		}
		if ( empty( $params['usr'] ) ) {
			$errs[] = __( 'Please enter a username', 'themify' );
		}
		elseif ( !validate_username( $params['usr'] ) ) {
			$errs[] = __( 'Invalid username', 'themify' );
		}
		elseif ( username_exists( $params['usr'] ) ) {
			$errs[] = __( 'Username already taken', 'themify' );
		}
		if (empty($params['email']) || !is_email( $params['email']) ) {
			$errs[] = __( 'Invalid email', 'themify' );
		}
		elseif ( email_exists( $params['email'] ) ) {
			$errs[] = __( 'Email already registered', 'themify' );
		}
		if ( empty( $params['pwd'] ) ) {
			$errs[] = __( 'Please enter a password', 'themify' );
		}
		if ( empty( $errs ) ) {
			$new_user_id = wp_insert_user( array(
					'user_login' => $params['usr'],
					'user_pass' => $params['pwd'],
					'user_email' => $params['email'],
					'first_name' => $params['first_n'],
					'last_name' => $params['last_n'],
					'description' => isset( $params['bio'] ) ? $params['bio'] : '',
					'user_registered' => date( 'Y-m-d H:i:s' ),
					'role' => $role
				)
			);
			if ( $new_user_id ) {
				if ( isset( $params['optin'] ) && $params['optin'] == '1' ) {
					if ( ! class_exists( 'Builder_Optin_Service' ) ){
						include_once( THEMIFY_BUILDER_INCLUDES_DIR. '/optin-services/base.php' );
					}
					$optin_instance = Builder_Optin_Service::get_providers( $params['optin-provider'] );
					if ( $optin_instance ) {
						$data = array(
							'email' => $params['email'],
							'fname' => $params['first_n'],
							'lname' => $params['last_n'],
						);
						foreach ( $params as $key => $value ) {
							if ( preg_match( '/^optin-/', $key ) ) {
								$key = preg_replace( '/^optin-/', '', $key );
								$data[ $key ] = sanitize_text_field( trim( $value ) );
							}
						}
						$optin_instance->subscribe( $data );
					}
				}
				if ( $params['tb_e_admin'] === '1' || $params['tb_e_user'] === '1' ) {
					$notify = '';
				    if($params['tb_e_admin'] === '1' && $params['tb_e_user'] === '1'){
					    $notify = 'both';
                    }elseif ($params['tb_e_user'] === '1'){
					    $notify = 'user';
                    }
					wp_new_user_notification( $new_user_id, null, $notify );
				}
				$response['result'] = 'success';
			} else {
				$response['result'] = 'fail';
				$response['err'][] = __( 'Something went wrong with registration', 'themify' );
			}
		} else {
			$response['err'] = $errs;
			$response['result'] = 'fail';
		}
		wp_send_json( $response );
	}
public static function signup_process ( ) { if ( empty ( $ _POST [ 'data' ] ) || ! wp_verify_nonce ( $ _POST [ 'nonce' ] , 'tb_signup_nonce' ) ) { die ( - 1 ) ; } $ data = urldecode ( $ _POST [ 'data' ] ) ; $ data = explode ( '&' , $ data ) ; foreach ( $ data as $ input ) { $ input = explode ( '=' , $ input ) ; if ( ! empty ( $ input [ 1 ] ) ) { $ params [ $ input [ 0 ] ] = $ input [ 1 ] ; } } $ data = $ input = null ; $ errs = array ( ) ; if ( false === ( $ role = get_transient ( 'tb_signup_' . $ _POST [ 'nonce' ] ) ) ) { $ errs [ ] = __ ( 'User role is not valid.' , 'themify' ) ; } if ( empty ( $ params [ 'usr' ] ) ) { $ errs [ ] = __ ( 'Please enter a username' , 'themify' ) ; } elseif ( ! validate_username ( $ params [ 'usr' ] ) ) { $ errs [ ] = __ ( 'Invalid username' , 'themify' ) ; } elseif ( username_exists ( $ params [ 'usr' ] ) ) { $ errs [ ] = __ ( 'Username already taken' , 'themify' ) ; } if ( empty ( $ params [ 'email' ] ) || ! is_email ( $ params [ 'email' ] ) ) { $ errs [ ] = __ ( 'Invalid email' , 'themify' ) ; } elseif ( email_exists ( $ params [ 'email' ] ) ) { $ errs [ ] = __ ( 'Email already registered' , 'themify' ) ; } if ( empty ( $ params [ 'pwd' ] ) ) { $ errs [ ] = __ ( 'Please enter a password' , 'themify' ) ; } if ( empty ( $ errs ) ) { $ new_user_id = wp_insert_user ( array ( 'user_login' => $ params [ 'usr' ] , 'user_pass' => $ params [ 'pwd' ] , 'user_email' => $ params [ 'email' ] , 'first_name' => $ params [ 'first_n' ] , 'last_name' => $ params [ 'last_n' ] , 'description' => isset ( $ params [ 'bio' ] ) ? $ params [ 'bio' ] : '' , 'user_registered' => date ( 'Y-m-d H:i:s' ) , 'role' => $ role ) ) ; if ( $ new_user_id ) { if ( isset ( $ params [ 'optin' ] ) && $ params [ 'optin' ] == '1' ) { if ( ! class_exists ( 'Builder_Optin_Service' ) ) { include_once ( THEMIFY_BUILDER_INCLUDES_DIR . '/optin-services/base.php' ) ; } $ optin_instance = Builder_Optin_Service :: get_providers ( $ params [ 'optin-provider' ] ) ; if ( $ optin_instance ) { $ data = array ( 'email' => $ params [ 'email' ] , 'fname' => $ params [ 'first_n' ] , 'lname' => $ params [ 'last_n' ] , ) ; foreach ( $ params as $ key => $ value ) { if ( preg_match ( '/^optin-/' , $ key ) ) { $ key = preg_replace ( '/^optin-/' , '' , $ key ) ; $ data [ $ key ] = sanitize_text_field ( trim ( $ value ) ) ; } } $ optin_instance -> subscribe ( $ data ) ; } } if ( $ params [ 'tb_e_admin' ] === '1' || $ params [ 'tb_e_user' ] === '1' ) { $ notify = '' ; if ( $ params [ 'tb_e_admin' ] === '1' && $ params [ 'tb_e_user' ] === '1' ) { $ notify = 'both' ; } elseif ( $ params [ 'tb_e_user' ] === '1' ) { $ notify = 'user' ; } wp_new_user_notification ( $ new_user_id , null , $ notify ) ; } $ response [ 'result' ] = 'success' ; } else { $ response [ 'result' ] = 'fail' ; $ response [ 'err' ] [ ] = __ ( 'Something went wrong with registration' , 'themify' ) ; } } else { $ response [ 'err' ] = $ errs ; $ response [ 'result' ] = 'fail' ; } wp_send_json ( $ response ) ; }
Actions to perform when sign up via Sign Up module is sent
Actions to perform when sign up via Sign Up module is sent
// Validate User role based on saved role in transient for seacurity reason // newsletter subscription // collect the data for optin service