Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Settings | |
0.00% |
0 / 28 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| settings_register | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
6 | |||
| 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 | ); |
| 56 | foreach ( $settings as $value ) { |
| 57 | register_setting( |
| 58 | 'options', |
| 59 | $value[0], |
| 60 | array( |
| 61 | 'default' => $value[2], |
| 62 | 'show_in_rest' => true, |
| 63 | 'type' => $value[1], |
| 64 | ) |
| 65 | ); |
| 66 | } |
| 67 | } |
| 68 | } |