Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // remember - the suffix of the hook should contain specific form id!
- add_action( "gform_pre_submission_3", "wp_doin_pre_submission" );
- function wp_doin_pre_submission($form) {
- // get the user created arguments and store them in an array
- // each of the $_POST elements should be read from the form visual editor
- $username = esc_attr( $_POST['input_1'] );
- $email = sanitize_email( $_POST['input_2'] );
- // if we're doing a cron job let's forget about it
- if ( defined( 'DOING_CRON' ) || isset( $_GET['doing_wp_cron'] ) )
- return;
- // let's check if a user with given name exists
- // we're already doing that in the form validation, but this gives us another bridge of safety
- $user_id = username_exists( $username );
- // let's validate the email and the user
- if ( !$user_id and email_exists( $email ) == false ) {
- // let's generate a passowrd
- $random_password = wp_generate_password( $length = 12, false );
- // let's create a new user
- $user_id = wp_create_user( $name, $random_password, $email );
- // let's notify the new user
- wp_new_user_notification( $user_id, $random_password );
- } else {
- // validation failed
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement