/var/www/html_it/wp-content/plugins/elementor/core/editor/data/globals/endpoints/base.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace Elementor\Core\Editor\Data\Globals\Endpoints;

use 
Elementor\Data\V2\Base\Endpoint;
use 
Elementor\Data\V2\Base\Exceptions\Data_Exception;
use 
Elementor\Data\V2\Base\Exceptions\Error_404;
use 
Elementor\Plugin;

abstract class 
Base extends Endpoint {
    protected function 
register() {
        
parent::register();

        
$args = [
            
'id_arg_type_regex' => '[\w]+',
        ];

        
$this->register_item_route\WP_REST_Server::READABLE$args );
        
$this->register_item_route\WP_REST_Server::CREATABLE$args );
        
$this->register_item_route\WP_REST_Server::DELETABLE$args );
    }

    public function 
get_items$request ) {
        return 
$this->get_kit_items();
    }

    
/**
     * @inheritDoc
     * @throws \Elementor\Data\V2\Base\Exceptions\Error_404
     */
    
public function get_item$id$request ) {
        
$items $this->get_kit_items();

        if ( ! isset( 
$items$id ] ) ) {
            throw new 
Error_404esc_html__'The Global value you are trying to use is not available.''elementor' ),
                
'global_not_found'
            
);
        }

        return 
$items$id ];
    }

    public function 
create_item$id$request ) {
        
$item $request->get_body_params();

        if ( ! isset( 
$item['title'] ) ) {
            return new 
Data_Exceptionesc_html__'Invalid title''elementor' ), 'invalid_title' );
        }

        
$kit Plugin::$instance->kits_manager->get_active_kit();

        
$item['id'] = $id;

        
$db_item $this->convert_db_format$item );

        
$kit->add_repeater_row'custom_' $this->get_name(), $db_item );

        return 
$item;
    }

    abstract protected function 
get_kit_items();

    
/**
     * @param array $item frontend format.
     * @return array backend format.
     */
    
abstract protected function convert_db_format$item );
}