classic-search
3 days ago
customberg
8 months ago
customizer
3 months ago
dashboard
2 months ago
initializers
1 month ago
inline-search
3 days ago
instant-search
2 months ago
search-blocks
3 days ago
widgets
1 month ago
wpes
8 months ago
class-ai-answers.php
3 months ago
class-cli.php
3 months ago
class-helper.php
3 days ago
class-module-control.php
2 months ago
class-options.php
3 months ago
class-package.php
3 days ago
class-plan.php
8 months ago
class-rest-controller.php
1 month ago
class-settings.php
2 months ago
class-stats.php
8 months ago
class-template-tags.php
8 months ago
class-settings.php
71 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Jetpack Search Overlay Settings |
| 4 | * |
| 5 | * @package automattic/jetpack-search |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Search; |
| 9 | |
| 10 | // Exit if file is accessed directly. |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit( 0 ); |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Class to initialize search settings on the site. |
| 17 | * |
| 18 | * 1. Settings are synced to WPCOM according to `Automattic\Jetpack\Sync\Modules\Search::$options_to_sync`. |
| 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 |
| 22 | */ |
| 23 | class Settings { |
| 24 | |
| 25 | /** |
| 26 | * Class initialization. |
| 27 | */ |
| 28 | public function __construct() { |
| 29 | add_action( 'admin_init', array( $this, 'settings_register' ) ); |
| 30 | add_action( 'rest_api_init', array( $this, 'settings_register' ) ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Register requisite settings. |
| 35 | * |
| 36 | * @since 9.x.x |
| 37 | */ |
| 38 | public function settings_register() { |
| 39 | // NOTE: This contains significant code overlap with class-jetpack-search-customize. |
| 40 | $setting_prefix = Options::OPTION_PREFIX; |
| 41 | $settings = array( |
| 42 | array( $setting_prefix . 'ai_prompt_override', 'string', '' ), |
| 43 | array( $setting_prefix . 'color_theme', 'string', 'light' ), |
| 44 | array( $setting_prefix . 'result_format', 'string', 'minimal' ), |
| 45 | array( $setting_prefix . 'default_sort', 'string', 'relevance' ), |
| 46 | array( $setting_prefix . 'overlay_trigger', 'string', Options::DEFAULT_OVERLAY_TRIGGER ), |
| 47 | array( $setting_prefix . 'excluded_post_types', 'string', '' ), |
| 48 | array( $setting_prefix . 'highlight_color', 'string', '#FFC' ), |
| 49 | array( $setting_prefix . 'enable_sort', 'boolean', true ), |
| 50 | array( $setting_prefix . 'inf_scroll', 'boolean', true ), |
| 51 | array( $setting_prefix . 'filtering_opens_overlay', 'boolean', true ), |
| 52 | array( $setting_prefix . 'show_post_date', 'boolean', true ), |
| 53 | array( $setting_prefix . 'show_product_price', 'boolean', true ), |
| 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 ), |
| 57 | ); |
| 58 | foreach ( $settings as $value ) { |
| 59 | register_setting( |
| 60 | 'options', |
| 61 | $value[0], |
| 62 | array( |
| 63 | 'default' => $value[2], |
| 64 | 'show_in_rest' => true, |
| 65 | 'type' => $value[1], |
| 66 | ) |
| 67 | ); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 |