[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Activity: Spam action
   4   *
   5   * @package BuddyPress
   6   * @subpackage ActivityActions
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Mark specific activity item as spam and redirect to previous page.
  12   *
  13   * @since 1.6.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_spam_activity( $activity_id = 0 ) {
  19      $bp = buddypress();
  20  
  21      // Not viewing activity, or action is not spam, or Akismet isn't present.
  22      if ( !bp_is_activity_component() || !bp_is_current_action( 'spam' ) || empty( $bp->activity->akismet ) )
  23          return false;
  24  
  25      if ( empty( $activity_id ) && bp_action_variable( 0 ) )
  26          $activity_id = (int) bp_action_variable( 0 );
  27  
  28      // Not viewing a specific activity item.
  29      if ( empty( $activity_id ) )
  30          return false;
  31  
  32      // Is the current user allowed to spam items?
  33      if ( !bp_activity_user_can_mark_spam() )
  34          return false;
  35  
  36      // Load up the activity item.
  37      $activity = new BP_Activity_Activity( $activity_id );
  38      if ( empty( $activity->id ) )
  39          return false;
  40  
  41      // Check nonce.
  42      check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id );
  43  
  44      /**
  45       * Fires before the marking activity as spam so plugins can modify things if they want to.
  46       *
  47       * @since 1.6.0
  48       *
  49       * @param int    $activity_id Activity ID to be marked as spam.
  50       * @param object $activity    Activity object for the ID to be marked as spam.
  51       */
  52      do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity );
  53  
  54      // Mark as spam.
  55      bp_activity_mark_as_spam( $activity );
  56      $activity->save();
  57  
  58      // Tell the user the spamming has been successful.
  59      bp_core_add_message( __( 'The activity item has been marked as spam and is no longer visible.', 'buddypress' ) );
  60  
  61      /**
  62       * Fires after the marking activity as spam so plugins can act afterwards based on the activity.
  63       *
  64       * @since 1.6.0
  65       *
  66       * @param int $activity_id Activity ID that was marked as spam.
  67       * @param int $user_id     User ID associated with activity.
  68       */
  69      do_action( 'bp_activity_action_spam_activity', $activity_id, $activity->user_id );
  70  
  71      // Check for the redirect query arg, otherwise let WP handle things.
  72      if ( !empty( $_GET['redirect_to'] ) )
  73          bp_core_redirect( esc_url( $_GET['redirect_to'] ) );
  74      else
  75          bp_core_redirect( wp_get_referer() );
  76  }
  77  add_action( 'bp_actions', 'bp_activity_action_spam_activity' );


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1