• File: prompt-loader.php
  • Full Path: /home/slvgwrnz/public_html/wp-content/plugins/elementor/modules/mcp/abilities/utils/prompt-loader.php
  • Date Modified: 09/01/2026 8:47 AM
  • File size: 1.24 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php

namespace Elementor\Modules\Mcp\Abilities\Utils;

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

class Prompt_Loader {

	protected static function get_core_path(): string {
		return __DIR__ . '/../../static-resources/abilities/';
	}

	protected static function resolve_extra_path(): ?string {
		if ( ! defined( 'ELEMENTOR_PRO_PATH' ) ) {
			return null;
		}

		// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
		return rtrim( constant( 'ELEMENTOR_PRO_PATH' ), '/' ) . '/modules/mcp/static-resources-extra/abilities/';
	}

	public static function load( string $name ): string {
		$core_file  = static::get_core_path() . $name . '.md';
		$extra_path = static::resolve_extra_path();
		$extra_file = null !== $extra_path ? $extra_path . $name . '.md' : null;

		// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
		$content = file_exists( $core_file ) ? rtrim( (string) file_get_contents( $core_file ) ) : '';
		// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
		$extra = ( null !== $extra_file && file_exists( $extra_file ) ) ? rtrim( (string) file_get_contents( $extra_file ) ) : '';

		return implode( "\n\n", array_filter( [ $content, $extra ] ) );
	}
}