# wp-graphql/trunk/src/Data/Loader/CommentAuthorLoader.php

WPGraphQL, version trunk. 57 lines.

- Page: https://pluginprobe.com/plugins/wp-graphql/trunk/code/src/Data/Loader/CommentAuthorLoader.php
- Raw: https://pluginprobe.com/plugins/wp-graphql/trunk/raw/src/Data/Loader/CommentAuthorLoader.php
- Modified: 2023-11-02T19:07:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wp-graphql/trunk/code/src/Data/Loader/CommentAuthorLoader.php#L10-L20`.

```php
<?php
namespace WPGraphQL\Data\Loader;

use WPGraphQL\Model\CommentAuthor;

/**
 * Class CommentAuthorLoader
 *
 * @package WPGraphQL\Data\Loader
 */
class CommentAuthorLoader extends AbstractDataLoader {

	/**
	 * {@inheritDoc}
	 *
	 * @return ?\WPGraphQL\Model\CommentAuthor
	 */
	protected function get_model( $entry, $key ) {
		if ( ! $entry instanceof \WP_Comment ) {
			return null;
		}

		return new CommentAuthor( $entry );
	}

	/**
	 * {@inheritDoc}
	 *
	 * @param int[] $keys Array of IDs to load
	 */
	public function loadKeys( array $keys ) {
		/**
		 * Prepare the args for the query. We're provided a specific set of IDs of comments
		 * so we want to query as efficiently as possible with as little overhead to get the comment
		 * objects. No need to count the rows, etc.
		 */
		$args = [
			'comment__in'   => $keys,
			'orderby'       => 'comment__in',
			'number'        => count( $keys ),
			'no_found_rows' => true,
			'count'         => false,
		];

		/**
		 * Execute the query. Call get_comments() to add them to the cache.
		 */
		$query = new \WP_Comment_Query( $args );
		$query->get_comments();
		$loaded = [];
		foreach ( $keys as $key ) {
			$loaded[ $key ] = \WP_Comment::get_instance( $key );
		}
		return $loaded;
	}
}

```
