| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\Mcp\Abilities; |
| 4 |
|
| 5 |
use Elementor\Modules\Variables\Services\Batch_Operations\Batch_Processor; |
| 6 |
use Elementor\Modules\Variables\Services\Variables_Service; |
| 7 |
use Elementor\Modules\Variables\Storage\Variables_Repository; |
| 8 |
use Elementor\Plugin; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
class Global_Variables_Resource_Ability extends Abstract_Ability { |
| 15 |
const URI = 'elementor://global-variables'; |
| 16 |
|
| 17 |
protected function get_ability_id(): string { |
| 18 |
return 'elementor/global-variables-resource'; |
| 19 |
} |
| 20 |
|
| 21 |
protected function get_definition(): Ability_Definition { |
| 22 |
return new Ability_Definition( |
| 23 |
__( 'Global Variables', 'elementor' ), |
| 24 |
__( 'Design tokens (colors, fonts, sizes) from the active kit; check before styling with variables.', 'elementor' ), |
| 25 |
'elementor', |
| 26 |
[ 'type' => 'string' ], |
| 27 |
[ |
| 28 |
'mcp' => [ |
| 29 |
'type' => 'resource', |
| 30 |
'uri' => self::URI, |
| 31 |
'public' => true, |
| 32 |
'mimeType' => 'application/json', |
| 33 |
'description' => __( 'Design tokens (colors, fonts, sizes) from the active kit; check before styling with variables.', 'elementor' ), |
| 34 |
], |
| 35 |
], |
| 36 |
fn() => current_user_can( 'edit_posts' ) |
| 37 |
); |
| 38 |
} |
| 39 |
|
| 40 |
public function execute( $input = [] ) { |
| 41 |
$kit = Plugin::$instance->kits_manager->get_active_kit(); |
| 42 |
|
| 43 |
$variables_service = new Variables_Service( |
| 44 |
new Variables_Repository( $kit ), |
| 45 |
new Batch_Processor() |
| 46 |
); |
| 47 |
|
| 48 |
$variables_payload = $variables_service->load(); |
| 49 |
|
| 50 |
$data = $variables_payload['data'] ?? []; |
| 51 |
|
| 52 |
return wp_json_encode( [ |
| 53 |
'variables' => (object) $data, |
| 54 |
'total' => count( $data ), |
| 55 |
'watermark' => $variables_payload['watermark'] ?? null, |
| 56 |
] ); |
| 57 |
} |
| 58 |
} |
| 59 |
|