Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Exit if accessed directly
- if ( !defined( 'ABSPATH' ) ) exit;
- // BEGIN ENQUEUE PARENT ACTION
- // AUTO GENERATED - Do not modify or remove comment markers above or below:
- 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() == 'blog_registration') {
- $password = wp_generate_password( 12, false );
- $email = $formdata['your-email'];
- // 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' => $name,
- 'first_name' => reset($name_parts),
- 'last_name' => end($name_parts),
- '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 = "Welcome! Your login details are as follows:" . "\r\n";
- $message .= sprintf(__('Username: %s'), $username) . "\r\n";
- $message .= sprintf(__('Password: %s'), $password) . "\r\n";
- $message .= wp_login_url() . "\r\n";
- wp_mail($email, sprintf(__('[%s] Your username and password'), $blogname), $message);
- }
- }
- }
- return $cfdata;
- }
- add_action('wpcf7_before_send_mail', 'create_user_from_registration', 1);
- if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
- function chld_thm_cfg_parent_css() {
- wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css' );
- wp_enqueue_style( 'chld_thm_cfg_ext1', 'https://fonts.googleapis.com/css?family=Muli' );
- }
- endif;
- add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css' );
- // END ENQUEUE PARENT ACTION
- add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
- function custom_override_checkout_fields( $fields ) {
- unset($fields['billing']['billing_first_name']);
- unset($fields['billing']['billing_last_name']);
- unset($fields['billing']['billing_company']);
- unset($fields['billing']['billing_address_1']);
- unset($fields['billing']['billing_address_2']);
- unset($fields['billing']['billing_city']);
- unset($fields['billing']['billing_postcode']);
- unset($fields['billing']['billing_country']);
- unset($fields['billing']['billing_state']);
- unset($fields['billing']['billing_phone']);
- unset($fields['order']['order_comments']);
- unset($fields['billing']['billing_address_2']);
- unset($fields['billing']['billing_postcode']);
- unset($fields['billing']['billing_company']);
- unset($fields['billing']['billing_last_name']);
- unset($fields['billing']['billing_email']);
- unset($fields['billing']['billing_city']);
- return $fields;
- }
- add_action( 'admin_bar_menu', 'wp_admin_bar_my_custom_account_menu', 11 );
- function wp_admin_bar_my_custom_account_menu( $wp_admin_bar ) {
- $user_id = get_current_user_id();
- $current_user = wp_get_current_user();
- $profile_url = get_edit_profile_url( $user_id );
- if ( 0 != $user_id ) {
- /* Add the "My Account" menu */
- $avatar = get_avatar( $user_id, 28 );
- $howdy = sprintf( __('Welcome, %1$s'), $current_user->display_name );
- $class = empty( $avatar ) ? '' : 'with-avatar';
- $wp_admin_bar->add_menu( array('id' => 'my-account',
- 'parent' => 'top-secondary',
- 'title' => $howdy . $avatar,
- 'href' => $profile_url,
- 'meta' => array(
- 'class' => $class,
- ),
- ) );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement