• 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::transition_comment_status() –

You appear to be a bot. Output may be restricted

Description

Usage

Akismet::transition_comment_status( $new_status, $old_status, $comment );

Parameters

$new_status
( mixed ) required –
$old_status
( mixed ) required –
$comment
( mixed ) required –

Returns

void

Source

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

1 to 64 of 64
  public static function transition_comment_status( $new_status, $old_status, $comment ) {
    
    if ( $new_status == $old_status )
      return;

    if ( 'spam' === $new_status || 'spam' === $old_status ) {
      // Clear the cache of the "X comments in your spam queue" count on the dashboard.
      wp_cache_delete( 'akismet_spam_count', 'widget' );
    }

    # we don't need to record a history item for deleted comments
    if ( $new_status == 'delete' )
      return;
    
    if ( !current_user_can( 'edit_post', $comment->comment_post_ID ) && !current_user_can( 'moderate_comments' ) )
      return;

    if ( defined('WP_IMPORTING') && WP_IMPORTING == true )
      return;
      
    // if this is present, it means the status has been changed by a re-check, not an explicit user action
    if ( get_comment_meta( $comment->comment_ID, 'akismet_rechecking' ) )
      return;
    
    // Assumption alert:
    // We want to submit comments to Akismet only when a moderator explicitly spams or approves it - not if the status
    // is changed automatically by another plugin.  Unfortunately WordPress doesn't provide an unambiguous way to
    // determine why the transition_comment_status action was triggered.  And there are several different ways by which
    // to spam and unspam comments: bulk actions, ajax, links in moderation emails, the dashboard, and perhaps others.
    // We'll assume that this is an explicit user action if certain POST/GET variables exist.
    if (
       // status=spam: Marking as spam via the REST API or...
       // status=unspam: I'm not sure. Maybe this used to be used instead of status=approved? Or the UI for removing from spam but not approving has been since removed?...
       // status=approved: Unspamming via the REST API (Calypso) or...
       ( isset( $_POST['status'] ) && in_array( $_POST['status'], array( 'spam', 'unspam', 'approved', ) ) )
       // spam=1: Clicking "Spam" underneath a comment in wp-admin and allowing the AJAX request to happen.
       || ( isset( $_POST['spam'] ) && (int) $_POST['spam'] == 1 )
       // unspam=1: Clicking "Not Spam" underneath a comment in wp-admin and allowing the AJAX request to happen. Or, clicking "Undo" after marking something as spam.
       || ( isset( $_POST['unspam'] ) && (int) $_POST['unspam'] == 1 )
       // comment_status=spam/unspam: It's unclear where this is happening.
       || ( isset( $_POST['comment_status'] )  && in_array( $_POST['comment_status'], array( 'spam', 'unspam' ) ) )
       // action=spam: Choosing "Mark as Spam" from the Bulk Actions dropdown in wp-admin (or the "Spam it" link in notification emails).
       // action=unspam: Choosing "Not Spam" from the Bulk Actions dropdown in wp-admin.
       // action=spamcomment: Following the "Spam" link below a comment in wp-admin (not allowing AJAX request to happen).
       // action=unspamcomment: Following the "Not Spam" link below a comment in wp-admin (not allowing AJAX request to happen).
       || ( isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'spam', 'unspam', 'spamcomment', 'unspamcomment', ) ) )
       // action=editedcomment: Editing a comment via wp-admin (and possibly changing its status).
       || ( isset( $_POST['action'] ) && in_array( $_POST['action'], array( 'editedcomment' ) ) )
       // for=jetpack: Moderation via the WordPress app, Calypso, anything powered by the Jetpack connection.
       || ( isset( $_GET['for'] ) && ( 'jetpack' == $_GET['for'] ) && ( ! defined( 'IS_WPCOM' ) || ! IS_WPCOM ) ) 
       // Certain WordPress.com API requests
       || ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST )
       // WordPress.org REST API requests
       || ( defined( 'REST_REQUEST' ) && REST_REQUEST )
     ) {
      if ( $new_status == 'spam' && ( $old_status == 'approved' || $old_status == 'unapproved' || !$old_status ) ) {
        return self::submit_spam_comment( $comment->comment_ID );
      } elseif ( $old_status == 'spam' && ( $new_status == 'approved' || $new_status == 'unapproved' ) ) {
        return self::submit_nonspam_comment( $comment->comment_ID );
      }
    }

    self::update_comment_history( $comment->comment_ID, '', 'status-' . $new_status );
  }
 

 View on GitHub View on Trac

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

Primary Sidebar

Information

Function name: Akismet::transition_comment_status
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,S,T

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