[ 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          if ( !bp_core_avatar_handle_crop( $args ) ) {
  78              bp_core_add_message( __( 'There was a problem cropping the group profile photo.', 'buddypress' ), 'error' );
  79          } else {
  80              /**
  81               * Fires after a group avatar is uploaded.
  82               *
  83               * @since 2.8.0
  84               *
  85               * @param int    $group_id ID of the group.
  86               * @param string $type     Avatar type. 'crop' or 'full'.
  87               * @param array  $args     Array of parameters passed to the avatar handler.
  88               */
  89              do_action( 'groups_avatar_uploaded', bp_get_current_group_id(), 'crop', $args );
  90              bp_core_add_message( __( 'The new group profile photo was uploaded successfully.', 'buddypress' ) );
  91          }
  92      }
  93  
  94      /**
  95       * Fires before the loading of the group Change Avatar page template.
  96       *
  97       * @since 1.0.0
  98       *
  99       * @param int $id ID of the group that is being displayed.
 100       */
 101      do_action( 'groups_screen_group_admin_avatar', $bp->groups->current_group->id );
 102  
 103      /**
 104       * Filters the template to load for a group's Change Avatar page.
 105       *
 106       * @since 1.0.0
 107       *
 108       * @param string $value Path to a group's Change Avatar template.
 109       */
 110      bp_core_load_template( apply_filters( 'groups_template_group_admin_avatar', 'groups/single/home' ) );
 111  }
 112  add_action( 'bp_screens', 'groups_screen_group_admin_avatar' );


Generated: Sun Dec 15 01:01:38 2019 Cross-referenced by PHPXref 0.7.1