[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-activity/ -> bp-activity-akismet.php (source)

   1  <?php
   2  /**
   3   * Akismet support for BuddyPress' Activity Stream.
   4   *
   5   * @package BuddyPress
   6   * @subpackage ActivityAkismet
   7   * @since 1.6.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Loads Akismet filtering for activity.
  15   *
  16   * @since 1.6.0
  17   * @since 2.3.0 We only support Akismet 3+.
  18   */
  19  function bp_activity_setup_akismet() {
  20      /**
  21       * Filters if BuddyPress Activity Akismet support has been disabled by another plugin.
  22       *
  23       * @since 1.6.0
  24       *
  25       * @param bool $value Return value of bp_is_akismet_active boolean function.
  26       */
  27      if ( ! apply_filters( 'bp_activity_use_akismet', bp_is_akismet_active() ) ) {
  28          return;
  29      }
  30  
  31      // Instantiate Akismet for BuddyPress.
  32      buddypress()->activity->akismet = new BP_Akismet();
  33  }
  34  add_action( 'bp_activity_setup_globals', 'bp_activity_setup_akismet' );
  35  
  36  /**
  37   * Delete old spam activity meta data.
  38   *
  39   * This is done as a clean-up mechanism, as _bp_akismet_submission meta can
  40   * grow to be quite large.
  41   *
  42   * @since 1.6.0
  43   *
  44   * @global wpdb $wpdb WordPress database object.
  45   */
  46  function bp_activity_akismet_delete_old_metadata() {
  47      global $wpdb;
  48  
  49      $bp = buddypress();
  50  
  51      /**
  52       * Filters the threshold for how many days old Akismet metadata needs to be before being automatically deleted.
  53       *
  54       * @since 1.6.0
  55       *
  56       * @param integer 15 How many days old metadata needs to be.
  57       */
  58      $interval = apply_filters( 'bp_activity_akismet_delete_meta_interval', 15 );
  59  
  60      // Enforce a minimum of 1 day.
  61      $interval = max( 1, absint( $interval ) );
  62  
  63      // _bp_akismet_submission meta values are large, so expire them after $interval days regardless of the activity status.
  64      $sql          = $wpdb->prepare( "SELECT a.id FROM {$bp->activity->table_name} a LEFT JOIN {$bp->activity->table_name_meta} m ON a.id = m.activity_id WHERE m.meta_key = %s AND DATE_SUB(%s, INTERVAL {$interval} DAY) > a.date_recorded LIMIT 10000", '_bp_akismet_submission', current_time( 'mysql', 1 ) );
  65      $activity_ids = $wpdb->get_col( $sql );
  66  
  67      if ( ! empty( $activity_ids ) ) {
  68          foreach ( $activity_ids as $activity_id )
  69              bp_activity_delete_meta( $activity_id, '_bp_akismet_submission' );
  70      }
  71  }
  72  add_action( 'bp_activity_akismet_delete_old_metadata', 'bp_activity_akismet_delete_old_metadata' );


Generated: Fri Feb 26 01:01:36 2021 Cross-referenced by PHPXref 0.7.1