HEX
Server: Apache
System: Linux WWW 6.1.0-40-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.153-1 (2025-09-20) x86_64
User: web11 (1011)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/lcc.kaunokolegija.lt/wp-content/plugins/weglot/src/actions/admin/class-ajax-user-info.php
<?php

namespace WeglotWP\Actions\Admin;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use WeglotWP\Models\Hooks_Interface_Weglot;
use WeglotWP\Services\User_Api_Service_Weglot;

class Ajax_User_Info implements Hooks_Interface_Weglot {
	/**
	 * @var User_Api_Service_Weglot
	 */
	private $user_services;

	public function __construct() {
		$this->user_services = weglot_get_service( User_Api_Service_Weglot::class );
	}

	/**
	 * @see Hooks_Interface_Weglot
	 *
	 * @since 3.0.0
	 * @return void
	 */
	public function hooks() {
		if ( ! is_admin() ) {
			return;
		}

		add_action( 'wp_ajax_get_user_info', array( $this, 'get_user_info' ) );
	}

	/**
	 * @since 3.0.0
	 * @return void
	 */
	public function get_user_info() {
		if ( ! isset( $_POST['api_key'] ) ) { //phpcs:ignore
			wp_send_json_error();
		}

		$api_key = sanitize_title( $_POST['api_key'] ); //phpcs:ignore

		$response = $this->user_services->get_user_info( $api_key );

		if ( array_key_exists( 'not_exist', $response ) && ! $response['not_exist'] ) {
			wp_send_json_error();
		}

		wp_send_json_success( $response );
	}
}