PluginProbe
Elementor Website Builder – more than just a page builder / 3.6.0-dev10
Elementor Website Builder – more than just a page builder v3.6.0-dev10
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 4.0.7 All 451 releases
elementor / core / editor / data / widgets-config / controller.php

controller.php in Elementor Website Builder – more than just a page builder 3.6.0-dev10, at core/editor/data/widgets-config/controller.php

83 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Editor\Data\WidgetsConfig;
3
4 use Elementor\Core\Utils\Collection;
5 use Elementor\Data\V2\Base\Controller as Controller_Base;
6 use Elementor\Plugin;
7
8 class Controller extends Controller_Base {
9 public function get_name() {
10 return 'widgets-config';
11 }
12
13 public function register_endpoints() {
14 $this->index_endpoint->register_item_route(
15 \WP_REST_Server::READABLE,
16 [
17 'id_arg_type_regex' => '[\w]+',
18 'exclude' => [
19 'description' => 'ids of widgets that should be excluded',
20 'type' => 'array',
21 'default' => [],
22 'items' => [
23 'type' => 'string',
24 ],
25 ],
26 ]
27 );
28 }
29
30 public function get_items_args( $methods ) {
31 return [
32 'exclude' => [
33 'description' => 'ids of widgets that should be excluded',
34 'type' => 'array',
35 'default' => [],
36 'items' => [
37 'type' => 'string',
38 ],
39 ],
40 ];
41 }
42
43 public function get_items( $request ) {
44 $config = ( new Collection( Plugin::$instance->widgets_manager->get_widget_types() ) );
45
46 $exclude = $request->get_param( 'exclude' );
47
48 if ( ! empty( $exclude ) ) {
49 $config = $config->filter( function ( $widget, $widget_key ) use ( $exclude ) {
50 return ! in_array( $widget_key, $exclude, true );
51 } );
52 }
53
54 return (object) $config
55 ->map( function ( $widget ) {
56 return $this->prepare_for_response( $widget );
57 } )
58 ->all();
59 }
60
61 public function get_item( $request ) {
62 $widget = Plugin::$instance->widgets_manager->get_widget_types( $request->get_param( 'id' ) );
63
64 return (object) $this->prepare_for_response( $widget );
65 }
66
67 public function get_permission_callback( $request ) {
68 return current_user_can( 'edit_posts' );
69 }
70
71 /**
72 * @param $widget
73 *
74 * @return array
75 */
76 private function prepare_for_response( $widget ) {
77 return [
78 'controls' => $widget->get_stack( false )['controls'],
79 'tabs_controls' => $widget->get_tabs_controls(),
80 ];
81 }
82 }
83