PluginProbe ʕ •ᴥ•ʔ
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor / 4.0.1
ElementsKit Elementor Addons – Advanced Widgets & Templates Addons for Elementor v4.0.1
4.0.2 4.0.1 4.0.0 3.10.02 3.10.01 3.9.10 3.9.9 3.9.8 3.9.7 3.9.5 3.9.6 3.9.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.3.1 2.3.1.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.4.0 2.5.0 2.5.1 2.5.10 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.5 2.8.6 2.8.7 2.8.8 2.9.0 2.9.1 2.9.2 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.5.6 3.6.0 3.6.1 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.8.1 3.8.2 3.9.0 3.9.1 3.9.2 trunk 1.2.6 1.2.7 1.2.9 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.2 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.0.9.1 2.0.9.2 2.0.9.3
elementskit-lite / mcp / abilities.php
elementskit-lite / mcp Last commit date
assets 3 weeks ago abilities.php 3 weeks ago manager.php 3 weeks ago rest-proxy.php 3 weeks ago server.php 3 weeks ago service.php 3 weeks ago
abilities.php
612 lines
1 <?php
2 namespace ElementsKit_Lite\Mcp;
3
4 defined( 'ABSPATH' ) || exit;
5
6 /**
7 * Registers ElementsKit's WP Abilities.
8 *
9 * The abilities are the public backend MCP contract. Each one is a thin wrapper
10 * whose execute_callback delegates to the shared {@see Service} — no business
11 * logic lives here.
12 *
13 * @since 3.10.x
14 */
15 class Abilities {
16
17 const CATEGORY = 'elementskit';
18
19 /**
20 * Wire the ability + category registration onto the Abilities API hooks.
21 */
22 public function hooks() {
23 if ( ! function_exists( 'wp_register_ability' ) ) {
24 return;
25 }
26
27 add_action( 'wp_abilities_api_categories_init', [ $this, 'register_category' ] );
28 add_action( 'wp_abilities_api_init', [ $this, 'register_abilities' ] );
29 }
30
31 /**
32 * Fully-qualified ability ids exposed by ElementsKit, in a stable order.
33 *
34 * @return string[]
35 */
36 public static function ability_ids() {
37 return [
38 'elementskit/list-widgets',
39 'elementskit/insert-widget',
40 'elementskit/list-templates',
41 'elementskit/insert-template',
42 'elementskit/create-page',
43 'elementskit/create-template',
44 'elementskit/create-header-footer',
45 'elementskit/list-custom-widgets',
46 'elementskit/create-custom-widget',
47 'elementskit/list-mega-menus',
48 'elementskit/enable-mega-menu',
49 'elementskit/update-mega-menu-item',
50 'elementskit/create-mega-menu',
51 'elementskit/list-library-templates',
52 'elementskit/import-library-template',
53 ];
54 }
55
56 public function register_category() {
57 if ( ! function_exists( 'wp_register_ability_category' ) ) {
58 return;
59 }
60
61 wp_register_ability_category(
62 self::CATEGORY,
63 [
64 'label' => __( 'ElementsKit', 'elementskit-lite' ),
65 'description' => __( 'Read and modify ElementsKit widgets and templates for Elementor.', 'elementskit-lite' ),
66 ]
67 );
68 }
69
70 public function register_abilities() {
71 if ( ! function_exists( 'wp_register_ability' ) ) {
72 return;
73 }
74
75 wp_register_ability(
76 'elementskit/list-widgets',
77 [
78 'label' => __( 'List ElementsKit widgets', 'elementskit-lite' ),
79 'description' => __( 'List the ElementsKit widgets (Lite and Pro) available in Elementor.', 'elementskit-lite' ),
80 'category' => self::CATEGORY,
81 'input_schema' => [
82 'type' => 'object',
83 'properties' => [
84 'search' => [
85 'type' => 'string',
86 'description' => __( 'Optional case-insensitive filter matched against the widget type and title.', 'elementskit-lite' ),
87 ],
88 'category' => [
89 'type' => 'string',
90 'description' => __( 'Optional Elementor category slug to filter by.', 'elementskit-lite' ),
91 ],
92 ],
93 ],
94 'output_schema' => [
95 'type' => 'object',
96 'properties' => [
97 'success' => [ 'type' => 'boolean' ],
98 'count' => [ 'type' => 'integer' ],
99 'widgets' => [ 'type' => 'array' ],
100 ],
101 ],
102 'execute_callback' => static function ( $input ) {
103 return ( new Service() )->list_widgets( is_array( $input ) ? $input : [] );
104 },
105 'permission_callback' => static function () {
106 return current_user_can( 'edit_posts' );
107 },
108 ]
109 );
110
111 wp_register_ability(
112 'elementskit/insert-widget',
113 [
114 'label' => __( 'Insert ElementsKit widget', 'elementskit-lite' ),
115 'description' => __( 'Insert an ElementsKit widget into an Elementor document.', 'elementskit-lite' ),
116 'category' => self::CATEGORY,
117 'input_schema' => [
118 'type' => 'object',
119 'required' => [ 'post_id', 'widget_type' ],
120 'properties' => [
121 'post_id' => [
122 'type' => 'integer',
123 'description' => __( 'Target Elementor document id.', 'elementskit-lite' ),
124 ],
125 'parent_id' => [
126 'type' => 'string',
127 'description' => __( 'Container id to append to, or "document" for the document root.', 'elementskit-lite' ),
128 'default' => 'document',
129 ],
130 'widget_type' => [
131 'type' => 'string',
132 'description' => __( 'ElementsKit widget name, e.g. "elementskit-heading".', 'elementskit-lite' ),
133 ],
134 'settings' => [
135 'type' => 'object',
136 'description' => __( 'Elementor control settings for the widget.', 'elementskit-lite' ),
137 ],
138 ],
139 ],
140 'output_schema' => [
141 'type' => 'object',
142 'properties' => [
143 'success' => [ 'type' => 'boolean' ],
144 'post_id' => [ 'type' => 'integer' ],
145 'element_id' => [ 'type' => 'string' ],
146 'inserted_root_ids' => [ 'type' => 'array' ],
147 'preview_url' => [ 'type' => 'string' ],
148 'version' => [ 'type' => 'string' ],
149 ],
150 ],
151 'execute_callback' => static function ( $input ) {
152 return ( new Service() )->insert_widget( is_array( $input ) ? $input : [] );
153 },
154 'permission_callback' => static function ( $input ) {
155 $post_id = is_array( $input ) && isset( $input['post_id'] ) ? (int) $input['post_id'] : 0;
156
157 return current_user_can( 'edit_posts' ) && $post_id > 0 && current_user_can( 'edit_post', $post_id );
158 },
159 ]
160 );
161
162 wp_register_ability(
163 'elementskit/list-templates',
164 [
165 'label' => __( 'List ElementsKit templates', 'elementskit-lite' ),
166 'description' => __( 'List the available ElementsKit templates.', 'elementskit-lite' ),
167 'category' => self::CATEGORY,
168 'input_schema' => [
169 'type' => 'object',
170 'properties' => [
171 'type' => [
172 'type' => 'string',
173 'description' => __( 'Optional template type filter (e.g. header, footer).', 'elementskit-lite' ),
174 ],
175 'search' => [
176 'type' => 'string',
177 'description' => __( 'Optional title search term.', 'elementskit-lite' ),
178 ],
179 'per_page' => [
180 'type' => 'integer',
181 'description' => __( 'Maximum number of templates to return (1-100).', 'elementskit-lite' ),
182 ],
183 ],
184 ],
185 'output_schema' => [
186 'type' => 'object',
187 'properties' => [
188 'success' => [ 'type' => 'boolean' ],
189 'count' => [ 'type' => 'integer' ],
190 'templates' => [ 'type' => 'array' ],
191 ],
192 ],
193 'execute_callback' => static function ( $input ) {
194 return ( new Service() )->list_templates( is_array( $input ) ? $input : [] );
195 },
196 'permission_callback' => static function () {
197 return current_user_can( 'edit_posts' );
198 },
199 ]
200 );
201
202 wp_register_ability(
203 'elementskit/insert-template',
204 [
205 'label' => __( 'Insert ElementsKit template', 'elementskit-lite' ),
206 'description' => __( 'Insert an ElementsKit template into an Elementor document.', 'elementskit-lite' ),
207 'category' => self::CATEGORY,
208 'input_schema' => [
209 'type' => 'object',
210 'required' => [ 'post_id', 'template_id' ],
211 'properties' => [
212 'post_id' => [
213 'type' => 'integer',
214 'description' => __( 'Target Elementor document id.', 'elementskit-lite' ),
215 ],
216 'template_id' => [
217 'type' => 'integer',
218 'description' => __( 'Source ElementsKit template id.', 'elementskit-lite' ),
219 ],
220 ],
221 ],
222 'output_schema' => [
223 'type' => 'object',
224 'properties' => [
225 'success' => [ 'type' => 'boolean' ],
226 'post_id' => [ 'type' => 'integer' ],
227 'template_id' => [ 'type' => 'integer' ],
228 'inserted_root_ids' => [ 'type' => 'array' ],
229 'preview_url' => [ 'type' => 'string' ],
230 'version' => [ 'type' => 'string' ],
231 ],
232 ],
233 'execute_callback' => static function ( $input ) {
234 return ( new Service() )->insert_template( is_array( $input ) ? $input : [] );
235 },
236 'permission_callback' => static function ( $input ) {
237 $post_id = is_array( $input ) && isset( $input['post_id'] ) ? (int) $input['post_id'] : 0;
238
239 return current_user_can( 'edit_posts' ) && $post_id > 0 && current_user_can( 'edit_post', $post_id );
240 },
241 ]
242 );
243
244 $this->register_build_abilities();
245 $this->register_mega_menu_abilities();
246 $this->register_library_abilities();
247 }
248
249 /**
250 * Create-page / create-template / custom-widget abilities.
251 */
252 private function register_build_abilities() {
253 wp_register_ability(
254 'elementskit/create-page',
255 [
256 'label' => __( 'Create page with ElementsKit', 'elementskit-lite' ),
257 'description' => __( 'Create a new Elementor page or post, optionally seeded with an element tree of ElementsKit widgets and containers.', 'elementskit-lite' ),
258 'category' => self::CATEGORY,
259 'input_schema' => [
260 'type' => 'object',
261 'properties' => [
262 'title' => [ 'type' => 'string', 'description' => __( 'Page title.', 'elementskit-lite' ) ],
263 'post_type' => [ 'type' => 'string', 'enum' => [ 'page', 'post' ], 'default' => 'page' ],
264 'canvas' => [ 'type' => 'boolean', 'description' => __( 'Use the Elementor Canvas template.', 'elementskit-lite' ), 'default' => true ],
265 'elements' => [ 'type' => 'array', 'description' => __( 'Elementor element tree to seed the page with.', 'elementskit-lite' ) ],
266 ],
267 ],
268 'output_schema' => [
269 'type' => 'object',
270 'properties' => [
271 'success' => [ 'type' => 'boolean' ],
272 'post_id' => [ 'type' => 'integer' ],
273 'post_type' => [ 'type' => 'string' ],
274 'post_status' => [ 'type' => 'string', 'description' => __( 'Published when the user can publish this post type, otherwise draft.', 'elementskit-lite' ) ],
275 'edit_url' => [ 'type' => 'string' ],
276 'preview_url' => [ 'type' => 'string' ],
277 'note' => [ 'type' => 'string' ],
278 ],
279 ],
280 'execute_callback' => static function ( $input ) {
281 return ( new Service() )->create_page( is_array( $input ) ? $input : [] );
282 },
283 'permission_callback' => static function () {
284 return current_user_can( 'edit_pages' ) || current_user_can( 'edit_posts' );
285 },
286 ]
287 );
288
289 wp_register_ability(
290 'elementskit/create-template',
291 [
292 'label' => __( 'Create ElementsKit template', 'elementskit-lite' ),
293 'description' => __( 'Create an ElementsKit header, footer, or section template, optionally seeded with an Elementor element tree.', 'elementskit-lite' ),
294 'category' => self::CATEGORY,
295 'input_schema' => [
296 'type' => 'object',
297 'properties' => [
298 'title' => [ 'type' => 'string' ],
299 'type' => [ 'type' => 'string', 'enum' => [ 'header', 'footer', 'section' ], 'default' => 'section' ],
300 'activation' => [ 'type' => 'string', 'enum' => [ 'yes', 'no' ], 'default' => 'no' ],
301 'condition' => [ 'type' => 'string', 'description' => __( 'Display condition for header/footer templates.', 'elementskit-lite' ) ],
302 'elements' => [ 'type' => 'array' ],
303 ],
304 ],
305 'output_schema' => [
306 'type' => 'object',
307 'properties' => [
308 'success' => [ 'type' => 'boolean' ],
309 'id' => [ 'type' => 'integer' ],
310 'type' => [ 'type' => 'string' ],
311 'edit_url' => [ 'type' => 'string' ],
312 ],
313 ],
314 'execute_callback' => static function ( $input ) {
315 return ( new Service() )->create_template( is_array( $input ) ? $input : [] );
316 },
317 'permission_callback' => static function () {
318 return current_user_can( 'manage_options' );
319 },
320 ]
321 );
322
323 wp_register_ability(
324 'elementskit/create-header-footer',
325 [
326 'label' => __( 'Create ElementsKit header/footer', 'elementskit-lite' ),
327 'description' => __( 'Create an ElementsKit header or footer, activated site-wide so it displays. Optionally build it from a ready-made ElementsKit Template Library template (pass template_id from list-library-templates).', 'elementskit-lite' ),
328 'category' => self::CATEGORY,
329 'input_schema' => [
330 'type' => 'object',
331 'properties' => [
332 'type' => [ 'type' => 'string', 'enum' => [ 'header', 'footer' ], 'default' => 'header' ],
333 'title' => [ 'type' => 'string' ],
334 'condition' => [ 'type' => 'string', 'description' => __( 'Display condition. Defaults to entire_site.', 'elementskit-lite' ), 'default' => 'entire_site' ],
335 'activation' => [ 'type' => 'string', 'enum' => [ 'yes', 'no' ], 'default' => 'yes' ],
336 'template_id' => [ 'type' => 'string', 'description' => __( 'Library template id to build the header/footer from.', 'elementskit-lite' ) ],
337 'elements' => [ 'type' => 'array', 'description' => __( 'Element tree to seed with (ignored if template_id is given).', 'elementskit-lite' ) ],
338 ],
339 ],
340 'output_schema' => [
341 'type' => 'object',
342 'properties' => [
343 'success' => [ 'type' => 'boolean' ],
344 'id' => [ 'type' => 'integer' ],
345 'type' => [ 'type' => 'string' ],
346 'activated' => [ 'type' => 'boolean' ],
347 'condition' => [ 'type' => 'string' ],
348 'edit_url' => [ 'type' => 'string' ],
349 'preview_url' => [ 'type' => 'string' ],
350 ],
351 ],
352 'execute_callback' => static function ( $input ) {
353 return ( new Service() )->create_header_footer( is_array( $input ) ? $input : [] );
354 },
355 'permission_callback' => static function () {
356 return current_user_can( 'manage_options' );
357 },
358 ]
359 );
360
361 wp_register_ability(
362 'elementskit/list-custom-widgets',
363 [
364 'label' => __( 'List ElementsKit custom widgets', 'elementskit-lite' ),
365 'description' => __( 'List custom widgets built with the ElementsKit Widget Builder.', 'elementskit-lite' ),
366 'category' => self::CATEGORY,
367 'input_schema' => [ 'type' => 'object', 'properties' => [] ],
368 'output_schema' => [
369 'type' => 'object',
370 'properties' => [
371 'success' => [ 'type' => 'boolean' ],
372 'count' => [ 'type' => 'integer' ],
373 'widgets' => [ 'type' => 'array' ],
374 ],
375 ],
376 'execute_callback' => static function ( $input ) {
377 return ( new Service() )->list_custom_widgets( is_array( $input ) ? $input : [] );
378 },
379 'permission_callback' => static function () {
380 return current_user_can( 'manage_options' );
381 },
382 ]
383 );
384
385 wp_register_ability(
386 'elementskit/create-custom-widget',
387 [
388 'label' => __( 'Create ElementsKit custom widget', 'elementskit-lite' ),
389 'description' => __( 'Build a custom Elementor widget with the ElementsKit Widget Builder (title, icon, categories, markup, CSS, JS and control tabs). Pass an id to update an existing one.', 'elementskit-lite' ),
390 'category' => self::CATEGORY,
391 'input_schema' => [
392 'type' => 'object',
393 'required' => [ 'title' ],
394 'properties' => [
395 'id' => [ 'type' => 'integer', 'description' => __( 'Existing elementskit_widget id to update.', 'elementskit-lite' ) ],
396 'title' => [ 'type' => 'string' ],
397 'icon' => [ 'type' => 'string', 'default' => 'eicon-cog' ],
398 'categories' => [ 'type' => 'array', 'items' => [ 'type' => 'string' ] ],
399 'markup' => [ 'type' => 'string' ],
400 'css' => [ 'type' => 'string' ],
401 'js' => [ 'type' => 'string' ],
402 'tabs' => [ 'type' => 'object', 'additionalProperties' => true ],
403 ],
404 ],
405 'output_schema' => [
406 'type' => 'object',
407 'properties' => [
408 'success' => [ 'type' => 'boolean' ],
409 'id' => [ 'type' => 'integer' ],
410 ],
411 ],
412 'execute_callback' => static function ( $input ) {
413 return ( new Service() )->create_custom_widget( is_array( $input ) ? $input : [] );
414 },
415 'permission_callback' => static function () {
416 return current_user_can( 'manage_options' );
417 },
418 ]
419 );
420 }
421
422 /**
423 * Mega menu abilities.
424 */
425 private function register_mega_menu_abilities() {
426 wp_register_ability(
427 'elementskit/list-mega-menus',
428 [
429 'label' => __( 'List mega menus', 'elementskit-lite' ),
430 'description' => __( 'List WordPress nav menus with their ElementsKit Mega Menu enable state and items. Use it to resolve a menu id / menu-item id.', 'elementskit-lite' ),
431 'category' => self::CATEGORY,
432 'input_schema' => [ 'type' => 'object', 'properties' => [] ],
433 'output_schema' => [
434 'type' => 'object',
435 'properties' => [
436 'success' => [ 'type' => 'boolean' ],
437 'menus' => [ 'type' => 'array' ],
438 ],
439 ],
440 'execute_callback' => static function ( $input ) {
441 return ( new Service() )->list_mega_menus( is_array( $input ) ? $input : [] );
442 },
443 'permission_callback' => static function () {
444 return current_user_can( 'edit_theme_options' );
445 },
446 ]
447 );
448
449 wp_register_ability(
450 'elementskit/enable-mega-menu',
451 [
452 'label' => __( 'Enable mega menu for a menu', 'elementskit-lite' ),
453 'description' => __( 'Enable or disable ElementsKit Mega Menu for an entire nav menu location (the menu-wide switch).', 'elementskit-lite' ),
454 'category' => self::CATEGORY,
455 'input_schema' => [
456 'type' => 'object',
457 'required' => [ 'menu_id' ],
458 'properties' => [
459 'menu_id' => [ 'type' => 'integer', 'description' => __( 'The nav menu term id.', 'elementskit-lite' ) ],
460 'enabled' => [ 'type' => 'boolean', 'default' => true ],
461 ],
462 ],
463 'output_schema' => [
464 'type' => 'object',
465 'properties' => [
466 'success' => [ 'type' => 'boolean' ],
467 'menu_id' => [ 'type' => 'integer' ],
468 'enabled' => [ 'type' => 'boolean' ],
469 ],
470 ],
471 'execute_callback' => static function ( $input ) {
472 return ( new Service() )->enable_mega_menu( is_array( $input ) ? $input : [] );
473 },
474 'permission_callback' => static function () {
475 return current_user_can( 'manage_options' );
476 },
477 ]
478 );
479
480 wp_register_ability(
481 'elementskit/update-mega-menu-item',
482 [
483 'label' => __( 'Update mega menu item', 'elementskit-lite' ),
484 'description' => __( 'Enable and configure the ElementsKit Mega Menu panel on a nav-menu item, and optionally set the Elementor element tree shown as the panel content.', 'elementskit-lite' ),
485 'category' => self::CATEGORY,
486 'input_schema' => [
487 'type' => 'object',
488 'required' => [ 'menu_item_id' ],
489 'properties' => [
490 'menu_item_id' => [ 'type' => 'integer', 'description' => __( 'The nav_menu_item post id.', 'elementskit-lite' ) ],
491 'settings' => [ 'type' => 'object', 'additionalProperties' => true ],
492 'elements' => [ 'type' => 'array', 'description' => __( 'Elementor element tree for the panel content.', 'elementskit-lite' ) ],
493 ],
494 ],
495 'output_schema' => [
496 'type' => 'object',
497 'properties' => [
498 'success' => [ 'type' => 'boolean' ],
499 'menu_item_id' => [ 'type' => 'integer' ],
500 ],
501 ],
502 'execute_callback' => static function ( $input ) {
503 return ( new Service() )->update_mega_menu_item( is_array( $input ) ? $input : [] );
504 },
505 'permission_callback' => static function () {
506 return current_user_can( 'manage_options' );
507 },
508 ]
509 );
510
511 wp_register_ability(
512 'elementskit/create-mega-menu',
513 [
514 'label' => __( 'Create ElementsKit mega menu', 'elementskit-lite' ),
515 'description' => __( 'One-shot mega menu creation: create (or reuse) a nav menu, add a top-level item, switch Mega Menu on and enable + configure the panel on that item, optionally seeded with an Elementor element tree.', 'elementskit-lite' ),
516 'category' => self::CATEGORY,
517 'input_schema' => [
518 'type' => 'object',
519 'properties' => [
520 'menu_name' => [ 'type' => 'string', 'description' => __( 'Name for a new nav menu (used when menu_id is absent).', 'elementskit-lite' ) ],
521 'menu_id' => [ 'type' => 'integer', 'description' => __( 'Existing nav menu term id to add the item to.', 'elementskit-lite' ) ],
522 'item_title' => [ 'type' => 'string', 'description' => __( 'Label of the top-level item that opens the panel.', 'elementskit-lite' ) ],
523 'item_url' => [ 'type' => 'string', 'description' => __( 'Link for the item. Defaults to "#".', 'elementskit-lite' ) ],
524 'template_id' => [ 'type' => 'string', 'description' => __( 'ElementsKit Template Library id to fill the panel with (from list-library-templates). The panel is populated on the backend so it never previews blank.', 'elementskit-lite' ) ],
525 'settings' => [ 'type' => 'object', 'additionalProperties' => true, 'description' => __( 'Mega menu item settings (menu_icon, menu_badge_text, megamenu_width_type, ...).', 'elementskit-lite' ) ],
526 'elements' => [ 'type' => 'array', 'description' => __( 'Elementor element tree for the panel content (used when template_id is absent).', 'elementskit-lite' ) ],
527 ],
528 ],
529 'output_schema' => [
530 'type' => 'object',
531 'properties' => [
532 'success' => [ 'type' => 'boolean' ],
533 'menu_id' => [ 'type' => 'integer' ],
534 'menu_item_id' => [ 'type' => 'integer' ],
535 'menu_name' => [ 'type' => 'string' ],
536 'manage_url' => [ 'type' => 'string' ],
537 ],
538 ],
539 'execute_callback' => static function ( $input ) {
540 return ( new Service() )->create_mega_menu( is_array( $input ) ? $input : [] );
541 },
542 'permission_callback' => static function () {
543 return current_user_can( 'manage_options' ) && current_user_can( 'edit_theme_options' );
544 },
545 ]
546 );
547 }
548
549 /**
550 * Template-library abilities.
551 */
552 private function register_library_abilities() {
553 wp_register_ability(
554 'elementskit/list-library-templates',
555 [
556 'label' => __( 'List template library', 'elementskit-lite' ),
557 'description' => __( 'List ready-made templates, sections and pages from the ElementsKit Template Library.', 'elementskit-lite' ),
558 'category' => self::CATEGORY,
559 'input_schema' => [ 'type' => 'object', 'properties' => [] ],
560 'output_schema' => [
561 'type' => 'object',
562 'properties' => [
563 'success' => [ 'type' => 'boolean' ],
564 'library' => [ 'type' => 'array' ],
565 ],
566 ],
567 'execute_callback' => static function ( $input ) {
568 return ( new Service() )->list_library_templates( is_array( $input ) ? $input : [] );
569 },
570 'permission_callback' => static function () {
571 return current_user_can( 'edit_posts' );
572 },
573 ]
574 );
575
576 wp_register_ability(
577 'elementskit/import-library-template',
578 [
579 'label' => __( 'Import template from library', 'elementskit-lite' ),
580 'description' => __( 'Import a ready-made template, section or page from the ElementsKit Template Library into an Elementor document.', 'elementskit-lite' ),
581 'category' => self::CATEGORY,
582 'input_schema' => [
583 'type' => 'object',
584 'required' => [ 'post_id', 'template_id' ],
585 'properties' => [
586 'post_id' => [ 'type' => 'integer', 'description' => __( 'Target Elementor document id.', 'elementskit-lite' ) ],
587 'template_id' => [ 'type' => 'string', 'description' => __( 'Library template id.', 'elementskit-lite' ) ],
588 ],
589 ],
590 'output_schema' => [
591 'type' => 'object',
592 'properties' => [
593 'success' => [ 'type' => 'boolean' ],
594 'post_id' => [ 'type' => 'integer' ],
595 'template_id' => [ 'type' => 'string' ],
596 'inserted_root_ids' => [ 'type' => 'array' ],
597 'preview_url' => [ 'type' => 'string' ],
598 ],
599 ],
600 'execute_callback' => static function ( $input ) {
601 return ( new Service() )->import_library_template( is_array( $input ) ? $input : [] );
602 },
603 'permission_callback' => static function ( $input ) {
604 $post_id = is_array( $input ) && isset( $input['post_id'] ) ? (int) $input['post_id'] : 0;
605
606 return current_user_can( 'edit_posts' ) && $post_id > 0 && current_user_can( 'edit_post', $post_id );
607 },
608 ]
609 );
610 }
611 }
612