Skip to:
Content

Ticket #7218: 7218.akismet.patch

File 7218.akismet.patch, 4.9 KB (added by r-a-y, 9 months ago)

Refreshed for 2.9

  • src/bp-activity/bp-activity-akismet.php

     
    3434add_action( 'bp_activity_setup_globals', 'bp_activity_setup_akismet' ); 
    3535 
    3636/** 
     37 * Tell Akismet not to check activity item if marked as spam by a person. 
     38 * 
     39 * @since 2.9.0 This logic was moved out of bp_activity_mark_as_spam() 
     40 * 
     41 * @param BP_Activity_Activity $activity Activity item being marked as spam. 
     42 * @param string               $source   Source of determination of spam status. For example 
     43 *                                       "by_a_person" or "by_akismet". 
     44 */ 
     45function bp_activity_akismet_mark_as_spam_by_a_person( $activity, $source = 'by_a_person' ) { 
     46        $bp = buddypress(); 
     47 
     48        // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity. 
     49        if ( 'by_a_person' == $source && ! empty( $bp->activity->akismet ) ) { 
     50                remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 ); 
     51 
     52                // Build data package for Akismet. 
     53                $activity_data = BP_Akismet::build_akismet_data_package( $activity ); 
     54 
     55                // Tell Akismet this is spam. 
     56                $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'spam' ); 
     57 
     58                // Update meta. 
     59                add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_spam_meta' ), 1, 1 ); 
     60        } 
     61} 
     62add_action( 'bp_activity_mark_as_spam', 'bp_activity_akismet_mark_as_spam_by_a_person', 1, 2 ); 
     63 
     64/** 
     65 * Tell Akismet not to check activity item if marked as ham by a person. 
     66 * 
     67 * @since 2.9.0 This logic was moved out of bp_activity_mark_as_ham() 
     68 * 
     69 * @param BP_Activity_Activity $activity Activity item being marked as ham. 
     70 * @param string               $source   Source of determination of ham status. For example 
     71 *                                       "by_a_person" or "by_akismet". 
     72 */ 
     73function bp_activity_akismet_mark_as_ham_by_a_person( $activity, $source = 'by_a_person' ) { 
     74        $bp = buddypress(); 
     75 
     76        // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity. 
     77        if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) { 
     78                remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 ); 
     79 
     80                // Build data package for Akismet. 
     81                $activity_data = BP_Akismet::build_akismet_data_package( $activity ); 
     82 
     83                // Tell Akismet this is spam. 
     84                $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'ham' ); 
     85 
     86                // Update meta. 
     87                add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_ham_meta' ), 1, 1 ); 
     88        } 
     89} 
     90add_action( 'bp_activity_mark_as_ham', 'bp_activity_akismet_mark_as_ham_by_a_person', 1, 2 ); 
     91 
     92/** 
    3793 * Delete old spam activity meta data. 
    3894 * 
    3995 * This is done as a clean-up mechanism, as _bp_akismet_submission meta can 
  • src/bp-activity/bp-activity-functions.php

     
    33943394        // Clear the activity comment cache for this activity item. 
    33953395        wp_cache_delete( $activity->id, 'bp_activity_comments' ); 
    33963396 
    3397         // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity. 
    3398         if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) { 
    3399                 remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4 ); 
    3400  
    3401                 // Build data package for Akismet. 
    3402                 $activity_data = BP_Akismet::build_akismet_data_package( $activity ); 
    3403  
    3404                 // Tell Akismet this is spam. 
    3405                 $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'spam' ); 
    3406  
    3407                 // Update meta. 
    3408                 add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_spam_meta' ), 1, 1 ); 
    3409         } 
    3410  
    34113397        /** 
    34123398         * Fires at the end of the process to mark an activity item as spam. 
    34133399         * 
     
    34413427        // Clear the activity comment cache for this activity item. 
    34423428        wp_cache_delete( $activity->id, 'bp_activity_comments' ); 
    34433429 
    3444         // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity. 
    3445         if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) { 
    3446                 remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4 ); 
    3447  
    3448                 // Build data package for Akismet. 
    3449                 $activity_data = BP_Akismet::build_akismet_data_package( $activity ); 
    3450  
    3451                 // Tell Akismet this is spam. 
    3452                 $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'ham' ); 
    3453  
    3454                 // Update meta. 
    3455                 add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_ham_meta' ), 1, 1 ); 
    3456         } 
    3457  
    34583430        /** 
    34593431         * Fires at the end of the process to mark an activity item as ham. 
    34603432         *