PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.5
Elementor Website Builder – more than just a page builder v4.0.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 / app / modules / onboarding / data / endpoints / user-choices.php

user-choices.php in Elementor Website Builder – more than just a page builder 4.0.5, at app/modules/onboarding/data/endpoints/user-choices.php

79 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\App\Modules\Onboarding\Data\Endpoints;
4
5 use Elementor\App\Modules\Onboarding\Storage\Onboarding_Progress_Manager;
6 use Elementor\App\Modules\Onboarding\Validation\User_Choices_Validator;
7 use Elementor\Data\V2\Base\Endpoint as Endpoint_Base;
8 use WP_REST_Server;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 class User_Choices extends Endpoint_Base {
15
16 public function get_name(): string {
17 return 'user-choices';
18 }
19
20 public function get_format(): string {
21 return 'onboarding';
22 }
23
24 protected function register(): void {
25 parent::register();
26
27 $this->register_items_route( WP_REST_Server::EDITABLE );
28 }
29
30 public function get_items( $request ) {
31 $permission = $this->check_permission();
32 if ( is_wp_error( $permission ) ) {
33 return $permission;
34 }
35
36 $manager = Onboarding_Progress_Manager::instance();
37 $choices = $manager->get_choices();
38
39 return [
40 'data' => $choices->to_array(),
41 ];
42 }
43
44 public function update_items( $request ) {
45 $permission = $this->check_permission();
46 if ( is_wp_error( $permission ) ) {
47 return $permission;
48 }
49
50 $params = $request->get_json_params();
51
52 $validator = new User_Choices_Validator();
53 $validated = $validator->validate( $params ?? [] );
54
55 if ( is_wp_error( $validated ) ) {
56 return $validated;
57 }
58
59 $manager = Onboarding_Progress_Manager::instance();
60 $choices = $manager->update_choices( $validated );
61
62 return [
63 'data' => 'success',
64 'choices' => $choices->to_array(),
65 ];
66 }
67
68 private function check_permission() {
69 if ( ! current_user_can( 'manage_options' ) ) {
70 return new \WP_Error(
71 'rest_forbidden',
72 __( 'Sorry, you are not allowed to access onboarding data.', 'elementor' ),
73 [ 'status' => 403 ]
74 );
75 }
76 return true;
77 }
78 }
79