Skip to content

Instantly share code, notes, and snippets.

@SainathPoojary
Last active July 4, 2025 08:57
Show Gist options
  • Select an option

  • Save SainathPoojary/d6f39d0e45a3b2018f9312bdda1e26b5 to your computer and use it in GitHub Desktop.

Select an option

Save SainathPoojary/d6f39d0e45a3b2018f9312bdda1e26b5 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Simulate Comment Meta Box Offset Bug
* Description: Demonstrates the "Show more comments" offset bug in the Comments meta box
* using a custom comment type, without altering core filters.
* Version: 1.0
* Author: Test Automation Team
*/
/**
* Ensure the 'post' post type supports comments.
*/
add_action( 'init', function () {
add_post_type_support( 'post', 'comments' );
} );
/**
* Add the native WordPress comments meta box to the 'post' post type.
*/
add_action( 'add_meta_boxes', function () {
add_meta_box(
'commentsdiv',
__( 'Comments' ),
'post_comment_meta_box',
'post',
'normal',
'core'
);
} );
/**
* On plugin activation, create a post with 16 custom comments of type 'custom_note'.
*
* WordPress core does not add the 'comment' class for custom comment types,
* which causes the "Show more comments" offset logic in post.js to break.
*/
register_activation_hook( __FILE__, function () {
$post_id = wp_insert_post( [
'post_title' => 'Custom Comment Type Test',
'post_content' => 'This post contains 16 comments of a custom comment type (custom_note).',
'post_status' => 'publish',
'post_type' => 'post',
] );
if ( ! $post_id || is_wp_error( $post_id ) ) {
return;
}
// Insert 16 approved comments of type 'custom_note'.
for ( $i = 1; $i <= 16; $i++ ) {
wp_insert_comment( [
'comment_post_ID' => $post_id,
'comment_author' => 'Tester',
'comment_author_email' => 'tester@example.com',
'comment_content' => "Custom Comment #{$i}",
'comment_type' => 'custom_note',
'comment_approved' => 1,
] );
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment