PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / modules / mcp / abilities / get-default-styles-ability.php

get-default-styles-ability.php in Elementor Website Builder – more than just a page builder 4.3.0-beta3, at modules/mcp/abilities/get-default-styles-ability.php

99 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\Mcp\Abilities;
4
5 use Elementor\Modules\DefaultStyles\Default_Styles_Repository;
6 use Elementor\Modules\Mcp\Abilities\Utils\Element_Default_Styles_Builder;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 class Get_Default_Styles_Ability extends Abstract_Ability {
13
14 private ?Default_Styles_Repository $repository;
15
16 public function __construct( ?Default_Styles_Repository $repository = null ) {
17 $this->repository = $repository;
18 }
19
20 protected function get_ability_id(): string {
21 return 'elementor/get-default-styles';
22 }
23
24 protected function get_definition(): Ability_Definition {
25 return new Ability_Definition(
26 __( 'Get Default Styles', 'elementor' ),
27 __( 'Returns the active kit\'s site-wide default styles for a single HTML wrapper tag (h1..h6, p, a, section, div, button, ...) as a raw CSS string. Includes selectors, @media(--breakpoint) blocks, and &:hover/&:focus/&:active pseudo-states as the frontend renders them. Widget-specific base styles are NOT included — this is only the kit\'s site-wide default layer.', 'elementor' ),
28 'elementor',
29 [
30 'type' => 'object',
31 'required' => [ 'tag', 'default_styles' ],
32 'properties' => [
33 'tag' => [
34 'type' => 'string',
35 'description' => 'Echoes the requested HTML tag.',
36 ],
37 'default_styles' => [
38 'type' => 'string',
39 'description' => 'Raw CSS string of the kit site-wide default for this tag. Empty when the kit has no default set for the tag.',
40 ],
41 ],
42 ],
43 [
44 'annotations' => [
45 'readonly' => true,
46 'idempotent' => true,
47 'destructive' => false,
48 ],
49 ],
50 fn() => current_user_can( 'edit_posts' ),
51 [
52 'type' => 'object',
53 'required' => [ 'tag' ],
54 'properties' => [
55 'tag' => [
56 'type' => 'string',
57 'description' => 'HTML wrapper tag to look up (e.g. h2, p, a, button, section). Must be one of Elementor\'s allowed wrapper tags.',
58 ],
59 ],
60 ]
61 );
62 }
63
64 public function execute( $input = [] ) {
65 $tag = isset( $input['tag'] ) ? (string) $input['tag'] : '';
66
67 if ( '' === $tag ) {
68 return new \WP_Error(
69 'invalid_input',
70 __( 'A tag is required.', 'elementor' ),
71 [ 'status' => \WP_Http::BAD_REQUEST ]
72 );
73 }
74
75 if ( ! class_exists( Default_Styles_Repository::class ) || ! Default_Styles_Repository::is_allowed_tag( $tag ) ) {
76 return new \WP_Error(
77 'invalid_tag',
78 __( 'The provided tag is not an allowed HTML wrapper tag.', 'elementor' ),
79 [ 'status' => \WP_Http::BAD_REQUEST ]
80 );
81 }
82
83 return [
84 'tag' => $tag,
85 'default_styles' => Element_Default_Styles_Builder::render_kit_default( $tag, $this->get_repository() ),
86 ];
87 }
88
89 private function get_repository(): ?Default_Styles_Repository {
90 if ( null !== $this->repository ) {
91 return $this->repository;
92 }
93
94 $this->repository = Default_Styles_Repository::make();
95
96 return $this->repository;
97 }
98 }
99