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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
<?php
namespace Elementor\Modules\WpRest\Classes;
use Elementor\Plugin; use Elementor\Utils;
if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. }
class Elementor_Post_Meta {
public function register(): void { $post_types = get_post_types_by_support( 'elementor' );
foreach ( $post_types as $post_type ) { $this->register_edit_mode_meta( $post_type ); $this->register_template_type_meta( $post_type ); $this->register_elementor_data_meta( $post_type ); $this->register_page_settings_meta( $post_type );
if ( Utils::has_pro() ) { $this->register_conditions_meta( $post_type ); } } }
private function register_edit_mode_meta( string $post_type ): void { register_meta( 'post', '_elementor_edit_mode', [ 'single' => true, 'object_subtype' => $post_type, 'show_in_rest' => [ 'schema' => [ 'title' => 'Elementor edit mode', 'description' => 'Elementor edit mode, `builder` is required for Elementor editing', 'type' => 'string', 'enum' => [ '', 'builder' ], 'default' => '', 'context' => [ 'edit' ], ], ], 'auth_callback' => [ $this, 'check_edit_permission' ], ]); }
private function register_template_type_meta( string $post_type ): void { $document_types = Plugin::$instance->documents->get_document_types();
register_meta( 'post', '_elementor_template_type', [ 'single' => true, 'object_subtype' => $post_type, 'show_in_rest' => [ 'schema' => [ 'title' => 'Elementor template type', 'description' => 'Elementor document type', 'type' => 'string', 'enum' => array_merge( array_keys( $document_types ), [ '' ] ), 'default' => '', 'context' => [ 'edit' ], ], ], 'auth_callback' => [ $this, 'check_edit_permission' ], ]); }
private function register_elementor_data_meta( string $post_type ): void { register_meta( 'post', '_elementor_data', [ 'single' => true, 'object_subtype' => $post_type, 'show_in_rest' => [ 'schema' => [ 'title' => 'Elementor data', 'description' => 'Elementor JSON as a string', 'type' => 'string', 'default' => '', 'context' => [ 'edit' ], ], ], 'auth_callback' => [ $this, 'check_edit_permission' ], ]); }
private function register_page_settings_meta( string $post_type ): void { register_meta( 'post', '_elementor_page_settings', [ 'single' => true, 'object_subtype' => $post_type, 'type' => 'object', 'show_in_rest' => [ 'schema' => [ 'title' => 'Elementor page settings', 'description' => 'Elementor page level settings', 'type' => 'object', 'properties' => [ 'hide_title' => [ 'type' => 'string', 'enum' => [ 'yes', 'no' ], 'default' => '', ], ], 'default' => '{}', 'additionalProperties' => true, 'context' => [ 'edit' ], ], ], 'auth_callback' => [ $this, 'check_edit_permission' ], ]); }
private function register_conditions_meta( string $post_type ): void { register_meta( 'post', '_elementor_conditions', [ 'object_subtype' => $post_type, 'type' => 'object', 'title' => 'Elementor conditions', 'description' => 'Elementor conditions', 'single' => true, 'show_in_rest' => [ 'schema' => [ 'description' => 'Elementor conditions', 'type' => 'array', 'additionalProperties' => true, 'default' => [], 'context' => [ 'edit' ], ], ], 'auth_callback' => [ $this, 'check_edit_permission' ], ]); }
/** * Check if current user has permission to edit the specific post with elementor * * @param bool $allowed Whether the user can add the post meta. Default false. * @param string $meta_key The meta key. * @param int $post_id Post ID. * @return bool * @since 3.27.0 */ public function check_edit_permission( bool $allowed, string $meta_key, int $post_id ): bool { $document = Plugin::$instance->documents->get( $post_id );
return $document && $document->is_editable_by_current_user(); } }
|