PluginProbe
Elementor Website Builder – more than just a page builder / 4.1.5
Elementor Website Builder – more than just a page builder v4.1.5
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 / modules / favorites / controller.php

controller.php in Elementor Website Builder – more than just a page builder 4.1.5, at modules/favorites/controller.php

85 lines 2.0 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\Favorites;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit; // Exit if accessed directly.
7 }
8
9 use Elementor\Data\V2\Base\Controller as Controller_Base;
10 use Elementor\Plugin;
11
12 class Controller extends Controller_Base {
13
14 public function get_name() {
15 return 'favorites';
16 }
17
18 public function create_item( $request ) {
19 $module = $this->get_module();
20 $type = $request->get_param( 'id' );
21 $favorite = $request->get_param( 'favorite' );
22
23 $module->update( $type, $favorite, $module::ACTION_MERGE );
24
25 return $module->get( $type );
26 }
27
28 public function delete_item( $request ) {
29 $module = $this->get_module();
30 $type = $request->get_param( 'id' );
31 $favorite = $request->get_param( 'favorite' );
32
33 $module->update( $type, $favorite, $module::ACTION_DELETE );
34
35 return $module->get( $type );
36 }
37
38 public function create_item_permissions_check( $request ) {
39 return current_user_can( 'edit_posts' );
40 }
41
42 public function delete_item_permissions_check( $request ) {
43 return $this->create_item_permissions_check( $request );
44 }
45
46 /**
47 * Get the favorites module instance.
48 *
49 * @return Module
50 */
51 protected function get_module() {
52 return Plugin::instance()->modules_manager->get_modules( 'favorites' );
53 }
54
55 public function register_endpoints() {
56 $this->index_endpoint->register_item_route( \WP_REST_Server::CREATABLE, [
57 'id_arg_type_regex' => '[\w]+',
58 'id' => [
59 'description' => 'Type of favorites.',
60 'type' => 'string',
61 'required' => true,
62 ],
63 'favorite' => [
64 'description' => 'The favorite slug to create.',
65 'type' => 'string',
66 'required' => true,
67 ],
68 ] );
69
70 $this->index_endpoint->register_item_route( \WP_REST_Server::DELETABLE, [
71 'id_arg_type_regex' => '[\w]+',
72 'id' => [
73 'description' => 'Type of favorites.',
74 'type' => 'string',
75 'required' => true,
76 ],
77 'favorite' => [
78 'description' => 'The favorite slug to delete.',
79 'type' => 'string',
80 'required' => true,
81 ],
82 ] );
83 }
84 }
85