PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 All 507 releases
← All changes | jetpack_vendor/automattic/jetpack-search/src/class-settings.php +34 -11 13.7.2 → 16.3-beta View file →
@@ -8,9 +8,9 @@
8 8 namespace Automattic\Jetpack\Search;
9 9
10 10 // Exit if file is accessed directly.
11 11 if ( ! defined( 'ABSPATH' ) ) {
12 - exit;
12 + exit( 0 );
13 13 }
14 14
15 15 /**
16 16 * Class to initialize search settings on the site.
@@ -16,8 +16,10 @@
16 16 * Class to initialize search settings on the site.
17 17 *
18 18 * 1. Settings are synced to WPCOM according to `Automattic\Jetpack\Sync\Modules\Search::$options_to_sync`.
19 19 * 2. All synced options must also be explicitly whitelisted and sanitized on WPCOM; see `PCYsg-sBM-p2`.
20 + *
21 + * @phan-constructor-used-for-side-effects
20 22 */
21 23 class Settings {
22 24
23 25 /**
@@ -34,10 +36,10 @@
34 36 * @since 9.x.x
35 37 */
36 38 public function settings_register() {
37 39 // NOTE: This contains significant code overlap with class-jetpack-search-customize.
38 - $setting_prefix = Options::OPTION_PREFIX;
39 - $settings = array(
40 + $setting_prefix = Options::OPTION_PREFIX;
41 + $settings = array(
40 42 array( $setting_prefix . 'ai_prompt_override', 'string', '' ),
41 43 array( $setting_prefix . 'color_theme', 'string', 'light' ),
42 44 array( $setting_prefix . 'result_format', 'string', 'minimal' ),
43 45 array( $setting_prefix . 'default_sort', 'string', 'relevance' ),
@@ -47,19 +49,40 @@
47 49 array( $setting_prefix . 'enable_sort', 'boolean', true ),
48 50 array( $setting_prefix . 'inf_scroll', 'boolean', true ),
49 51 array( $setting_prefix . 'filtering_opens_overlay', 'boolean', true ),
50 52 array( $setting_prefix . 'show_post_date', 'boolean', true ),
53 + array( $setting_prefix . 'show_product_price', 'boolean', true ),
51 54 array( $setting_prefix . 'show_powered_by', 'boolean', true ),
55 + array( $setting_prefix . 'ai_answers_enabled', 'boolean', false ),
56 + array( $setting_prefix . 'suggestions_enabled', 'boolean', false ),
52 57 );
58 + $ai_answers_enabled_key = $setting_prefix . 'ai_answers_enabled';
59 +
53 60 foreach ( $settings as $value ) {
54 - register_setting(
55 - 'options',
56 - $value[0],
57 - array(
58 - 'default' => $value[2],
59 - 'show_in_rest' => true,
60 - 'type' => $value[1],
61 - )
61 + $args = array(
62 + 'default' => $value[2],
63 + 'show_in_rest' => true,
64 + 'type' => $value[1],
62 65 );
66 +
67 + // Also reachable via WordPress core's generic /wp/v2/settings route,
68 + // which the plan-aware write gates elsewhere (REST_Controller, the
69 + // plugin's AI feature settings endpoint) don't cover.
70 + if ( $ai_answers_enabled_key === $value[0] ) {
71 + $args['sanitize_callback'] = array( __CLASS__, 'sanitize_ai_answers_enabled' );
72 + }
73 +
74 + register_setting( 'options', $value[0], $args );
63 75 }
76 + }
77 +
78 + /**
79 + * Reject enabling AI Answers on a site whose plan doesn't support it.
80 + *
81 + * @param mixed $value Raw value being saved.
82 + * @return bool
83 + */
84 + public static function sanitize_ai_answers_enabled( $value ) {
85 + $value = rest_sanitize_boolean( $value );
86 + return $value && ! Search_Blocks::supports_paid_search() ? false : $value;
64 87 }
65 88 }