PluginProbe
Elementor Website Builder – more than just a page builder / 4.1.0-beta3
Elementor Website Builder – more than just a page builder v4.1.0-beta3
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 4.1.0-dev1 All 452 releases
elementor / modules / mcp / abilities / update-settings-ability.php

update-settings-ability.php in Elementor Website Builder – more than just a page builder 4.1.0-beta3, at modules/mcp/abilities/update-settings-ability.php

91 lines 2.8 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\Mcp\Abilities;
4
5 use Elementor\Plugin;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 class Update_Settings_Ability extends Abstract_Ability {
12
13 protected function get_ability_id(): string {
14 return 'elementor/update-page-settings';
15 }
16
17 protected function get_definition(): Ability_Definition {
18 return new Ability_Definition(
19 __( 'Update Elementor Page Settings', 'elementor' ),
20 __( 'Updates Elementor document-level settings for a post (for example page layout, title visibility, or custom page settings). Pass only the keys you want to change. Use list-pages to resolve IDs and get-page-structure when you also need the element tree. Requires permission to edit the target post.', 'elementor' ),
21 'elementor',
22 [
23 'type' => 'object',
24 'properties' => [
25 'success' => [ 'type' => 'boolean' ],
26 'post_id' => [ 'type' => 'integer' ],
27 ],
28 ],
29 [
30 'annotations' => [
31 'readonly' => false,
32 'idempotent' => false,
33 'destructive' => false,
34 ],
35 ],
36 function () {
37 return current_user_can( 'edit_posts' );
38 },
39 [
40 'type' => 'object',
41 'required' => [ 'post_id', 'settings' ],
42 'properties' => [
43 'post_id' => [
44 'type' => 'integer',
45 'description' => 'WordPress post ID of the Elementor document.',
46 ],
47 'settings' => [
48 'type' => 'object',
49 'description' => 'Partial document settings object; merged into existing settings. Schema enforcement is delegated to document->save().',
50 'additionalProperties' => true,
51 ],
52 ],
53 ]
54 );
55 }
56
57 public function execute( $input = [] ) {
58 $post_id = isset( $input['post_id'] ) ? absint( $input['post_id'] ) : 0;
59 $settings = isset( $input['settings'] ) && is_array( $input['settings'] ) ? $input['settings'] : null;
60
61 if ( ! $post_id ) {
62 return new \WP_Error( 'invalid_post_id', __( 'A valid post_id is required.', 'elementor' ), [ 'status' => \WP_Http::BAD_REQUEST ] );
63 }
64
65 if ( null === $settings ) {
66 return new \WP_Error( 'invalid_settings', __( 'The settings object is required.', 'elementor' ), [ 'status' => \WP_Http::BAD_REQUEST ] );
67 }
68
69 $document = Plugin::$instance->documents->get( $post_id );
70
71 if ( ! $document ) {
72 return new \WP_Error( 'document_not_found', __( 'Document not found.', 'elementor' ), [ 'status' => \WP_Http::NOT_FOUND ] );
73 }
74
75 if ( ! $document->is_editable_by_current_user() ) {
76 return new \WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to edit this document.', 'elementor' ), [ 'status' => \WP_Http::FORBIDDEN ] );
77 }
78
79 $saved = $document->save( [ 'settings' => $settings ] );
80
81 if ( ! $saved ) {
82 return new \WP_Error( 'save_failed', __( 'Could not save document settings.', 'elementor' ), [ 'status' => \WP_Http::INTERNAL_SERVER_ERROR ] );
83 }
84
85 return [
86 'success' => true,
87 'post_id' => $post_id,
88 ];
89 }
90 }
91