[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-activity/actions/ -> delete.php (source)

   1  <?php
   2  /**
   3   * Activity: Delete action
   4   *
   5   * @package BuddyPress
   6   * @subpackage ActivityActions
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Delete specific activity item and redirect to previous page.
  12   *
  13   * @since 1.1.0
  14   *
  15   * @param int $activity_id Activity id to be deleted. Defaults to 0.
  16   * @return bool False on failure.
  17   */
  18  function bp_activity_action_delete_activity( $activity_id = 0 ) {
  19      // Not viewing activity or action is not delete.
  20      if ( !bp_is_activity_component() || !bp_is_current_action( 'delete' ) )
  21          return false;
  22  
  23      if ( empty( $activity_id ) && bp_action_variable( 0 ) )
  24          $activity_id = (int) bp_action_variable( 0 );
  25  
  26      // Not viewing a specific activity item.
  27      if ( empty( $activity_id ) )
  28          return false;
  29  
  30      // Check the nonce.
  31      check_admin_referer( 'bp_activity_delete_link' );
  32  
  33      // Load up the activity item.
  34      $activity = new BP_Activity_Activity( $activity_id );
  35  
  36      // Check access.
  37      if ( ! bp_activity_user_can_delete( $activity ) )
  38          return false;
  39  
  40      /**
  41       * Fires before the deletion so plugins can still fetch information about it.
  42       *
  43       * @since 1.5.0
  44       *
  45       * @param int $activity_id The activity ID.
  46       * @param int $user_id     The user associated with the activity.
  47       */
  48      do_action( 'bp_activity_before_action_delete_activity', $activity_id, $activity->user_id );
  49  
  50      // Delete the activity item and provide user feedback.
  51      if ( bp_activity_delete( array( 'id' => $activity_id, 'user_id' => $activity->user_id ) ) )
  52          bp_core_add_message( __( 'Activity deleted successfully', 'buddypress' ) );
  53      else
  54          bp_core_add_message( __( 'There was an error when deleting that activity', 'buddypress' ), 'error' );
  55  
  56      /**
  57       * Fires after the deletion so plugins can act afterwards based on the activity.
  58       *
  59       * @since 1.1.0
  60       *
  61       * @param int $activity_id The activity ID.
  62       * @param int $user_id     The user associated with the activity.
  63       */
  64      do_action( 'bp_activity_action_delete_activity', $activity_id, $activity->user_id );
  65  
  66      // Check for the redirect query arg, otherwise let WP handle things.
  67      if ( !empty( $_GET['redirect_to'] ) )
  68          bp_core_redirect( esc_url( $_GET['redirect_to'] ) );
  69      else
  70          bp_core_redirect( wp_get_referer() );
  71  }
  72  add_action( 'bp_actions', 'bp_activity_action_delete_activity' );


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