[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-xprofile/screens/ -> settings-profile.php (source)

   1  <?php
   2  /**
   3   * XProfile: User's "Settings > Profile Visibility" screen handler
   4   *
   5   * @package BuddyPress
   6   * @subpackage XProfileScreens
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Show the xprofile settings template.
  12   *
  13   * @since 2.0.0
  14   */
  15  function bp_xprofile_screen_settings() {
  16  
  17      // Redirect if no privacy settings page is accessible.
  18      if ( bp_action_variables() || ! bp_is_active( 'xprofile' ) ) {
  19          bp_do_404();
  20          return;
  21      }
  22  
  23      /**
  24       * Filters the template to load for the XProfile settings screen.
  25       *
  26       * @since 2.0.0
  27       *
  28       * @param string $template Path to the XProfile change avatar template to load.
  29       */
  30      bp_core_load_template( apply_filters( 'bp_settings_screen_xprofile', '/members/single/settings/profile' ) );
  31  }
  32  
  33  /**
  34   * Handles the saving of xprofile field visibilities.
  35   *
  36   * @since 1.9.0
  37   */
  38  function bp_xprofile_action_settings() {
  39  
  40      // Bail if not a POST action.
  41      if ( ! bp_is_post_request() ) {
  42          return;
  43      }
  44  
  45      // Bail if no submit action.
  46      if ( ! isset( $_POST['xprofile-settings-submit'] ) ) {
  47          return;
  48      }
  49  
  50      // Bail if not in settings.
  51      if ( ! bp_is_user_settings_profile() ) {
  52          return;
  53      }
  54  
  55      // 404 if there are any additional action variables attached
  56      if ( bp_action_variables() ) {
  57          bp_do_404();
  58          return;
  59      }
  60  
  61      // Nonce check.
  62      check_admin_referer( 'bp_xprofile_settings' );
  63  
  64      /**
  65       * Fires before saving xprofile field visibilities.
  66       *
  67       * @since 2.0.0
  68       */
  69      do_action( 'bp_xprofile_settings_before_save' );
  70  
  71      /* Save ******************************************************************/
  72  
  73      // Only save if there are field ID's being posted.
  74      if ( ! empty( $_POST['field_ids'] ) ) {
  75  
  76          // Get the POST'ed field ID's.
  77          $posted_field_ids = explode( ',', $_POST['field_ids'] );
  78  
  79          // Backward compatibility: a bug in BP 2.0 caused only a single
  80          // group's field IDs to be submitted. Look for values submitted
  81          // in the POST request that may not appear in 'field_ids', and
  82          // add them to the list of IDs to save.
  83          foreach ( $_POST as $posted_key => $posted_value ) {
  84              preg_match( '/^field_([0-9]+)_visibility$/', $posted_key, $matches );
  85              if ( ! empty( $matches[1] ) && ! in_array( $matches[1], $posted_field_ids ) ) {
  86                  $posted_field_ids[] = $matches[1];
  87              }
  88          }
  89  
  90          // Save the visibility settings.
  91          foreach ( $posted_field_ids as $field_id ) {
  92  
  93              $visibility_level = 'public';
  94  
  95              if ( !empty( $_POST['field_' . $field_id . '_visibility'] ) ) {
  96                  $visibility_level = $_POST['field_' . $field_id . '_visibility'];
  97              }
  98  
  99              xprofile_set_field_visibility_level( $field_id, bp_displayed_user_id(), $visibility_level );
 100          }
 101      }
 102  
 103      /* Other *****************************************************************/
 104  
 105      /**
 106       * Fires after saving xprofile field visibilities.
 107       *
 108       * @since 2.0.0
 109       */
 110      do_action( 'bp_xprofile_settings_after_save' );
 111  
 112      // Redirect to the root domain.
 113      bp_core_redirect( bp_displayed_user_domain() . bp_get_settings_slug() . '/profile' );
 114  }
 115  add_action( 'bp_actions', 'bp_xprofile_action_settings' );


Generated: Wed Jul 24 01:01:43 2019 Cross-referenced by PHPXref 0.7.1