1 | <?php namespace EmailLog\Core\UI\Setting; |
||
11 | abstract class Setting { |
||
12 | |||
13 | /** |
||
14 | * @var \EmailLog\Core\UI\Setting\SettingSection |
||
15 | */ |
||
16 | protected $section; |
||
17 | |||
18 | /** |
||
19 | * Set default values for SettingSection. |
||
20 | * Further customization can be done by the add-on in the `initialize` method. |
||
21 | */ |
||
22 | public function __construct() { |
||
31 | |||
32 | /** |
||
33 | * Setup hooks and filters. |
||
34 | */ |
||
35 | public function load() { |
||
36 | add_filter( 'el_setting_sections', array( $this, 'register' ) ); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Register the setting using the filter. |
||
41 | * |
||
42 | * @param SettingSection[] $sections List of existing SettingSections. |
||
43 | * |
||
44 | * @return SettingSection[] Modified list of SettingSections. |
||
45 | */ |
||
46 | public function register( $sections ) { |
||
47 | $sections[] = $this->section; |
||
48 | |||
49 | return $sections; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Get the value stored in the option. |
||
54 | * If no values are found then the default values are returned. |
||
55 | * |
||
56 | * @return array Stored value. |
||
57 | */ |
||
58 | public function get_value() { |
||
59 | $value = get_option( $this->section->option_name ); |
||
60 | |||
61 | return wp_parse_args( $value, $this->section->default_value ); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Customize the SettingSection. |
||
66 | * |
||
67 | * @return void |
||
68 | */ |
||
69 | abstract protected function initialize(); |
||
70 | |||
71 | /** |
||
72 | * Get the list of SettingFields. |
||
73 | * |
||
74 | * @return SettingField[] List of fields for the Setting. |
||
75 | */ |
||
76 | protected function get_fields() { |
||
79 | |||
80 | /** |
||
81 | * Render the Settings section. |
||
82 | * |
||
83 | * By default it does nothing. |
||
84 | */ |
||
85 | public function render() { |
||
88 | |||
89 | /** |
||
90 | * Sanitize the option values. |
||
91 | * |
||
92 | * @param mixed $values User entered values. |
||
93 | * |
||
94 | * @return mixed Sanitized values. |
||
95 | */ |
||
96 | public function sanitize( $values ) { |
||
116 | |||
117 | /** |
||
118 | * Build SettingField objects from field id and labels. |
||
119 | * |
||
120 | * @since 2.1.0 |
||
121 | * |
||
122 | * @return \EmailLog\Core\UI\Setting\SettingField[] Built SettingFields. |
||
123 | */ |
||
124 | protected function build_fields() { |
||
139 | } |
||
140 |