• I was working on the function of duplicate comments. I have the fallow code in the comment.php file of wp-inlcude but its not working:

    **
     * Validates whether this comment is allowed to be made.
     *
     * @since 2.0.0
     *
     * @global wpdb $wpdb WordPress database abstraction object.
     *
     * @param array $commentdata Contains information on the comment
     * @return mixed Signifies the approval status (0|1|'spam')
     */
    function wp_allow_comment( $commentdata ) {
    	global $wpdb;
    
    if(is_page(2999)){
    
    } else {
    
    	// Simple duplicate check
    	// expected_slashed ($comment_post_ID, $comment_author, $comment_author_email, $comment_content)
    	$dupe = $wpdb->prepare(
    		"SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_parent = %s AND comment_approved != 'trash' AND ( comment_author = %s ",
    		wp_unslash( $commentdata['comment_post_ID'] ),
    		wp_unslash( $commentdata['comment_parent'] ),
    		wp_unslash( $commentdata['comment_author'] )
    	);
    	if ( $commentdata['comment_author_email'] ) {
    		$dupe .= $wpdb->prepare(
    			"OR comment_author_email = %s ",
    			wp_unslash( $commentdata['comment_author_email'] )
    		);
    	}
    	$dupe .= $wpdb->prepare(
    		") AND comment_content = %s LIMIT 1",
    		wp_unslash( $commentdata['comment_content'] )
    	);
    	if ( $wpdb->get_var( $dupe ) ) {
    		/**
    		 * Fires immediately after a duplicate comment is detected.
    		 *
    		 * @since 3.0.0
    		 *
    		 * @param array $commentdata Comment data.
    		 */
    		do_action( 'comment_duplicate_trigger', $commentdata );
    		if ( defined( 'DOING_AJAX' ) ) {
    			die( __('Duplicate comment detected; it looks as though you’ve already said that!') );
    		}
    		wp_die( __( 'Duplicate comment detected; it looks as though you’ve already said that!' ), 409 );
    	}
    }

    If its page id 2999 then duplicate is allowd else not.

    Even if i change the if statement to the fallow it doesn’t work

    /**
     * Validates whether this comment is allowed to be made.
     *
     * @since 2.0.0
     *
     * @global wpdb $wpdb WordPress database abstraction object.
     *
     * @param array $commentdata Contains information on the comment
     * @return mixed Signifies the approval status (0|1|'spam')
     */
    
    function wp_allow_comment( $commentdata ) {
    	global $wpdb;
    
    $string = "home";
              $container = $post->post_title;
                if(strstr($container,$string)) {
    
    } else {
  • The topic ‘Duplicate comments’ is closed to new replies.