# wp-parsely/3.23.3/src/class-validator.php

Parse.ly, version 3.23.3. 70 lines.

- Page: https://pluginprobe.com/plugins/wp-parsely/3.23.3/code/src/class-validator.php
- Raw: https://pluginprobe.com/plugins/wp-parsely/3.23.3/raw/src/class-validator.php
- Modified: 2024-11-12T09:05:26+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-parsely/3.23.3/code/src/class-validator.php#L10-L20`.

```php
<?php
/**
 * Validator class
 *
 * @package Parsely
 * @since   3.9.0
 */

declare(strict_types=1);

namespace Parsely;

use WP_Error;

/**
 * Contains a variety of validation functions.
 *
 * @since 3.9.0
 */
class Validator {

	public const INVALID_API_CREDENTIALS = 'invalid_api_credentials';

	/**
	 * Validates the passed Metadata Secret.
	 *
	 * Currently, the Metadata Secret is considered valid if it is exactly 10
	 * characters.
	 *
	 * @since 3.9.0
	 *
	 * @param string $metadata_secret The Metadata Secret to be validated.
	 * @return bool True if the Metadata Secret is valid, false otherwise.
	 */
	public static function validate_metadata_secret( string $metadata_secret ): bool {
		return strlen( $metadata_secret ) === 10;
	}

	/**
	 * Validates the passed API Credentials.
	 *
	 * @since 3.11.0
	 *
	 * @param Parsely $parsely The Parsely instance.
	 * @param string  $site_id The Site ID to be validated.
	 * @param string  $api_secret The API Secret to be validated.
	 * @return bool|WP_Error True if the API Credentials are valid, WP_Error otherwise.
	 */
	public static function validate_api_credentials( Parsely $parsely, string $site_id, string $api_secret ) {
		// If the API secret is empty, the validation endpoint will always fail.
		// Since it's possible to use the plugin without an API Secret, we'll
		// skip the validation and assume it's valid.
		if ( '' === $api_secret ) {
			return true;
		}

		$content_api = $parsely->get_content_api();
		$is_valid    = $content_api->validate_credentials( $site_id, $api_secret );

		if ( is_wp_error( $is_valid ) ) {
			return new WP_Error(
				self::INVALID_API_CREDENTIALS,
				__( 'Invalid API Credentials', 'wp-parsely' )
			);
		}

		return $is_valid;
	}
}

```
