[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-groups/screens/single/admin/ -> group-avatar.php (source)

   1  <?php
   2  /**
   3   * Groups: Single group "Manage > Photo" screen handler
   4   *
   5   * @package BuddyPress
   6   * @subpackage GroupsScreens
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Handle the display of a group's Change Avatar page.
  12   *
  13   * @since 1.0.0
  14   */
  15  function groups_screen_group_admin_avatar() {
  16  
  17      if ( 'group-avatar' != bp_get_group_current_admin_tab() )
  18          return false;
  19  
  20      // If the logged-in user doesn't have permission or if avatar uploads are disabled, then stop here.
  21      if ( ! bp_is_item_admin() || bp_disable_group_avatar_uploads() || ! buddypress()->avatar->show_avatars )
  22          return false;
  23  
  24      $bp = buddypress();
  25  
  26      // If the group admin has deleted the admin avatar.
  27      if ( bp_is_action_variable( 'delete', 1 ) ) {
  28  
  29          // Check the nonce.
  30          check_admin_referer( 'bp_group_avatar_delete' );
  31  
  32          if ( bp_core_delete_existing_avatar( array( 'item_id' => $bp->groups->current_group->id, 'object' => 'group' ) ) ) {
  33              bp_core_add_message( __( 'The group profile photo was deleted successfully!', 'buddypress' ) );
  34          } else {
  35              bp_core_add_message( __( 'There was a problem deleting the group profile photo. Please try again.', 'buddypress' ), 'error' );
  36          }
  37      }
  38  
  39      if ( ! isset( $bp->avatar_admin ) ) {
  40          $bp->avatar_admin = new stdClass();
  41      }
  42  
  43      $bp->avatar_admin->step = 'upload-image';
  44  
  45      if ( !empty( $_FILES ) ) {
  46  
  47          // Check the nonce.
  48          check_admin_referer( 'bp_avatar_upload' );
  49  
  50          // Pass the file to the avatar upload handler.
  51          if ( bp_core_avatar_handle_upload( $_FILES, 'groups_avatar_upload_dir' ) ) {
  52              $bp->avatar_admin->step = 'crop-image';
  53  
  54              // Make sure we include the jQuery jCrop file for image cropping.
  55              add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' );
  56          }
  57  
  58      }
  59  
  60      // If the image cropping is done, crop the image and save a full/thumb version.
  61      if ( isset( $_POST['avatar-crop-submit'] ) ) {
  62  
  63          // Check the nonce.
  64          check_admin_referer( 'bp_avatar_cropstore' );
  65  
  66          $args = array(
  67              'object'        => 'group',
  68              'avatar_dir'    => 'group-avatars',
  69              'item_id'       => $bp->groups->current_group->id,
  70              'original_file' => $_POST['image_src'],
  71              'crop_x'        => $_POST['x'],
  72              'crop_y'        => $_POST['y'],
  73              'crop_w'        => $_POST['w'],
  74              'crop_h'        => $_POST['h']
  75          );
  76  
  77          $cropped_avatar = bp_core_avatar_handle_crop( $args, 'array' );
  78  
  79          if ( ! $cropped_avatar ) {
  80              bp_core_add_message( __( 'There was a problem cropping the group profile photo.', 'buddypress' ), 'error' );
  81          } else {
  82              /**
  83               * Fires after a group avatar is uploaded.
  84               *
  85               * @since 2.8.0
  86               * @since 10.0.0 Adds a new param: an array containing the full, thumb avatar and the timestamp.
  87               *
  88               * @param int    $group_id       ID of the group.
  89               * @param string $type           Avatar type. 'crop' or 'camera'.
  90               * @param array  $args           Array of parameters passed to the avatar handler.
  91               * @param array  $cropped_avatar Array containing the full, thumb avatar and the timestamp.
  92               */
  93              do_action( 'groups_avatar_uploaded', bp_get_current_group_id(), 'crop', $args, $cropped_avatar );
  94              bp_core_add_message( __( 'The new group profile photo was uploaded successfully.', 'buddypress' ) );
  95          }
  96      }
  97  
  98      /**
  99       * Fires before the loading of the group Change Avatar page template.
 100       *
 101       * @since 1.0.0
 102       *
 103       * @param int $id ID of the group that is being displayed.
 104       */
 105      do_action( 'groups_screen_group_admin_avatar', $bp->groups->current_group->id );
 106  
 107      /**
 108       * Filters the template to load for a group's Change Avatar page.
 109       *
 110       * @since 1.0.0
 111       *
 112       * @param string $value Path to a group's Change Avatar template.
 113       */
 114      bp_core_load_template( apply_filters( 'groups_template_group_admin_avatar', 'groups/single/home' ) );
 115  }
 116  add_action( 'bp_screens', 'groups_screen_group_admin_avatar' );


Generated: Thu Nov 21 01:00:57 2024 Cross-referenced by PHPXref 0.7.1