PluginProbe
Elementor Website Builder – more than just a page builder / 3.27.0-dev2
Elementor Website Builder – more than just a page builder v3.27.0-dev2
4.3.0 4.3.0-beta3 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 All 453 releases
elementor / modules / wp-rest / classes / elementor-post-meta.php

elementor-post-meta.php in Elementor Website Builder – more than just a page builder 3.27.0-dev2, at modules/wp-rest/classes/elementor-post-meta.php

122 lines 3.2 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\WpRest\Classes;
4
5 use Elementor\Plugin;
6 use Elementor\Utils;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 class Elementor_Post_Meta {
13
14 public function register(): void {
15 $post_types = get_post_types_by_support( 'elementor' );
16
17 foreach ( $post_types as $post_type ) {
18 register_meta( $post_type, '_elementor_edit_mode', [
19 'single' => true,
20 'show_in_rest' => [
21 'schema' => [
22 'title' => 'Elementor edit mode',
23 'description' => 'Elementor edit mode, `builder` is required for Elementor editing',
24 'type' => 'string',
25 'enum' => [ '', 'builder' ],
26 'default' => '',
27 'context' => [ 'edit' ],
28 ],
29 ],
30 'auth_callback' => [ $this, 'check_edit_permission' ],
31 ]);
32
33 $document_types = Plugin::$instance->documents->get_document_types();
34
35 register_meta( $post_type, '_elementor_template_type', [
36 'single' => true,
37 'show_in_rest' => [
38 'schema' => [
39 'title' => 'Elementor template type',
40 'description' => 'Elementor document type',
41 'type' => 'string',
42 'enum' => array_merge( array_keys( $document_types ), [ '' ] ),
43 'default' => '',
44 'context' => [ 'edit' ],
45 ],
46 ],
47 'auth_callback' => [ $this, 'check_edit_permission' ],
48 ]);
49
50 register_meta( $post_type, '_elementor_data', [
51 'single' => true,
52 'show_in_rest' => [
53 'schema' => [
54 'title' => 'Elementor data',
55 'description' => 'Elementor JSON as a string',
56 'type' => 'string',
57 'default' => '',
58 'context' => [ 'edit' ],
59 ],
60 ],
61 'auth_callback' => [ $this, 'check_edit_permission' ],
62 ]);
63
64 register_meta( $post_type, '_elementor_page_settings', [
65 'single' => true,
66 'show_in_rest' => [
67 'schema' => [
68 'title' => 'Elementor page settings',
69 'description' => 'Elementor page level settings',
70 'type' => 'object',
71 'properties' => [
72 'hide_title' => [
73 'type' => 'string',
74 'enum' => [ 'yes', 'no' ],
75 'default' => '',
76 ],
77 ],
78 'default' => '{}',
79 'additionalProperties' => true,
80 'context' => [ 'edit' ],
81 ],
82 ],
83 'auth_callback' => [ $this, 'check_edit_permission' ],
84 ]);
85
86 if ( Utils::has_pro() ) {
87 register_meta( $post_type, '_elementor_conditions', [
88 'type' => 'object',
89 'title' => 'Elementor conditions',
90 'description' => 'Elementor conditions',
91 'single' => true,
92 'show_in_rest' => [
93 'schema' => [
94 'description' => 'Elementor conditions',
95 'type' => 'array',
96 'additionalProperties' => true,
97 'default' => [],
98 'context' => [ 'edit' ],
99 ],
100 ],
101 'auth_callback' => [ $this, 'check_edit_permission' ],
102 ]);
103 }
104 }
105 }
106
107 /**
108 * Check if current user has permission to edit the specific post with elementor
109 *
110 * @param bool $allowed Whether the user can add the post meta. Default false.
111 * @param string $meta_key The meta key.
112 * @param int $post_id Post ID.
113 * @return bool
114 * @since 3.27.0
115 */
116 public function check_edit_permission( bool $allowed, string $meta_key, int $post_id ): bool {
117 $document = Plugin::$instance->documents->get( $post_id );
118
119 return $document && $document->is_editable_by_current_user();
120 }
121 }
122