• 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::comments_match() – Do these two comments, without checking the comment_ID, "match"?

You appear to be a bot. Output may be restricted

Description

Do these two comments, without checking the comment_ID, "match"?

Usage

$bool = Akismet::comments_match( $comment1, $comment2 );

Parameters

$comment1
( mixed ) required – A comment object or array.
$comment2
( mixed ) required – A comment object or array.

Returns

bool Whether the two comments should be treated as the same comment.

Source

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

1 to 52 of 52
  private static function comments_match( $comment1, $comment2 ) {
    $comment1 = (array) $comment1;
    $comment2 = (array) $comment2;

    // Set default values for these strings that we check in order to simplify
    // the checks and avoid PHP warnings.
    if ( ! isset( $comment1['comment_author'] ) ) {
      $comment1['comment_author'] = '';
    }

    if ( ! isset( $comment2['comment_author'] ) ) {
      $comment2['comment_author'] = '';
    }

    if ( ! isset( $comment1['comment_author_email'] ) ) {
      $comment1['comment_author_email'] = '';
    }

    if ( ! isset( $comment2['comment_author_email'] ) ) {
      $comment2['comment_author_email'] = '';
    }

    $comments_match = (
         isset( $comment1['comment_post_ID'], $comment2['comment_post_ID'] )
      && intval( $comment1['comment_post_ID'] ) == intval( $comment2['comment_post_ID'] )
      && (
        // The comment author length max is 255 characters, limited by the TINYTEXT column type.
        // If the comment author includes multibyte characters right around the 255-byte mark, they
        // may be stripped when the author is saved in the DB, so a 300+ char author may turn into
        // a 253-char author when it's saved, not 255 exactly.  The longest possible character is
        // theoretically 6 bytes, so we'll only look at the first 248 bytes to be safe.
        substr( $comment1['comment_author'], 0, 248 ) == substr( $comment2['comment_author'], 0, 248 )
        || substr( stripslashes( $comment1['comment_author'] ), 0, 248 ) == substr( $comment2['comment_author'], 0, 248 )
        || substr( $comment1['comment_author'], 0, 248 ) == substr( stripslashes( $comment2['comment_author'] ), 0, 248 )
        // Certain long comment author names will be truncated to nothing, depending on their encoding.
        || ( ! $comment1['comment_author'] && strlen( $comment2['comment_author'] ) > 248 )
        || ( ! $comment2['comment_author'] && strlen( $comment1['comment_author'] ) > 248 )
        )
      && (
        // The email max length is 100 characters, limited by the VARCHAR(100) column type.
        // Same argument as above for only looking at the first 93 characters.
        substr( $comment1['comment_author_email'], 0, 93 ) == substr( $comment2['comment_author_email'], 0, 93 )
        || substr( stripslashes( $comment1['comment_author_email'] ), 0, 93 ) == substr( $comment2['comment_author_email'], 0, 93 )
        || substr( $comment1['comment_author_email'], 0, 93 ) == substr( stripslashes( $comment2['comment_author_email'] ), 0, 93 )
        // Very long emails can be truncated and then stripped if the [0:100] substring isn't a valid address.
        || ( ! $comment1['comment_author_email'] && strlen( $comment2['comment_author_email'] ) > 100 )
        || ( ! $comment2['comment_author_email'] && strlen( $comment1['comment_author_email'] ) > 100 )
      )
    );

    return $comments_match;
  }
 

 View on GitHub View on Trac

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

Primary Sidebar

Information

Function name: Akismet::comments_match
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,M

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