[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * BuddyPress Members Filters.
   4   *
   5   * Filters specific to the Members component.
   6   *
   7   * @package BuddyPress
   8   * @subpackage MembersFilters
   9   * @since 1.5.0
  10   */
  11  
  12  // Exit if accessed directly.
  13  defined( 'ABSPATH' ) || exit;
  14  
  15  /**
  16   * Escape commonly used fullname output functions.
  17   */
  18  add_filter( 'bp_displayed_user_fullname',    'esc_html' );
  19  add_filter( 'bp_get_loggedin_user_fullname', 'esc_html' );
  20  
  21  // Filter the user registration URL to point to BuddyPress's registration page.
  22  add_filter( 'register_url', 'bp_get_signup_page' );
  23  
  24  /**
  25   * Load additional sign-up sanitization filters on bp_loaded.
  26   *
  27   * These are used to prevent XSS in the BuddyPress sign-up process. You can
  28   * unhook these to allow for customization of your registration fields;
  29   * however, it is highly recommended that you leave these in place for the
  30   * safety of your network.
  31   *
  32   * @since 1.5.0
  33   */
  34  function bp_members_signup_sanitization() {
  35  
  36      // Filters on sign-up fields.
  37      $fields = array (
  38          'bp_get_signup_username_value',
  39          'bp_get_signup_email_value',
  40          'bp_get_signup_with_blog_value',
  41          'bp_get_signup_blog_url_value',
  42          'bp_get_signup_blog_title_value',
  43          'bp_get_signup_blog_privacy_value',
  44          'bp_get_signup_avatar_dir_value',
  45      );
  46  
  47      // Add the filters to each field.
  48      foreach( $fields as $filter ) {
  49          add_filter( $filter, 'esc_html',       1 );
  50          add_filter( $filter, 'wp_filter_kses', 2 );
  51          add_filter( $filter, 'stripslashes',   3 );
  52      }
  53  
  54      // Sanitize email.
  55      add_filter( 'bp_get_signup_email_value', 'sanitize_email' );
  56  }
  57  add_action( 'bp_loaded', 'bp_members_signup_sanitization' );
  58  
  59  /**
  60   * Make sure the username is not the blog slug in case of root profile & subdirectory blog.
  61   *
  62   * If BP_ENABLE_ROOT_PROFILES is defined & multisite config is set to subdirectories,
  63   * then there is a chance site.url/username == site.url/blogslug. If so, user's profile
  64   * is not reachable, instead the blog is displayed. This filter makes sure the signup username
  65   * is not the same than the blog slug for this particular config.
  66   *
  67   * @since 2.1.0
  68   *
  69   * @param array $illegal_names Array of illiegal names.
  70   * @return array $illegal_names
  71   */
  72  function bp_members_signup_with_subdirectory_blog( $illegal_names = array() ) {
  73      if ( ! bp_core_enable_root_profiles() ) {
  74          return $illegal_names;
  75      }
  76  
  77      if ( is_network_admin() && isset( $_POST['blog'] ) ) {
  78          $blog = $_POST['blog'];
  79          $domain = '';
  80  
  81          if ( preg_match( '|^([a-zA-Z0-9-])$|', $blog['domain'] ) ) {
  82              $domain = strtolower( $blog['domain'] );
  83          }
  84  
  85          if ( username_exists( $domain ) ) {
  86              $illegal_names[] = $domain;
  87          }
  88  
  89      } else {
  90          $illegal_names[] = buddypress()->signup->username;
  91      }
  92  
  93      return $illegal_names;
  94  }
  95  add_filter( 'subdirectory_reserved_names', 'bp_members_signup_with_subdirectory_blog', 10, 1 );
  96  
  97  /**
  98   * Filter the user profile URL to point to BuddyPress profile edit.
  99   *
 100   * @since 1.6.0
 101   *
 102   * @param string $url     WP profile edit URL.
 103   * @param int    $user_id ID of the user.
 104   * @param string $scheme  Scheme to use.
 105   * @return string
 106   */
 107  function bp_members_edit_profile_url( $url, $user_id, $scheme = 'admin' ) {
 108  
 109      // If xprofile is active, use profile domain link.
 110      if ( ! is_admin() && bp_is_active( 'xprofile' ) ) {
 111          $profile_link = trailingslashit( bp_core_get_user_domain( $user_id ) . bp_get_profile_slug() . '/edit' );
 112  
 113      } else {
 114          // Default to $url.
 115          $profile_link = $url;
 116      }
 117  
 118      /**
 119       * Filters the user profile URL to point to BuddyPress profile edit.
 120       *
 121       * @since 1.5.2
 122       *
 123       * @param string $url WP profile edit URL.
 124       * @param int    $user_id ID of the user.
 125       * @param string $scheme Scheme to use.
 126       */
 127      return apply_filters( 'bp_members_edit_profile_url', $profile_link, $url, $user_id, $scheme );
 128  }
 129  add_filter( 'edit_profile_url', 'bp_members_edit_profile_url', 10, 3 );


Generated: Mon Jul 22 01:01:43 2019 Cross-referenced by PHPXref 0.7.1