functions - Wordpress registration and contact form 7

Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 5 years ago.

Improve this question

A very nice man shared this code to add to a theme's function file that will convert a cf7 form into a WORDPRESS registration form. The code that a man shared on moot point works for one form by calling the title of the form. I ask if there is a way to edit the code found under "Check this is the user registration form" so it can work for three forms and not just one, perhaps call for each form's title using "or". Thank you in advance for any advice, much appreciated. I confirmed this does work for one form:

function create_user_from_registration($cfdata) {
    if (!isset($cfdata->posted_data) && class_exists('WPCF7_Submission')) {
        // Contact Form 7 version 3.9 removed $cfdata->posted_data and now
        // we have to retrieve it from an API
        $submission = WPCF7_Submission::get_instance();
        if ($submission) {
            $formdata = $submission->get_posted_data();
        }
    } elseif (isset($cfdata->posted_data)) {
        // For pre-3.9 versions of Contact Form 7
        $formdata = $cfdata->posted_data;
    } else {
        // We can't retrieve the form data
        return $cfdata;
    }
    // Check this is the user registration form
    if ( $cfdata->title() == 'Registration: Retailer') {
        $password = wp_generate_password( 12, false );
        $email = $formdata['email'];
        $name = $formdata['username'];
        // Construct a username from the user's name
        $username = strtolower(str_replace(' ', '', $name));
        $name_parts = explode(' ',$name);
        if ( !email_exists( $email ) ) {
            // Find an unused username
            $username_tocheck = $username;
            $i = 1;
            while ( username_exists( $username_tocheck ) ) {
                $username_tocheck = $username . $i++;
            }
            $username = $username_tocheck;
            // Create the user
            $userdata = array(
                'user_login' => $username,
                'user_pass' => $password,
                'user_email' => $email,
                'nickname' => reset($name_parts),
                'display_name' => $formdata['company'],
                'first_name' => $formdata['firstname'],
                'last_name' => $formdata['lastname'],
                'role' => 'customer'
            );
            $user_id = wp_insert_user( $userdata );
            if ( !is_wp_error($user_id) ) {
                // Email login details to user
                $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
                $message = "Hello! We have received your registration request and is pending approval (be sure to save this email). We take pride in verifying that you are a legitimate business before approving your account. Your login details are as follows:" . "\r\n";
                $message .= sprintf(__('Username: %s'), $username) . "\r\n";
                $message .= sprintf(__('Password: %s'), $password) . "\r\n";
                $message .= home_url() . "\r\n";
                wp_mail($email, sprintf(__('[%s] Your username and password pending approval: SAVE THIS EMAIL'), $blogname), $message);
            }
        }
    }
    return $cfdata;
}
add_action('wpcf7_before_send_mail', 'create_user_from_registration', 1);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745314705a4622161.html

相关推荐

  • functions - Wordpress registration and contact form 7

    Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress.

    10小时前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信