[ Index ]

PHP Cross Reference of BBPress

title

Body

[close]

/src/includes/users/ -> signups.php (source)

   1  <?php
   2  
   3  /**
   4   * bbPress Signups
   5   *
   6   * This file contains functions for assisting with adding forum data to user
   7   * accounts during signup, account creation, and invitation.
   8   *
   9   * @package bbPress
  10   * @subpackage Signups
  11   */
  12  
  13  // Exit if accessed directly
  14  defined( 'ABSPATH' ) || exit;
  15  
  16  /**
  17   * Output the forum-role field when adding a new user
  18   *
  19   * @since 2.6.0 bbPress (r6674)
  20   */
  21  function bbp_add_user_form_role_field() {
  22  ?>
  23  
  24      <table class="form-table">
  25          <tr class="form-field">
  26              <th scope="row"><label for="bbp-forums-role"><?php esc_html_e( 'Forum Role', 'bbpress' ); ?></label></th>
  27              <td><?php
  28  
  29                  // Default user role
  30                  $default_role  = isset( $_POST['bbp-forums-role'] )
  31                      ? sanitize_key( $_POST['bbp-forums-role'] )
  32                      : bbp_get_default_role();
  33  
  34                  // Get the folum roles
  35                  $dynamic_roles = bbp_get_dynamic_roles();
  36  
  37                  // Only keymasters can set other keymasters
  38                  if ( ! bbp_is_user_keymaster() ) {
  39                      unset( $dynamic_roles[ bbp_get_keymaster_role() ] );
  40                  } ?>
  41  
  42                  <select name="bbp-forums-role" id="bbp-forums-role">
  43  
  44                      <?php foreach ( $dynamic_roles as $role => $details ) : ?>
  45  
  46                          <option <?php selected( $default_role, $role ); ?> value="<?php echo esc_attr( $role ); ?>"><?php echo bbp_translate_user_role( $details['name'] ); ?></option>
  47  
  48                      <?php endforeach; ?>
  49  
  50                  </select>
  51              </td>
  52          </tr>
  53      </table>
  54  
  55  <?php
  56  }
  57  
  58  /**
  59   * Maybe add forum role to signup meta array
  60   *
  61   * @since 2.6.0 bbPress (r6674)
  62   *
  63   * @param array $meta
  64   *
  65   * @return array
  66   */
  67  function bbp_user_add_role_to_signup_meta( $meta = array() ) {
  68  
  69      // Posted role
  70      $forum_role = isset( $_POST['bbp-forums-role'] )
  71          ? sanitize_key( $_POST['bbp-forums-role'] )
  72          : bbp_get_default_role();
  73  
  74      // Role keys
  75      $roles = array_keys( bbp_get_dynamic_roles() );
  76  
  77      // Bail if posted role is not in dynamic roles
  78      if ( empty( $forum_role ) || ! in_array( $forum_role, $roles, true ) ) {
  79          return $meta;
  80      }
  81  
  82      // Add role to meta
  83      $meta['bbp_new_role'] = $forum_role;
  84  
  85      // Return meta
  86      return $meta;
  87  }
  88  
  89  /**
  90   * Add forum meta data when inviting a user to a site
  91   *
  92   * @since 2.6.0 bbPress (r6674)
  93   *
  94   * @param int    $user_id     The invited user's ID.
  95   * @param array  $role        The role of invited user.
  96   * @param string $newuser_key The key of the invitation.
  97   */
  98  function bbp_user_add_role_on_invite( $user_id = '', $role = '', $newuser_key = '' ) {
  99  
 100      // Posted role
 101      $forum_role = isset( $_POST['bbp-forums-role'] )
 102          ? sanitize_key( $_POST['bbp-forums-role'] )
 103          : bbp_get_default_role();
 104  
 105      // Role keys
 106      $roles = array_keys( bbp_get_dynamic_roles() );
 107  
 108      // Bail if posted role is not in dynamic roles
 109      if ( empty( $forum_role ) || ! in_array( $forum_role, $roles, true ) ) {
 110          return;
 111      }
 112  
 113      // Option key
 114      $option_key = 'new_user_' . $newuser_key;
 115  
 116      // Get the user option
 117      $user_option = get_option( $option_key, array() );
 118  
 119      // Add the new role
 120      $user_option['bbp_new_role'] = $forum_role;
 121  
 122      // Update the invitation
 123      update_option( $option_key, $user_option );
 124  }
 125  
 126  /**
 127   * Single-site handler for adding a new user
 128   *
 129   * @since 2.6.0 bbPress (r6674)
 130   *
 131   * @param int $user_id
 132   */
 133  function bbp_user_add_role_on_register( $user_id = '' ) {
 134  
 135      // Posted role
 136      $forum_role = isset( $_POST['bbp-forums-role'] )
 137          ? sanitize_key( $_POST['bbp-forums-role'] )
 138          : bbp_get_default_role();
 139  
 140      // Role keys
 141      $roles = array_keys( bbp_get_dynamic_roles() );
 142  
 143      // Bail if posted role is not in dynamic roles
 144      if ( empty( $forum_role ) || ! in_array( $forum_role, $roles, true ) ) {
 145          return;
 146      }
 147  
 148      // Set the user role
 149      bbp_set_user_role( $user_id, $forum_role );
 150  }
 151  
 152  /**
 153   * Multi-site handler for adding a new user
 154   *
 155   * @since 2.6.0 bbPress (r6674)
 156   *
 157   * @param int $user_id User ID.
 158   */
 159  function bbp_user_add_role_on_activate( $user_id = 0, $password = '', $meta = array() ) {
 160  
 161      // Posted role
 162      $forum_role = isset( $meta['bbp_new_role'] )
 163          ? sanitize_key( $meta['bbp_new_role'] )
 164          : bbp_get_default_role();
 165  
 166      // Sanitize role
 167      $roles = array_keys( bbp_get_dynamic_roles() );
 168  
 169      // Bail if posted role is not in dynamic roles
 170      if ( empty( $forum_role ) || ! in_array( $forum_role, $roles, true ) ) {
 171          return;
 172      }
 173  
 174      // Set the user role
 175      bbp_set_user_role( $user_id, $forum_role );
 176  }


Generated: Sun Nov 17 01:01:25 2019 Cross-referenced by PHPXref 0.7.1