the_comments( array $args = [] )`
*
* @link https://wordpress.org/plugins/amp/
*/
class Component implements Component_Interface, Templating_Component_Interface {
/**
* Gets the unique identifier for the theme component.
*
* @return string Component slug.
*/
public function get_slug() : string {
return 'comments';
}
/**
* Adds the action and filter hooks to integrate with WordPress.
*/
public function initialize() {
add_action( 'wp_enqueue_scripts', array( $this, 'action_enqueue_comment_reply_script' ) );
add_filter( 'comment_form_default_fields', array( $this, 'filter_default_fields_markup' ) );
add_filter( 'comment_form_defaults', array( $this, 'filter_default_markup' ) );
}
/**
* Gets template tags to expose as methods on the Template_Tags class instance, accessible through `kadence()`.
*
* @return array Associative array of $method_name => $callback_info pairs. Each $callback_info must either be
* a callable or an array with key 'callable'. This approach is used to reserve the possibility of
* adding support for further arguments in the future.
*/
public function template_tags() : array {
return array(
'the_comments' => array( $this, 'the_comments' ),
);
}
/**
* Enqueues the WordPress core 'comment-reply' script as necessary.
*/
public function action_enqueue_comment_reply_script() {
// If the AMP plugin is active, return early.
if ( kadence()->is_amp() ) {
return;
}
// Enqueue comment script on singular post/page views only.
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
/**
* Displays the list of comments for the current post.
*
* Internally this method calls `wp_list_comments()`. However, in addition to that it will render the wrapping
* element for the list, so that must not be added manually. The method will also take care of generating the
* necessary markup if amp-live-list should be used for comments.
*
* @param array $args Optional. Array of arguments. See `wp_list_comments()` documentation for a list of supported
* arguments.
*/
public function the_comments( array $args = array() ) {
$args = array_merge(
$args,
array(
'style' => 'ol',
'short_ping' => true,
'avatar_size' => 60,
)
);
$amp_live_list = kadence()->using_amp_live_list_comments();
if ( $amp_live_list ) {
$comment_order = get_option( 'comment_order' );
$comments_per_page = get_option( 'page_comments' ) ? (int) get_option( 'comments_per_page' ) : 10000;
$poll_inverval = MINUTE_IN_SECONDS * 1000;
?>
>