| @@ -34,61 +34,14 @@ | ||
| 34 | 34 | if ( empty( $post_data['features'] ) ) { |
| 35 | 35 | return; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - $sanitized_features = $this->sanitize_features( $post_data['features'] ); | |
| 38 | + update_option( static::ONBOARDING_FEATURES_OPTION, $post_data['features'] ); | |
| 39 | 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 | 40 | return [ |
| 52 | 41 | 'status' => 'success', |
| 53 | 42 | 'payload' => [], |
| 54 | 43 | ]; |
| 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 | 44 | } |
| 92 | 45 | |
| 93 | 46 | private function get_usage_data() { |
| 94 | 47 | return get_option( static::ONBOARDING_FEATURES_OPTION, [] ); |