Guest User

CF7 Script Mod - GF

a guest
Jan 28th, 2016
318
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. // Exit if accessed directly
  3. if ( !defined( 'ABSPATH' ) ) exit;
  4.  
  5. // BEGIN ENQUEUE PARENT ACTION
  6. // AUTO GENERATED - Do not modify or remove comment markers above or below:
  7.  
  8.  
  9. function create_user_from_registration($cfdata) {
  10. if (!isset($cfdata->posted_data) && class_exists('WPCF7_Submission')) {
  11. // Contact Form 7 version 3.9 removed $cfdata->posted_data and now
  12. // we have to retrieve it from an API
  13. $submission = WPCF7_Submission::get_instance();
  14. if ($submission) {
  15. $formdata = $submission->get_posted_data();
  16. }
  17. } elseif (isset($cfdata->posted_data)) {
  18. // For pre-3.9 versions of Contact Form 7
  19. $formdata = $cfdata->posted_data;
  20. } else {
  21. // We can't retrieve the form data
  22. return $cfdata;
  23. }
  24. // Check this is the user registration form
  25. if ( $cfdata->title() == 'blog_registration') {
  26. $password = wp_generate_password( 12, false );
  27. $email = $formdata['your-email'];
  28. // Construct a username from the user's name
  29. $username = strtolower(str_replace(' ', '', $name));
  30. $name_parts = explode(' ',$name);
  31. if ( !email_exists( $email ) ) {
  32. // Find an unused username
  33. $username_tocheck = $username;
  34. $i = 1;
  35. while ( username_exists( $username_tocheck ) ) {
  36. $username_tocheck = $username . $i++;
  37. }
  38. $username = $username_tocheck;
  39. // Create the user
  40. $userdata = array(
  41. 'user_login' => $username,
  42. 'user_pass' => $password,
  43. 'user_email' => $email,
  44. 'nickname' => reset($name_parts),
  45. 'display_name' => $name,
  46. 'first_name' => reset($name_parts),
  47. 'last_name' => end($name_parts),
  48. 'role' => 'customer'
  49. );
  50. $user_id = wp_insert_user( $userdata );
  51. if ( !is_wp_error($user_id) ) {
  52. // Email login details to user
  53. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  54. $message = "Welcome! Your login details are as follows:" . "\r\n";
  55. $message .= sprintf(__('Username: %s'), $username) . "\r\n";
  56. $message .= sprintf(__('Password: %s'), $password) . "\r\n";
  57. $message .= wp_login_url() . "\r\n";
  58. wp_mail($email, sprintf(__('[%s] Your username and password'), $blogname), $message);
  59. }
  60. }
  61. }
  62. return $cfdata;
  63. }
  64. add_action('wpcf7_before_send_mail', 'create_user_from_registration', 1);
  65.  
  66. if ( !function_exists( 'chld_thm_cfg_parent_css' ) ):
  67. function chld_thm_cfg_parent_css() {
  68. wp_enqueue_style( 'chld_thm_cfg_parent', trailingslashit( get_template_directory_uri() ) . 'style.css' );
  69. wp_enqueue_style( 'chld_thm_cfg_ext1', 'https://fonts.googleapis.com/css?family=Muli' );
  70. }
  71. endif;
  72. add_action( 'wp_enqueue_scripts', 'chld_thm_cfg_parent_css' );
  73.  
  74. // END ENQUEUE PARENT ACTION
  75.  
  76. add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
  77.  
  78. function custom_override_checkout_fields( $fields ) {
  79. unset($fields['billing']['billing_first_name']);
  80. unset($fields['billing']['billing_last_name']);
  81. unset($fields['billing']['billing_company']);
  82. unset($fields['billing']['billing_address_1']);
  83. unset($fields['billing']['billing_address_2']);
  84. unset($fields['billing']['billing_city']);
  85. unset($fields['billing']['billing_postcode']);
  86. unset($fields['billing']['billing_country']);
  87. unset($fields['billing']['billing_state']);
  88. unset($fields['billing']['billing_phone']);
  89. unset($fields['order']['order_comments']);
  90. unset($fields['billing']['billing_address_2']);
  91. unset($fields['billing']['billing_postcode']);
  92. unset($fields['billing']['billing_company']);
  93. unset($fields['billing']['billing_last_name']);
  94. unset($fields['billing']['billing_email']);
  95. unset($fields['billing']['billing_city']);
  96. return $fields;
  97. }
  98. add_action( 'admin_bar_menu', 'wp_admin_bar_my_custom_account_menu', 11 );
  99. function wp_admin_bar_my_custom_account_menu( $wp_admin_bar ) {
  100. $user_id = get_current_user_id();
  101. $current_user = wp_get_current_user();
  102. $profile_url = get_edit_profile_url( $user_id );
  103.  
  104. if ( 0 != $user_id ) {
  105.  
  106. /* Add the "My Account" menu */
  107. $avatar = get_avatar( $user_id, 28 );
  108. $howdy = sprintf( __('Welcome, %1$s'), $current_user->display_name );
  109. $class = empty( $avatar ) ? '' : 'with-avatar';
  110.  
  111. $wp_admin_bar->add_menu( array('id' => 'my-account',
  112. 'parent' => 'top-secondary',
  113. 'title' => $howdy . $avatar,
  114. 'href' => $profile_url,
  115. 'meta' => array(
  116. 'class' => $class,
  117. ),
  118. ) );
  119. }
  120. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×