| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\Mcp\Abilities; |
| 4 |
|
| 5 |
use Elementor\Modules\GlobalClasses\Global_Classes_Repository; |
| 6 |
use Elementor\Plugin; |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
class Global_Classes_Resource_Ability extends Abstract_Ability { |
| 13 |
const URI = 'elementor://global-classes'; |
| 14 |
|
| 15 |
private ?Global_Classes_Repository $repository; |
| 16 |
|
| 17 |
public function __construct( ?Global_Classes_Repository $repository = null ) { |
| 18 |
$this->repository = $repository; |
| 19 |
} |
| 20 |
|
| 21 |
protected function get_ability_id(): string { |
| 22 |
return 'elementor/global-classes-resource'; |
| 23 |
} |
| 24 |
|
| 25 |
protected function get_definition(): Ability_Definition { |
| 26 |
return new Ability_Definition( |
| 27 |
__( 'Global Classes', 'elementor' ), |
| 28 |
__( 'Reusable CSS classes from the active kit, ordered from highest to lowest CSS priority. Check first before adding inline styles.', 'elementor' ), |
| 29 |
'elementor', |
| 30 |
[ 'type' => 'string' ], |
| 31 |
[ |
| 32 |
'mcp' => [ |
| 33 |
'type' => 'resource', |
| 34 |
'uri' => self::URI, |
| 35 |
'public' => true, |
| 36 |
'mimeType' => 'application/json', |
| 37 |
'description' => __( 'Reusable CSS classes from the active kit, ordered from highest to lowest CSS priority. Check first before adding inline styles.', 'elementor' ), |
| 38 |
], |
| 39 |
], |
| 40 |
fn() => current_user_can( 'edit_posts' ) |
| 41 |
); |
| 42 |
} |
| 43 |
|
| 44 |
public function execute( $input = [] ) { |
| 45 |
$classes = []; |
| 46 |
foreach ( $this->get_repository()->all_labels() as $id => $label ) { |
| 47 |
$classes[] = [ |
| 48 |
'id' => $id, |
| 49 |
'label' => $label, |
| 50 |
]; |
| 51 |
} |
| 52 |
|
| 53 |
return wp_json_encode( [ |
| 54 |
'priority_description' => __( 'Classes are ordered from highest to lowest priority. When classes on the same element set the same CSS property, the earlier class overrides the later one.', 'elementor' ), |
| 55 |
'classes' => $classes, |
| 56 |
] ); |
| 57 |
} |
| 58 |
|
| 59 |
private function get_repository(): Global_Classes_Repository { |
| 60 |
if ( $this->repository ) { |
| 61 |
return $this->repository; |
| 62 |
} |
| 63 |
|
| 64 |
$kit = Plugin::$instance->kits_manager->get_active_kit(); |
| 65 |
|
| 66 |
return Global_Classes_Repository::make( $kit ); |
| 67 |
} |
| 68 |
} |
| 69 |
|