/home/bonphmya/mercandestockages.store/wp-content/plugins/aioseo-eeat/app/Api/Users.php
<?php
namespace AIOSEO\Plugin\Addon\Eeat\Api;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Handles all user related endpoints.
 *
 * @since 1.0.0
 */
class Users {
	/**
	 * Returns a list of authors.
	 *
	 * @since 1.0.0
	 *
	 * @param  \WP_REST_Request  $request The request.
	 * @return \WP_REST_Response          The response.
	 */
	public static function getAuthors( $request ) {
		$params     = $request->get_json_params();
		$reviewerId = ! empty( $params['reviewerId'] ) ? intval( $params['reviewerId'] ) : '';
		$searchTerm = ! empty( $params['searchTerm'] ) ? sanitize_text_field( $params['searchTerm'] ) : '';

		$args = [
			'who'     => 'authors',
			'fields'  => [ 'ID', 'display_name', 'user_email' ],
			'orderby' => 'display_name',
			'order'   => 'ASC',
			'number'  => 50
		];

		if ( $searchTerm ) {
			$args += [
				'search'     => '*' . $searchTerm . '*',
				'search_col' => [ 'ID', 'display_name', 'user_email' ],
			];
		}

		$args    = apply_filters( 'aioseo_eeat_reviewer_list_args', $args );
		$authors = get_users( $args );

		if ( $reviewerId ) {
			$reviewer = get_user_by( 'ID', $reviewerId );
			if ( is_a( $reviewer, 'WP_User' ) ) {
				array_unshift( $authors, [
					'ID'           => $reviewer->ID,
					'display_name' => $reviewer->display_name,
					'user_email'   => $reviewer->user_email
				] );
			}
		}

		if ( empty( $authors ) ) {
			return new \WP_REST_Response( [
				'success' => false,
				'message' => 'No authors found.'
			], 400 );
		}

		return new \WP_REST_Response( [
			'success' => true,
			'authors' => $authors
		], 200 );
	}
}