Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/24/2011 02:00:04 PM (15 years ago)
Author:
djpaul
Message:

First pass of Akismet support for the Activity component. See #3660

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-actions.php

    r5253 r5259  
    171171}
    172172add_action( 'bp_actions', 'bp_activity_action_delete_activity' );
     173
     174/**
     175 * Mark specific activity item as spam and redirect to previous page
     176 *
     177 * @global object $bp BuddyPress global settings
     178 * @param int $activity_id Activity id to be deleted. Defaults to 0.
     179 * @return bool False on failure
     180 * @since 1.6
     181 */
     182function bp_activity_action_spam_activity( $activity_id = 0 ) {
     183        global $bp;
     184
     185        // Not viewing activity, or action is not spam, or Akismet isn't present
     186        if ( !bp_is_activity_component() || !bp_is_current_action( 'spam' ) || empty( $bp->activity->akismet ) )
     187                return false;
     188
     189        if ( empty( $activity_id ) && bp_action_variable( 0 ) )
     190                $activity_id = (int) bp_action_variable( 0 );
     191
     192        // Not viewing a specific activity item
     193        if ( empty( $activity_id ) )
     194                return false;
     195
     196        // Is the current user allowed to spam items?
     197        if ( !BP_Akismet::user_can_mark_spam() )
     198                return false;
     199
     200        // Load up the activity item
     201        $activity = new BP_Activity_Activity( $activity_id );
     202        if ( empty( $activity->id ) )
     203                return false;
     204
     205        // Check nonce
     206        check_admin_referer( 'bp_activity_akismet_spam_' . $activity->id );
     207
     208        // Call an action before the spamming so plugins can modify things if they want to
     209        do_action( 'bp_activity_before_action_spam_activity', $activity->id, $activity );
     210
     211        // Mark as spam
     212        $bp->activity->akismet->mark_as_spam( $activity );
     213        $activity->save();
     214
     215        // Tell the user the spamming has been succesful
     216        bp_core_add_message( __( 'The activity item has been marked as spam and is no longer visible.', 'buddypress' ) );
     217
     218        do_action( 'bp_activity_action_spam_activity', $activity_id, $activity->user_id );
     219
     220        // Check for the redirect query arg, otherwise let WP handle things
     221        if ( !empty( $_GET['redirect_to'] ) )
     222                bp_core_redirect( esc_url( $_GET['redirect_to'] ) );
     223        else
     224                bp_core_redirect( wp_get_referer() );
     225}
     226add_action( 'bp_actions', 'bp_activity_action_spam_activity' );
    173227
    174228/**
     
    535589add_action( 'bp_actions', 'bp_activity_action_favorites_feed' );
    536590
     591
     592/**
     593 * Loads Akismet
     594 *
     595 * @global object $bp BuddyPress global settings
     596 * @since 1.6
     597 */
     598function bp_activity_setup_akismet() {
     599        global $bp;
     600
     601        $akismet_key = bp_get_option( 'wordpress_api_key' );
     602
     603        // Load Akismet support if Akismet is configured
     604        if ( !defined( 'AKISMET_VERSION' ) || ( empty( $akismet_key ) && !defined( 'WPCOM_API_KEY' ) ) )
     605                return;
     606
     607        // Instantiate Akismet for BuddyPress
     608        $bp->activity->akismet = new BP_Akismet();
     609}
    537610?>
Note: See TracChangeset for help on using the changeset viewer.