wp_lazyload_comment_meta( array $comment_ids )

Queue comment meta for lazy-loading.

Parameters

$comment_idsarrayrequired
List of comment IDs.

Source

function wp_lazyload_comment_meta( array $comment_ids ) {
	if ( empty( $comment_ids ) ) {
		return;
	}
	$lazyloader = wp_metadata_lazyloader();
	$lazyloader->queue_objects( 'comment', $comment_ids );
}

Changelog

VersionDescription
6.3.0Introduced.

User Contributed Notes

  1. Skip to note 2 content
    /**
     * Lazyloads metadata for a list of comment IDs.
     *
     * @param array $comment_ids Array of comment IDs.
     */
    function wpdocs_lazyload_comment_meta( array $comment_ids ) {
        foreach ( $comment_ids as $comment_id ) {
            // Simulate lazyloading by fetching comment metadata only when needed.
            $comment_meta = get_comment_meta( $comment_id );
            
            // Process the comment metadata.
            // For demonstration purposes, we'll just print it here.
            echo 'Lazyloaded metadata for comment ID ' . $comment_id . ':';
            foreach ( $comment_meta as $meta_key => $meta_values ) {
                echo $meta_key . ': ' . implode( ', ', $meta_values );
            }
        }
    }
    
    // Example usage
    $comment_ids_to_lazyload = array( 1, 2, 3, 4, 5 );
    wpdocs_lazyload_comment_meta( $comment_ids_to_lazyload );

    In this example, the wp_lazyload_comment_meta function takes an array of comment IDs and iterates through them. For each comment ID, it simulates lazyloading by fetching comment metadata using the get_comment_meta function. The metadata is then processed, and in this case, it’s simply printed to the screen. You can replace the print statements with your desired processing logic. The example usage at the end demonstrates how to call the function with an array of comment IDs.

You must log in before being able to contribute a note or feedback.