Advertisement
Guest User

Untitled

a guest
Mar 7th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. $post = array(
  2. 'post_title'=>$_POST['firstname'] . $_POST['lastname'],
  3. 'post_type'=>'registration',
  4. 'post_content'=>'',
  5. 'post_status' => 'publish',
  6. );
  7. $registration_id = wp_insert_post();
  8. update_post_meta($registration_id, 'email', $_POST['email']);
  9. //wp_publish_post($registration_id);
  10.  
  11. add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
  12. add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
  13.  
  14. function my_show_extra_profile_fields( $user ) { ?>
  15.  
  16. <h3>Extra profile information</h3>
  17.  
  18. <table class="form-table">
  19.  
  20. <tr>
  21. <th><label for="abn">ABN</label></th>
  22.  
  23. <td>
  24. <input type="text" name="abn" id="abn" value="<?php echo esc_attr( get_the_author_meta( 'abn', $user->ID ) ); ?>" class="regular-text" /><br />
  25. <span class="description">Please enter your abn num.</span>
  26. </td>
  27. </tr>
  28. <tr>
  29. <th><label for="abn">Business Name</label></th>
  30.  
  31. <td>
  32. <input type="text" name="BusinessName" id="BusinessName" value="<?php echo esc_attr( get_the_author_meta( 'BusinessName', $user->ID ) ); ?>" class="regular-text" /><br />
  33. <span class="description">Please enter your Business Name.</span>
  34. </td>
  35. </tr>
  36. <tr>
  37. <th><label for="abn">Business type</label></th>
  38.  
  39. <td>
  40. <input type="text" name="Businesstype" id="Businesstype" value="<?php echo esc_attr( get_the_author_meta( 'Businesstype', $user->ID ) ); ?>" class="regular-text" /><br />
  41. <span class="description">Please enter your Business type.</span>
  42. </td>
  43. </tr>
  44. </table>
  45. <?php }
  46.  
  47. add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
  48. add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
  49.  
  50. function my_save_extra_profile_fields( $user_id ) {
  51.  
  52. if ( !current_user_can( 'edit_user', $user_id ) )
  53. return false;
  54.  
  55. /* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
  56. update_usermeta( $user_id, 'abn', $_POST['abn'] );
  57. update_usermeta( $user_id, 'BusinessName', $_POST['BusinessName'] );
  58. update_usermeta( $user_id, 'Businesstype', $_POST['Businesstype'] );
  59. }
  60.  
  61. //add bulk action in registration post types
  62. add_filter('manage_edit-product_columns', 'my_extra_cake_columns');
  63. function my_extra_cake_columns($columns) {
  64. $columns['slices'] =__('Create User');
  65. return $columns;
  66. }
  67.  
  68.  
  69. add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
  70. add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
  71.  
  72. function my_save_extra_profile_fields( $user_id ) {
  73.  
  74. if ( !current_user_can( 'edit_user', $user_id ) )
  75. return false;
  76.  
  77. /* Copy and paste this line for additional fields. */
  78. update_usermeta( $user_id, 'abn', $_POST['abn'] );
  79. update_usermeta( $user_id, 'BusinessName', $_POST['BusinessName'] );
  80. update_usermeta( $user_id, 'Businesstype', $_POST['Businesstype'] );
  81. }
  82.  
  83. add_action( 'manage_product_posts_custom_column', 'my_cake_column_content', 10, 2 );
  84. function my_cake_column_content( $column_name, $post_id ) {
  85. if ( 'slices' != $column_name )
  86. return;
  87. echo '<a href="#">Add as user</a>';
  88. }
  89.  
  90. add_filter( 'manage_edit-product_sortable_columns', 'my_sortable_cake_column' );
  91. function my_sortable_cake_column( $columns ) {
  92. $columns['slices'] = 'slice';
  93. return $columns;
  94. }
  95.  
  96. //How to Create User
  97. $fname = get_post_meta($post_id,'firstname',true);
  98. $lname = get_post_meta($post_id,'lastname',true);
  99. $email_address = get_post_meta($post_id,'email',true);
  100. $password = rand(); //create random password
  101. $user_id = wp_create_user( $email_address, $password, $email_address );
  102. // Set the nickname
  103. wp_update_user(
  104. array(
  105. 'ID' => $user_id,
  106. 'nickname' => $email_address,
  107. 'first_name' => $fname,
  108. 'last_name' => $lname
  109. )
  110. );
  111.  
  112. // Set the role
  113. $user = new WP_User( $user_id );
  114.  
  115. //delete that post
  116. wp_delete_post( $post_id );
  117. // Email the user
  118. wp_mail( $email_address, 'Welcome!', 'Your Password: ' . $password );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement