• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress a2z

WordPress a2z

WordPress Dynamic API Reference

  • Home
  • Plugins
  • Themes
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Akismet::cron_recheck() –

You appear to be a bot. Output may be restricted

Description

Usage

Akismet::cron_recheck();

Parameters

Returns

void

Source

File name: akismet/class.akismet.php
Lines:

1 to 88 of 88
  public static function cron_recheck() {
    global $wpdb;

    $api_key = self::get_api_key();

    $status = self::verify_key( $api_key );
    if ( get_option( 'akismet_alert_code' ) || $status == 'invalid' ) {
      // since there is currently a problem with the key, reschedule a check for 6 hours hence
      wp_schedule_single_event( time() + 21600, 'akismet_schedule_cron_recheck' );
      do_action( 'akismet_scheduled_recheck', 'key-problem-' . get_option( 'akismet_alert_code' ) . '-' . $status );
      return false;
    }

    delete_option('akismet_available_servers');

    $comment_errors = $wpdb->get_col( "SELECT comment_id FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'	LIMIT 100" );
    
    load_plugin_textdomain( 'akismet' );

    foreach ( (array) $comment_errors as $comment_id ) {
      // if the comment no longer exists, or is too old, remove the meta entry from the queue to avoid getting stuck
      $comment = get_comment( $comment_id );

      if (
        ! $comment // Comment has been deleted
        || strtotime( $comment->comment_date_gmt ) < strtotime( "-15 days" ) // Comment is too old.
        || $comment->comment_approved !== "0" // Comment is no longer in the Pending queue
        ) {
        delete_comment_meta( $comment_id, 'akismet_error' );
        delete_comment_meta( $comment_id, 'akismet_delayed_moderation_email' );
        continue;
      }

      add_comment_meta( $comment_id, 'akismet_rechecking', true );
      $status = self::check_db_comment( $comment_id, 'retry' );

      $event = '';
      if ( $status == 'true' ) {
        $event = 'cron-retry-spam';
      } elseif ( $status == 'false' ) {
        $event = 'cron-retry-ham';
      }

      // If we got back a legit response then update the comment history
      // other wise just bail now and try again later.  No point in
      // re-trying all the comments once we hit one failure.
      if ( !empty( $event ) ) {
        delete_comment_meta( $comment_id, 'akismet_error' );
        self::update_comment_history( $comment_id, '', $event );
        update_comment_meta( $comment_id, 'akismet_result', $status );
        // make sure the comment status is still pending.  if it isn't, that means the user has already moved it elsewhere.
        $comment = get_comment( $comment_id );
        if ( $comment && 'unapproved' == wp_get_comment_status( $comment_id ) ) {
          if ( $status == 'true' ) {
            wp_spam_comment( $comment_id );
          } elseif ( $status == 'false' ) {
            // comment is good, but it's still in the pending queue.  depending on the moderation settings
            // we may need to change it to approved.
            if ( check_comment($comment->comment_author, $comment->comment_author_email, $comment->comment_author_url, $comment->comment_content, $comment->comment_author_IP, $comment->comment_agent, $comment->comment_type) )
              wp_set_comment_status( $comment_id, 1 );
            else if ( get_comment_meta( $comment_id, 'akismet_delayed_moderation_email', true ) )
              wp_notify_moderator( $comment_id );
          }
        }
        
        delete_comment_meta( $comment_id, 'akismet_delayed_moderation_email' );
      } else {
        // If this comment has been pending moderation for longer than MAX_DELAY_BEFORE_MODERATION_EMAIL,
        // send a moderation email now.
        if ( ( intval( gmdate( 'U' ) ) - strtotime( $comment->comment_date_gmt ) ) < self::MAX_DELAY_BEFORE_MODERATION_EMAIL ) {
          delete_comment_meta( $comment_id, 'akismet_delayed_moderation_email' );
          wp_notify_moderator( $comment_id );
        }

        delete_comment_meta( $comment_id, 'akismet_rechecking' );
        wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
        do_action( 'akismet_scheduled_recheck', 'check-db-comment-' . $status );
        return;
      }
      delete_comment_meta( $comment_id, 'akismet_rechecking' );
    }

    $remaining = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->commentmeta} WHERE meta_key = 'akismet_error'" );
    if ( $remaining && !wp_next_scheduled('akismet_schedule_cron_recheck') ) {
      wp_schedule_single_event( time() + 1200, 'akismet_schedule_cron_recheck' );
      do_action( 'akismet_scheduled_recheck', 'remaining' );
    }
  }
 

 View on GitHub View on Trac

Published: 19th December 2019 | Last updated: 19th December 2019

Primary Sidebar

Information

Function name: Akismet::cron_recheck
Class ref: Akismet
Plugin ref: Akismet
Version: 5.0.1
Sourcefile: class.akismet.php
File ref: class.akismet.php
Deprecated?: No
API Letters: A,C,R

Footer

WordPress a2z
WordPress a2z
WordPress Dynamic API Reference
WordPress 6.1.1. PHP: 8.0.28
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  wp-a2z.org
© Copyright WordPress a2z 2014-2023. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites