[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-members/ -> bp-members-screens.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Member Screens.
   4   *
   5   * Handlers for member screens that aren't handled elsewhere.
   6   *
   7   * @package BuddyPress
   8   * @subpackage MembersScreens
   9   * @since 1.5.0
  10   */
  11  
  12  // Exit if accessed directly.
  13  defined( 'ABSPATH' ) || exit;
  14  
  15  /**
  16   * Handle the display of the profile page by loading the correct template file.
  17   *
  18   * @since 1.5.0
  19   */
  20  function bp_members_screen_display_profile() {
  21  
  22      /**
  23       * Fires right before the loading of the Member profile screen template file.
  24       *
  25       * @since 1.5.0
  26       */
  27      do_action( 'bp_members_screen_display_profile' );
  28  
  29      /**
  30       * Filters the template to load for the Member profile page screen.
  31       *
  32       * @since 1.5.0
  33       *
  34       * @param string $template Path to the Member template to load.
  35       */
  36      bp_core_load_template( apply_filters( 'bp_members_screen_display_profile', 'members/single/home' ) );
  37  }
  38  
  39  /**
  40   * Handle the display of the members directory index.
  41   *
  42   * @since 1.5.0
  43   */
  44  function bp_members_screen_index() {
  45      if ( bp_is_members_directory() ) {
  46          bp_update_is_directory( true, 'members' );
  47  
  48          /**
  49           * Fires right before the loading of the Member directory index screen template file.
  50           *
  51           * @since 1.5.0
  52           */
  53          do_action( 'bp_members_screen_index' );
  54  
  55          /**
  56           * Filters the template to load for the Member directory page screen.
  57           *
  58           * @since 1.5.0
  59           *
  60           * @param string $value Path to the member directory template to load.
  61           */
  62          bp_core_load_template( apply_filters( 'bp_members_screen_index', 'members/index' ) );
  63      }
  64  }
  65  add_action( 'bp_screens', 'bp_members_screen_index' );
  66  
  67  /**
  68   * Handle the loading of the signup screen.
  69   *
  70   * @since 1.1.0
  71   */
  72  function bp_core_screen_signup() {
  73      $bp = buddypress();
  74  
  75      if ( ! bp_is_current_component( 'register' ) || bp_current_action() )
  76          return;
  77  
  78      // Not a directory.
  79      bp_update_is_directory( false, 'register' );
  80  
  81      // If the user is logged in, redirect away from here.
  82      if ( is_user_logged_in() ) {
  83  
  84          $redirect_to = bp_is_component_front_page( 'register' )
  85              ? bp_get_members_directory_permalink()
  86              : bp_get_root_domain();
  87  
  88          /**
  89           * Filters the URL to redirect logged in users to when visiting registration page.
  90           *
  91           * @since 1.5.1
  92           *
  93           * @param string $redirect_to URL to redirect user to.
  94           */
  95          bp_core_redirect( apply_filters( 'bp_loggedin_register_page_redirect_to', $redirect_to ) );
  96  
  97          return;
  98      }
  99  
 100      $bp->signup->step = 'request-details';
 101  
 102      if ( !bp_get_signup_allowed() ) {
 103          $bp->signup->step = 'registration-disabled';
 104  
 105          // If the signup page is submitted, validate and save.
 106      } elseif ( isset( $_POST['signup_submit'] ) && bp_verify_nonce_request( 'bp_new_signup' ) ) {
 107  
 108          /**
 109           * Fires before the validation of a new signup.
 110           *
 111           * @since 2.0.0
 112           */
 113          do_action( 'bp_signup_pre_validate' );
 114  
 115          // Check the base account details for problems.
 116          $account_details = bp_core_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );
 117  
 118          // If there are errors with account details, set them for display.
 119          if ( !empty( $account_details['errors']->errors['user_name'] ) )
 120              $bp->signup->errors['signup_username'] = $account_details['errors']->errors['user_name'][0];
 121  
 122          if ( !empty( $account_details['errors']->errors['user_email'] ) )
 123              $bp->signup->errors['signup_email'] = $account_details['errors']->errors['user_email'][0];
 124  
 125          // Check that both password fields are filled in.
 126          if ( empty( $_POST['signup_password'] ) || empty( $_POST['signup_password_confirm'] ) )
 127              $bp->signup->errors['signup_password'] = __( 'Please make sure you enter your password twice', 'buddypress' );
 128  
 129          // Check that the passwords match.
 130          if ( ( !empty( $_POST['signup_password'] ) && !empty( $_POST['signup_password_confirm'] ) ) && $_POST['signup_password'] != $_POST['signup_password_confirm'] )
 131              $bp->signup->errors['signup_password'] = __( 'The passwords you entered do not match.', 'buddypress' );
 132  
 133          $bp->signup->username = $_POST['signup_username'];
 134          $bp->signup->email = $_POST['signup_email'];
 135  
 136          // Now we've checked account details, we can check profile information.
 137          if ( bp_is_active( 'xprofile' ) ) {
 138  
 139              // Make sure hidden field is passed and populated.
 140              if ( isset( $_POST['signup_profile_field_ids'] ) && !empty( $_POST['signup_profile_field_ids'] ) ) {
 141  
 142                  // Let's compact any profile field info into an array.
 143                  $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
 144  
 145                  // Loop through the posted fields formatting any datebox values then validate the field.
 146                  foreach ( (array) $profile_field_ids as $field_id ) {
 147                      bp_xprofile_maybe_format_datebox_post_data( $field_id );
 148  
 149                      if ( isset( $_POST[ 'field_' . $field_id ] ) ) {
 150                          $_POST[ 'field_' . $field_id ] = trim( $_POST[ 'field_' . $field_id ] );
 151                      }
 152  
 153                      // Create errors for required fields without values.
 154                      if ( xprofile_check_is_required_field( $field_id ) && empty( $_POST[ 'field_' . $field_id ] ) && ! bp_current_user_can( 'bp_moderate' ) )
 155                          $bp->signup->errors['field_' . $field_id] = __( 'This is a required field', 'buddypress' );
 156                  }
 157  
 158                  // This situation doesn't naturally occur so bounce to website root.
 159              } else {
 160                  bp_core_redirect( bp_get_root_domain() );
 161              }
 162          }
 163  
 164          // Finally, let's check the blog details, if the user wants a blog and blog creation is enabled.
 165          if ( isset( $_POST['signup_with_blog'] ) ) {
 166              $active_signup = bp_core_get_root_option( 'registration' );
 167  
 168              if ( 'blog' == $active_signup || 'all' == $active_signup ) {
 169                  $blog_details = bp_core_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );
 170  
 171                  // If there are errors with blog details, set them for display.
 172                  if ( !empty( $blog_details['errors']->errors['blogname'] ) )
 173                      $bp->signup->errors['signup_blog_url'] = $blog_details['errors']->errors['blogname'][0];
 174  
 175                  if ( !empty( $blog_details['errors']->errors['blog_title'] ) )
 176                      $bp->signup->errors['signup_blog_title'] = $blog_details['errors']->errors['blog_title'][0];
 177              }
 178          }
 179  
 180          /**
 181           * Fires after the validation of a new signup.
 182           *
 183           * @since 1.1.0
 184           */
 185          do_action( 'bp_signup_validate' );
 186  
 187          // Add any errors to the action for the field in the template for display.
 188          if ( !empty( $bp->signup->errors ) ) {
 189              foreach ( (array) $bp->signup->errors as $fieldname => $error_message ) {
 190                  /**
 191                   * Filters the error message in the loop.
 192                   *
 193                   * @since 1.5.0
 194                   *
 195                   * @param string $value Error message wrapped in html.
 196                   */
 197                  add_action( 'bp_' . $fieldname . '_errors', function() use ( $error_message ) {
 198                      echo apply_filters( 'bp_members_signup_error_message', "<div class=\"error\">" . $error_message . "</div>" );
 199                  } );
 200              }
 201          } else {
 202              $bp->signup->step = 'save-details';
 203  
 204              // No errors! Let's register those deets.
 205              $active_signup = bp_core_get_root_option( 'registration' );
 206  
 207              if ( 'none' != $active_signup ) {
 208  
 209                  // Make sure the extended profiles module is enabled.
 210                  if ( bp_is_active( 'xprofile' ) ) {
 211                      // Let's compact any profile field info into usermeta.
 212                      $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
 213  
 214                      /*
 215                       * Loop through the posted fields, formatting any
 216                       * datebox values, then add to usermeta.
 217                       */
 218                      foreach ( (array) $profile_field_ids as $field_id ) {
 219                          bp_xprofile_maybe_format_datebox_post_data( $field_id );
 220  
 221                          if ( !empty( $_POST['field_' . $field_id] ) )
 222                              $usermeta['field_' . $field_id] = $_POST['field_' . $field_id];
 223  
 224                          if ( !empty( $_POST['field_' . $field_id . '_visibility'] ) )
 225                              $usermeta['field_' . $field_id . '_visibility'] = $_POST['field_' . $field_id . '_visibility'];
 226                      }
 227  
 228                      // Store the profile field ID's in usermeta.
 229                      $usermeta['profile_field_ids'] = $_POST['signup_profile_field_ids'];
 230                  }
 231  
 232                  // Hash and store the password.
 233                  $usermeta['password'] = wp_hash_password( $_POST['signup_password'] );
 234  
 235                  // If the user decided to create a blog, save those details to usermeta.
 236                  if ( 'blog' == $active_signup || 'all' == $active_signup )
 237                      $usermeta['public'] = ( isset( $_POST['signup_blog_privacy'] ) && 'public' == $_POST['signup_blog_privacy'] ) ? true : false;
 238  
 239                  /**
 240                   * Filters the user meta used for signup.
 241                   *
 242                   * @since 1.1.0
 243                   *
 244                   * @param array $usermeta Array of user meta to add to signup.
 245                   */
 246                  $usermeta = apply_filters( 'bp_signup_usermeta', $usermeta );
 247  
 248                  // Finally, sign up the user and/or blog.
 249                  if ( isset( $_POST['signup_with_blog'] ) && is_multisite() )
 250                      $wp_user_id = bp_core_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
 251                  else
 252                      $wp_user_id = bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta );
 253  
 254                  if ( is_wp_error( $wp_user_id ) ) {
 255                      $bp->signup->step = 'request-details';
 256                      bp_core_add_message( $wp_user_id->get_error_message(), 'error' );
 257                  } else {
 258                      $bp->signup->step = 'completed-confirmation';
 259                  }
 260              }
 261  
 262              /**
 263               * Fires after the completion of a new signup.
 264               *
 265               * @since 1.1.0
 266               */
 267              do_action( 'bp_complete_signup' );
 268          }
 269  
 270      }
 271  
 272      /**
 273       * Fires right before the loading of the Member registration screen template file.
 274       *
 275       * @since 1.5.0
 276       */
 277      do_action( 'bp_core_screen_signup' );
 278  
 279      /**
 280       * Filters the template to load for the Member registration page screen.
 281       *
 282       * @since 1.5.0
 283       *
 284       * @param string $value Path to the Member registration template to load.
 285       */
 286      bp_core_load_template( apply_filters( 'bp_core_template_register', array( 'register', 'registration/register' ) ) );
 287  }
 288  add_action( 'bp_screens', 'bp_core_screen_signup' );
 289  
 290  /**
 291   * Handle the loading of the Activate screen.
 292   *
 293   * @since 1.1.0
 294   */
 295  function bp_core_screen_activation() {
 296  
 297      // Bail if not viewing the activation page.
 298      if ( ! bp_is_current_component( 'activate' ) ) {
 299          return false;
 300      }
 301  
 302      // If the user is already logged in, redirect away from here.
 303      if ( is_user_logged_in() ) {
 304  
 305          // If activation page is also front page, set to members directory to
 306          // avoid an infinite loop. Otherwise, set to root domain.
 307          $redirect_to = bp_is_component_front_page( 'activate' )
 308              ? bp_get_members_directory_permalink()
 309              : bp_get_root_domain();
 310  
 311          // Trailing slash it, as we expect these URL's to be.
 312          $redirect_to = trailingslashit( $redirect_to );
 313  
 314          /**
 315           * Filters the URL to redirect logged in users to when visiting activation page.
 316           *
 317           * @since 1.9.0
 318           *
 319           * @param string $redirect_to URL to redirect user to.
 320           */
 321          $redirect_to = apply_filters( 'bp_loggedin_activate_page_redirect_to', $redirect_to );
 322  
 323          // Redirect away from the activation page.
 324          bp_core_redirect( $redirect_to );
 325      }
 326  
 327      // Get BuddyPress.
 328      $bp = buddypress();
 329  
 330      /**
 331       * Filters the template to load for the Member activation page screen.
 332       *
 333       * @since 1.1.1
 334       *
 335       * @param string $value Path to the Member activation template to load.
 336       */
 337      bp_core_load_template( apply_filters( 'bp_core_template_activate', array( 'activate', 'registration/activate' ) ) );
 338  }
 339  add_action( 'bp_screens', 'bp_core_screen_activation' );
 340  
 341  /** Theme Compatibility *******************************************************/
 342  
 343  new BP_Members_Theme_Compat();
 344  new BP_Registration_Theme_Compat();


Generated: Mon Apr 2 01:00:57 2018 Cross-referenced by PHPXref 0.7.1