[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * XProfile: User's "Profile > Change Avatar" screen handler
   4   *
   5   * @package BuddyPress
   6   * @subpackage XProfileScreens
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Handles the uploading and cropping of a user avatar. Displays the change avatar page.
  12   *
  13   * @since 1.0.0
  14   *
  15   */
  16  function xprofile_screen_change_avatar() {
  17  
  18      // Bail if not the correct screen.
  19      if ( ! bp_is_my_profile() && ! bp_current_user_can( 'bp_moderate' ) ) {
  20          return false;
  21      }
  22  
  23      // Bail if there are action variables.
  24      if ( bp_action_variables() ) {
  25          bp_do_404();
  26          return;
  27      }
  28  
  29      $bp = buddypress();
  30  
  31      if ( ! isset( $bp->avatar_admin ) ) {
  32          $bp->avatar_admin = new stdClass();
  33      }
  34  
  35      $bp->avatar_admin->step = 'upload-image';
  36  
  37      if ( !empty( $_FILES ) ) {
  38  
  39          // Check the nonce.
  40          check_admin_referer( 'bp_avatar_upload' );
  41  
  42          // Pass the file to the avatar upload handler.
  43          if ( bp_core_avatar_handle_upload( $_FILES, 'xprofile_avatar_upload_dir' ) ) {
  44              $bp->avatar_admin->step = 'crop-image';
  45  
  46              // Make sure we include the jQuery jCrop file for image cropping.
  47              add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' );
  48          }
  49      }
  50  
  51      // If the image cropping is done, crop the image and save a full/thumb version.
  52      if ( isset( $_POST['avatar-crop-submit'] ) ) {
  53  
  54          // Check the nonce.
  55          check_admin_referer( 'bp_avatar_cropstore' );
  56  
  57          $args = array(
  58              'item_id'       => bp_displayed_user_id(),
  59              'original_file' => $_POST['image_src'],
  60              'crop_x'        => $_POST['x'],
  61              'crop_y'        => $_POST['y'],
  62              'crop_w'        => $_POST['w'],
  63              'crop_h'        => $_POST['h']
  64          );
  65  
  66          if ( ! bp_core_avatar_handle_crop( $args ) ) {
  67              bp_core_add_message( __( 'There was a problem cropping your profile photo.', 'buddypress' ), 'error' );
  68          } else {
  69  
  70              /**
  71               * Fires right before the redirect, after processing a new avatar.
  72               *
  73               * @since 1.1.0
  74               * @since 2.3.4 Add two new parameters to inform about the user id and
  75               *              about the way the avatar was set (eg: 'crop' or 'camera').
  76               *
  77               * @param string $item_id Inform about the user id the avatar was set for.
  78               * @param string $value   Inform about the way the avatar was set ('crop').
  79               */
  80              do_action( 'xprofile_avatar_uploaded', (int) $args['item_id'], 'crop' );
  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      /**
  87       * Fires right before the loading of the XProfile change avatar screen template file.
  88       *
  89       * @since 1.0.0
  90       */
  91      do_action( 'xprofile_screen_change_avatar' );
  92  
  93      /**
  94       * Filters the template to load for the XProfile change avatar screen.
  95       *
  96       * @since 1.0.0
  97       *
  98       * @param string $template Path to the XProfile change avatar template to load.
  99       */
 100      bp_core_load_template( apply_filters( 'xprofile_template_change_avatar', 'members/single/home' ) );
 101  }


Generated: Wed Jul 17 01:01:40 2019 Cross-referenced by PHPXref 0.7.1