Advertisement
Guest User

Untitled

a guest
Nov 10th, 2016
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * PLEASE NOTE THIS CODE IS UNTESTED AND IS ONLY MEANT TO BE USED AS A STARTING POINT !!!
  5. *
  6. * CODE STILL NEEDS TO BE ADDED TO REMOVE OR PREVENT THE PASSWORD AND USER FIELDS FROM BEING SAVED TO THE LISTING!!
  7. * I MAY JUST END UP TURNING THIS INTO AN OPEN SOURCE PLUGIN LATER ON, BUT AS OF NOW I DON'T HAVE TIME TO
  8. */
  9.  
  10.  
  11. /**
  12. * This filter allows you to customize the user data before WP Job Manager adds the new user
  13. */
  14. add_filter( 'job_manager_create_account_data', 'smyles_allow_set_password_from_submit_form' );
  15.  
  16. /**
  17. * Override core WP Job Manager wp_job_manager_notify_new_user() function
  18. */
  19. add_action( 'after_setup_theme', array( $this, 'smyles_override_wp_job_manager_notify_new_user' ), 10 );
  20.  
  21. /**
  22. * Override core WP Job Manager notify function
  23. *
  24. * We have to prevent WP Job Manager from calling wp_new_user_notification() if using 4.3.1 or newer,
  25. * as it sets an activation key for the user in the DB, so we can bypass user account activation requirement.
  26. *
  27. * This function is called right before WP Job Manager defines its wp_job_manager_notify_new_user() function,
  28. * so we are essentially overriding it, and instead of using activation, we send a basic email with username
  29. * and password.
  30. *
  31. *
  32. */
  33. function smyles_override_wp_job_manager_notify_new_user(){
  34.  
  35. if ( ! function_exists( 'wp_job_manager_notify_new_user' ) ) :
  36.  
  37. function wp_job_manager_notify_new_user( $user_id, $password ) {
  38.  
  39. global $wp_version;
  40.  
  41. if ( version_compare( $wp_version, '4.3.1', '<' ) ) {
  42. // This means you're using old version of WordPress that does not require activation yet
  43. wp_new_user_notification( $user_id, $password );
  44.  
  45. } else {
  46. // Instead of calling wp_new_user_notification() we just send our own email
  47. $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
  48. $user = get_userdata( $user_id );
  49.  
  50. $message = sprintf( __( 'Username: %s' ), $user->user_login ) . "\r\n";
  51. $message .= sprintf( __( 'Password: %s' ), $password ) . "\r\n";
  52. $message .= wp_login_url() . "\r\n";
  53.  
  54. wp_mail( $user->user_email, sprintf( __( '[%s] Your username and password' ), $blogname ), $message );
  55.  
  56. }
  57. }
  58.  
  59. endif;
  60.  
  61. }
  62.  
  63. /**
  64. * Set User Values (including password) from Submit Form
  65. *
  66. * Available values that can be set are:
  67. * first_name, last_name, display_name, nickname, user_email, user_url, user_nicename, user_pass, description
  68. *
  69. * The key used inside the $_POST MUST be the exact meta key of the field you want to use for that value
  70. *
  71. * @param $new_user
  72. *
  73. * @return array
  74. */
  75. function smyles_allow_set_password_from_submit_form( $new_user ) {
  76.  
  77. // Password
  78. if( isset( $_POST['account_password'] ) ){
  79. $new_user['user_pass'] = $_POST['account_password'];
  80. }
  81. // First Name
  82. if( isset( $_POST['first_name'] ) ){
  83. $new_user['first_name'] = $_POST['first_name'];
  84. }
  85. // Last Name
  86. if( isset( $_POST['last_name'] ) ){
  87. $new_user['last_name'] = $_POST['last_name'];
  88. }
  89.  
  90. return $new_user;
  91.  
  92. }
  93.  
  94. // Change filter below to submit_resume_form_validate_fields if you're using this for Resume submit instead of Job
  95. add_filter( 'submit_job_form_validate_fields', 'smyles_check_user_passwords', 10, 3 );
  96.  
  97. /**
  98. * Verify that both password fields match
  99. *
  100. * This function verifies that both password fields match, and returns an error if they
  101. * do not. This assumes you created two password fields on the form, with the meta key of
  102. * account_password and account_password2
  103. *
  104. *
  105. *
  106. * @param $true
  107. * @param $fields
  108. * @param $values
  109. *
  110. * @return \WP_Error|boolean
  111. */
  112. function smyles_check_user_passwords( $true, $fields, $values ){
  113.  
  114. if( isset( $_POST['account_password'], $_POST['account_password2'] ) ){
  115.  
  116. if( $_POST['account_password'] !== $_POST['account_password2'] ){
  117. return new WP_Error( 'validation-error', __( 'Passwords do not match, please try again.' ) );
  118. }
  119.  
  120. }
  121.  
  122. return $true;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement