[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Members: Change Avatar screen handler
   4   *
   5   * @package BuddyPress
   6   * @subpackage MembersScreens
   7   * @since 6.0.0
   8   */
   9  
  10  /**
  11   * Handle the display of the profile Change Avatar page by loading the correct template file.
  12   *
  13   * @since 6.0.0
  14   */
  15  function bp_members_screen_change_avatar() {
  16      // Bail if not the correct screen.
  17      if ( ! bp_is_my_profile() && ! bp_current_user_can( 'bp_moderate' ) ) {
  18          return false;
  19      }
  20  
  21      // Bail if there are action variables.
  22      if ( bp_action_variables() ) {
  23          bp_do_404();
  24          return;
  25      }
  26  
  27      $bp = buddypress();
  28  
  29      if ( ! isset( $bp->avatar_admin ) ) {
  30          $bp->avatar_admin = new stdClass();
  31      }
  32  
  33      $bp->avatar_admin->step = 'upload-image';
  34  
  35      if ( !empty( $_FILES ) ) {
  36  
  37          // Check the nonce.
  38          check_admin_referer( 'bp_avatar_upload' );
  39  
  40          // Pass the file to the avatar upload handler.
  41          if ( bp_core_avatar_handle_upload( $_FILES, 'bp_members_avatar_upload_dir' ) ) {
  42              $bp->avatar_admin->step = 'crop-image';
  43  
  44              // Make sure we include the jQuery jCrop file for image cropping.
  45              add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' );
  46          }
  47      }
  48  
  49      // If the image cropping is done, crop the image and save a full/thumb version.
  50      if ( isset( $_POST['avatar-crop-submit'] ) ) {
  51  
  52          // Check the nonce.
  53          check_admin_referer( 'bp_avatar_cropstore' );
  54  
  55          $args = array(
  56              'item_id'       => bp_displayed_user_id(),
  57              'original_file' => $_POST['image_src'],
  58              'crop_x'        => $_POST['x'],
  59              'crop_y'        => $_POST['y'],
  60              'crop_w'        => $_POST['w'],
  61              'crop_h'        => $_POST['h']
  62          );
  63  
  64          if ( ! bp_core_avatar_handle_crop( $args ) ) {
  65              bp_core_add_message( __( 'There was a problem cropping your profile photo.', 'buddypress' ), 'error' );
  66          } else {
  67  
  68              /** This action is documented in wp-includes/deprecated.php */
  69              do_action_deprecated( 'xprofile_avatar_uploaded', array( (int) $args['item_id'], 'crop' ), '6.0.0', 'bp_members_avatar_uploaded' );
  70  
  71              /**
  72               * Fires right before the redirect, after processing a new avatar.
  73               *
  74               * @since 6.0.0
  75               *
  76               * @param string $item_id Inform about the user id the avatar was set for.
  77               * @param string $value   Inform about the way the avatar was set ('crop').
  78               */
  79              do_action( 'bp_members_avatar_uploaded', (int) $args['item_id'], 'crop' );
  80  
  81              bp_core_add_message( __( 'Your new profile photo was uploaded successfully.', 'buddypress' ) );
  82              bp_core_redirect( bp_displayed_user_domain() );
  83          }
  84      }
  85  
  86      /** This action is documented in wp-includes/deprecated.php */
  87      do_action_deprecated( 'xprofile_screen_change_avatar', array(), '6.0.0', 'bp_members_screen_change_avatar' );
  88  
  89      /**
  90       * Fires right before the loading of the Member Change Avatar screen template file.
  91       *
  92       * @since 6.0.0
  93       */
  94      do_action( 'bp_members_screen_change_avatar' );
  95  
  96      /** This filter is documented in wp-includes/deprecated.php */
  97      $template = apply_filters_deprecated( 'xprofile_template_change_avatar', array( 'members/single/home' ), '6.0.0', 'bp_members_template_change_avatar' );
  98  
  99      /**
 100       * Filters the template to load for the Member Change Avatar page screen.
 101       *
 102       * @since 6.0.0
 103       *
 104       * @param string $template Path to the Member template to load.
 105       */
 106      bp_core_load_template( apply_filters( 'bp_members_template_change_avatar', $template ) );
 107  }


Generated: Wed Jul 15 01:01:38 2020 Cross-referenced by PHPXref 0.7.1