| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\Mcp\Abilities\Utils; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
class Prompt_Loader { |
| 10 |
|
| 11 |
protected static function get_core_path(): string { |
| 12 |
return __DIR__ . '/../../static-resources/abilities/'; |
| 13 |
} |
| 14 |
|
| 15 |
protected static function resolve_extra_path(): ?string { |
| 16 |
if ( ! defined( 'ELEMENTOR_PRO_PATH' ) ) { |
| 17 |
return null; |
| 18 |
} |
| 19 |
|
| 20 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound |
| 21 |
return rtrim( constant( 'ELEMENTOR_PRO_PATH' ), '/' ) . '/modules/mcp/static-resources-extra/abilities/'; |
| 22 |
} |
| 23 |
|
| 24 |
public static function load( string $name ): string { |
| 25 |
$core_file = static::get_core_path() . $name . '.md'; |
| 26 |
$extra_path = static::resolve_extra_path(); |
| 27 |
$extra_file = null !== $extra_path ? $extra_path . $name . '.md' : null; |
| 28 |
|
| 29 |
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
| 30 |
$content = file_exists( $core_file ) ? rtrim( (string) file_get_contents( $core_file ) ) : ''; |
| 31 |
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
| 32 |
$extra = ( null !== $extra_file && file_exists( $extra_file ) ) ? rtrim( (string) file_get_contents( $extra_file ) ) : ''; |
| 33 |
|
| 34 |
return implode( "\n\n", array_filter( [ $content, $extra ] ) ); |
| 35 |
} |
| 36 |
} |
| 37 |
|