Guest User

Multiple registration page buddypress

a guest
Aug 14th, 2017
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.78 KB | None | 0 0
  1. add_action( 'bp_screens', 'cps_employer_screen_signup' );
  2.  
  3.  
  4. function cps_employer_screen_signup() {
  5.     $bp = buddypress();
  6.  
  7.     // we changed the original code in the following two lines
  8.     if ( !is_page( 'employer-register' ) || bp_current_action() )
  9.        
  10.         return;
  11.  
  12.     // Not a directory.
  13.     bp_update_is_directory( false, 'register' );
  14.  
  15.     // If the user is logged in, redirect away from here.
  16.     if ( is_user_logged_in() ) {
  17.  
  18.         $redirect_to = bp_is_component_front_page( 'register' )
  19.             ? bp_get_members_directory_permalink()
  20.             : bp_get_root_domain();
  21.  
  22.         /**
  23.          * Filters the URL to redirect logged in users to when visiting registration page.
  24.          *
  25.          * @since 1.5.1
  26.          *
  27.          * @param string $redirect_to URL to redirect user to.
  28.          */
  29.         bp_core_redirect( apply_filters( 'bp_loggedin_register_page_redirect_to', $redirect_to ) );
  30.  
  31.         return;
  32.     }
  33.  
  34.     $bp->signup->step = 'request-details';
  35.  
  36.     if ( !bp_get_signup_allowed() ) {
  37.         $bp->signup->step = 'registration-disabled';
  38.  
  39.         // If the signup page is submitted, validate and save.
  40.     } elseif ( isset( $_POST['signup_submit'] ) && bp_verify_nonce_request( 'bp_new_signup' ) ) {
  41.  
  42.         /**
  43.          * Fires before the validation of a new signup.
  44.          *
  45.          * @since 2.0.0
  46.          */
  47.         do_action( 'bp_signup_pre_validate' );
  48.  
  49.         // Check the base account details for problems.
  50.         $account_details = bp_core_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );
  51.  
  52.         // If there are errors with account details, set them for display.
  53.         if ( !empty( $account_details['errors']->errors['user_name'] ) )
  54.             $bp->signup->errors['signup_username'] = $account_details['errors']->errors['user_name'][0];
  55.  
  56.         if ( !empty( $account_details['errors']->errors['user_email'] ) )
  57.             $bp->signup->errors['signup_email'] = $account_details['errors']->errors['user_email'][0];
  58.  
  59.         // Check that both password fields are filled in.
  60.         if ( empty( $_POST['signup_password'] ) || empty( $_POST['signup_password_confirm'] ) )
  61.             $bp->signup->errors['signup_password'] = __( 'Please make sure you enter your password twice', 'buddypress' );
  62.  
  63.         // Check that the passwords match.
  64.         if ( ( !empty( $_POST['signup_password'] ) && !empty( $_POST['signup_password_confirm'] ) ) && $_POST['signup_password'] != $_POST['signup_password_confirm'] )
  65.             $bp->signup->errors['signup_password'] = __( 'The passwords you entered do not match.', 'buddypress' );
  66.  
  67.         $bp->signup->username = $_POST['signup_username'];
  68.         $bp->signup->email = $_POST['signup_email'];
  69.  
  70.         // Now we've checked account details, we can check profile information.
  71.         if ( bp_is_active( 'xprofile' ) ) {
  72.  
  73.             // Make sure hidden field is passed and populated.
  74.             if ( isset( $_POST['signup_profile_field_ids'] ) && !empty( $_POST['signup_profile_field_ids'] ) ) {
  75.  
  76.                 // Let's compact any profile field info into an array.
  77.                 $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
  78.  
  79.                 // Loop through the posted fields formatting any datebox values then validate the field.
  80.                 foreach ( (array) $profile_field_ids as $field_id ) {
  81.                     bp_xprofile_maybe_format_datebox_post_data( $field_id );
  82.  
  83.                     // Create errors for required fields without values.
  84.                     if ( xprofile_check_is_required_field( $field_id ) && empty( $_POST[ 'field_' . $field_id ] ) && ! bp_current_user_can( 'bp_moderate' ) )
  85.                         $bp->signup->errors['field_' . $field_id] = __( 'This is a required field', 'buddypress' );
  86.                 }
  87.  
  88.                 // This situation doesn't naturally occur so bounce to website root.
  89.             } else {
  90.                 bp_core_redirect( bp_get_root_domain() );
  91.             }
  92.         }
  93.  
  94.         // Finally, let's check the blog details, if the user wants a blog and blog creation is enabled.
  95.         if ( isset( $_POST['signup_with_blog'] ) ) {
  96.             $active_signup = bp_core_get_root_option( 'registration' );
  97.  
  98.             if ( 'blog' == $active_signup || 'all' == $active_signup ) {
  99.                 $blog_details = bp_core_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );
  100.  
  101.                 // If there are errors with blog details, set them for display.
  102.                 if ( !empty( $blog_details['errors']->errors['blogname'] ) )
  103.                     $bp->signup->errors['signup_blog_url'] = $blog_details['errors']->errors['blogname'][0];
  104.  
  105.                 if ( !empty( $blog_details['errors']->errors['blog_title'] ) )
  106.                     $bp->signup->errors['signup_blog_title'] = $blog_details['errors']->errors['blog_title'][0];
  107.             }
  108.         }
  109.  
  110.         /**
  111.          * Fires after the validation of a new signup.
  112.          *
  113.          * @since 1.1.0
  114.          */
  115.         do_action( 'bp_signup_validate' );
  116.  
  117.         // Add any errors to the action for the field in the template for display.
  118.         if ( !empty( $bp->signup->errors ) ) {
  119.             foreach ( (array) $bp->signup->errors as $fieldname => $error_message ) {
  120.                 /*
  121.                  * The addslashes() and stripslashes() used to avoid create_function()
  122.                  * syntax errors when the $error_message contains quotes.
  123.                  */
  124.  
  125.                 /**
  126.                  * Filters the error message in the loop.
  127.                  *
  128.                  * @since 1.5.0
  129.                  *
  130.                  * @param string $value Error message wrapped in html.
  131.                  */
  132.                 add_action( 'bp_' . $fieldname . '_errors', create_function( '', 'echo apply_filters(\'bp_members_signup_error_message\', "<div class=\"error\">" . stripslashes( \'' . addslashes( $error_message ) . '\' ) . "</div>" );' ) );
  133.             }
  134.         } else {
  135.             $bp->signup->step = 'save-details';
  136.  
  137.             // No errors! Let's register those deets.
  138.             $active_signup = bp_core_get_root_option( 'registration' );
  139.  
  140.             if ( 'none' != $active_signup ) {
  141.  
  142.                 // Make sure the extended profiles module is enabled.
  143.                 if ( bp_is_active( 'xprofile' ) ) {
  144.                     // Let's compact any profile field info into usermeta.
  145.                     $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
  146.  
  147.                     /*
  148.                      * Loop through the posted fields, formatting any
  149.                      * datebox values, then add to usermeta.
  150.                      */
  151.                     foreach ( (array) $profile_field_ids as $field_id ) {
  152.                         bp_xprofile_maybe_format_datebox_post_data( $field_id );
  153.  
  154.                         if ( !empty( $_POST['field_' . $field_id] ) )
  155.                             $usermeta['field_' . $field_id] = $_POST['field_' . $field_id];
  156.  
  157.                         if ( !empty( $_POST['field_' . $field_id . '_visibility'] ) )
  158.                             $usermeta['field_' . $field_id . '_visibility'] = $_POST['field_' . $field_id . '_visibility'];
  159.                     }
  160.  
  161.                     // Store the profile field ID's in usermeta.
  162.                     $usermeta['profile_field_ids'] = $_POST['signup_profile_field_ids'];
  163.                 }
  164.  
  165.                 // Hash and store the password.
  166.                 $usermeta['password'] = wp_hash_password( $_POST['signup_password'] );
  167.  
  168.                 // If the user decided to create a blog, save those details to usermeta.
  169.                 if ( 'blog' == $active_signup || 'all' == $active_signup )
  170.                     $usermeta['public'] = ( isset( $_POST['signup_blog_privacy'] ) && 'public' == $_POST['signup_blog_privacy'] ) ? true : false;
  171.  
  172.                 /**
  173.                  * Filters the user meta used for signup.
  174.                  *
  175.                  * @since 1.1.0
  176.                  *
  177.                  * @param array $usermeta Array of user meta to add to signup.
  178.                  */
  179.                 $usermeta = apply_filters( 'bp_signup_usermeta', $usermeta );
  180.  
  181.                 // Finally, sign up the user and/or blog.
  182.                 if ( isset( $_POST['signup_with_blog'] ) && is_multisite() )
  183.                     $wp_user_id = bp_core_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
  184.                 else
  185.                     $wp_user_id = bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta );
  186.  
  187.                 if ( is_wp_error( $wp_user_id ) ) {
  188.                     $bp->signup->step = 'request-details';
  189.                     bp_core_add_message( $wp_user_id->get_error_message(), 'error' );
  190.                 } else {
  191.                     $bp->signup->step = 'completed-confirmation';
  192.                 }
  193.             }
  194.  
  195.             /**
  196.              * Fires after the completion of a new signup.
  197.              *
  198.              * @since 1.1.0
  199.              */
  200.             do_action( 'bp_complete_signup' );
  201.         }
  202.  
  203.     }
  204.  
  205.     /**
  206.      * Fires right before the loading of the Member registration screen template file.
  207.      *
  208.      * @since 1.5.0
  209.      */
  210.     do_action( 'bp_core_screen_signup' );
  211.  
  212.     /**
  213.      * Filters the template to load for the Member registration page screen.
  214.      *
  215.      * @since 1.5.0
  216.      *
  217.      * @param string $value Path to the Member registration template to load.
  218.      */
  219.  
  220.      //we don't need the following line. Remove it completely or comment it out.
  221.  
  222.      //bp_core_load_template( apply_filters( 'bp_core_template_register', array( 'register', 'registration/register' ) ) );
  223.  
  224.  
  225. }
Add Comment
Please, Sign In to add comment