PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.2
Elementor Website Builder – more than just a page builder v4.3.2
4.3.2 4.3.1 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 All 455 releases
elementor / app / modules / onboarding / features-usage.php

features-usage.php in Elementor Website Builder – more than just a page builder 4.3.2, at app/modules/onboarding/features-usage.php

97 lines 2.3 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;
4
5 use Elementor\Tracker;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 class Features_Usage {
12
13 const ONBOARDING_FEATURES_OPTION = '_elementor_onboarding_features';
14
15 public function register() {
16 if ( ! Tracker::is_allow_track() ) {
17 return;
18 }
19
20 add_filter( 'elementor/tracker/send_tracking_data_params', function ( array $params ) {
21 $params['usages']['onboarding_features'] = $this->get_usage_data();
22
23 return $params;
24 } );
25 }
26
27 public function save_onboarding_features( $raw_post_data ) {
28 if ( empty( $raw_post_data ) ) {
29 return;
30 }
31
32 $post_data = json_decode( $raw_post_data, true );
33
34 if ( empty( $post_data['features'] ) ) {
35 return;
36 }
37
38 $sanitized_features = $this->sanitize_features( $post_data['features'] );
39
40 if ( null === $sanitized_features ) {
41 return [
42 'status' => 'error',
43 'payload' => [
44 'error_message' => esc_html__( 'There was a problem saving your selected features.', 'elementor' ),
45 ],
46 ];
47 }
48
49 update_option( static::ONBOARDING_FEATURES_OPTION, $sanitized_features );
50
51 return [
52 'status' => 'success',
53 'payload' => [],
54 ];
55 }
56
57 /**
58 * Sanitize the features selection payload.
59 *
60 * Expects an associative array of known tiers, each holding a list of
61 * free-text feature labels (see assets/js/utils/utils.js), e.g.:
62 * [ 'essential' => [ 'Templates & Theme Builder' ], 'advanced' => [], 'one' => [] ].
63 *
64 * @param mixed $features
65 *
66 * @return array|null Sanitized array, or null if the payload shape is invalid.
67 */
68 private function sanitize_features( $features ) {
69 if ( ! is_array( $features ) ) {
70 return null;
71 }
72
73 $allowed_tiers = [ 'essential', 'advanced', 'one' ];
74 $sanitized = [];
75
76 foreach ( $features as $tier => $selected_labels ) {
77 if ( ! in_array( $tier, $allowed_tiers, true ) || ! is_array( $selected_labels ) ) {
78 return null;
79 }
80
81 $sanitized[ $tier ] = array_values( array_map( function ( $label ) {
82 return is_string( $label ) ? sanitize_text_field( $label ) : null;
83 }, $selected_labels ) );
84
85 if ( in_array( null, $sanitized[ $tier ], true ) ) {
86 return null;
87 }
88 }
89
90 return $sanitized;
91 }
92
93 private function get_usage_data() {
94 return get_option( static::ONBOARDING_FEATURES_OPTION, [] );
95 }
96 }
97