1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
<?php
namespace SolidWP\Mail\Admin;
/** * Class SettingsScreen * * Manages the settings screen for the Solid Mail plugin. */ class SettingsScreen { /** * Settings screen slug. */ public const SETTINGS_SLUG = 'solid_mail_settings';
/** * Registers the settings screen. * * Defines the setting for the Solid Mail settings, including type, description, default values, and REST schema. */ public function register_settings_screen() { register_setting( self::SETTINGS_SLUG, self::SETTINGS_SLUG, [ 'type' => 'object', 'description' => esc_html__( 'Solid Mail Settings', 'LION' ), 'sanitize_callback' => [ $this, 'sanitize_setting' ], 'default' => $this->get_default_settings(), 'show_in_rest' => [ 'schema' => [ 'properties' => [ 'disable_logs' => [ 'type' => 'string', 'description' => esc_html__( 'Enable or disable logging of sent emails.', 'LION' ), ], ], ], ], ] ); }
/** * Sanitizes the setting values. * * Ensures that the provided settings are valid and safe to use. * * @param array $value The settings values to sanitize. * * @return array The sanitized settings values. */ public function sanitize_setting( $value ) { $parse_args = wp_parse_args( $value, $this->get_default_settings() );
if ( ! in_array( $parse_args['disable_logs'], [ 'no', 'yes' ], true ) ) { $parse_args['disable_logs'] = 'no'; }
return $parse_args; }
/** * Gets the default settings. * * Returns an array of default settings for the Solid Mail plugin. * * @return array The default settings. */ public function get_default_settings(): array { return [ 'disable_logs' => 'no', ]; }
/** * Retrieves the plugin settings. * * @return array The sanitized settings array. */ public function get_settings(): array { $settings = get_option( self::SETTINGS_SLUG, [] );
return $this->sanitize_setting( $settings ); } }
|