HEX
Server: Apache/2.4.41
System: Linux mainweb 5.4.0-182-generic #202-Ubuntu SMP Fri Apr 26 12:29:36 UTC 2024 x86_64
User: nationalmedicaregrp (1119)
PHP: 8.3.7
Disabled: exec,passthru,shell_exec,system,popen,proc_open,pcntl_exec
Upload Files
File: /home/flbestac/public_html/wp-content/plugins/elementor/modules/components/components-parser.php
<?php

namespace Elementor\Modules\Components;

use Elementor\Core\Utils\Api\Parse_Result;

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

class Components_Parser {
	const MIN_NAME_LENGTH = 2;
	const MAX_NAME_LENGTH = 50;

	public static function make() {
		return new static();
	}

	public function parse_name( $name, $existing_components_names ): Parse_Result {
		$result = Parse_Result::make();

		$sanitized = trim( sanitize_text_field( $name ) );

		if ( strlen( $sanitized ) < self::MIN_NAME_LENGTH ) {
			$result->errors()->add( 'name', 'component_name_too_short_min_' . self::MIN_NAME_LENGTH );
		}

		if ( strlen( $sanitized ) > self::MAX_NAME_LENGTH ) {
			$result->errors()->add( 'name', 'component_name_too_long_max_' . self::MAX_NAME_LENGTH );
		}

		if ( in_array( $sanitized, $existing_components_names, true ) ) {
			$result->errors()->add( 'name', 'duplicated_component_name' );
		}

		return $result->wrap( $sanitized );
	}
}