1 | <?php namespace EmailLog\Core\UI\Setting; |
||
10 | class CoreSetting extends Setting { |
||
11 | |||
12 | protected function initialize() { |
||
29 | |||
30 | /** |
||
31 | * Override `load` method so that the core settings are displayed first. |
||
32 | * |
||
33 | * @inheritdoc |
||
34 | */ |
||
35 | public function load() { |
||
36 | add_filter( 'el_setting_sections', array( $this, 'register' ), 9 ); |
||
37 | |||
38 | add_action( 'add_option_' . $this->section->option_name, array( $this, 'allowed_user_roles_added' ), 10, 2 ); |
||
39 | add_action( 'update_option_' . $this->section->option_name, array( $this, 'allowed_user_roles_changed' ), 10, 2 ); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Renders the Email Log `Allowed User Roles` settings. |
||
44 | * |
||
45 | * @param array $args Arguments. |
||
46 | */ |
||
47 | public function render_allowed_user_roles_settings( $args ) { |
||
79 | |||
80 | /** |
||
81 | * Sanitize allowed user roles setting. |
||
82 | * |
||
83 | * @param array $roles User selected user roles. |
||
84 | * |
||
85 | * @return array Sanitized user roles. |
||
86 | */ |
||
87 | public function sanitize_allowed_user_roles( $roles ) { |
||
94 | |||
95 | /** |
||
96 | * Renders the Email Log `Remove Data on Uninstall?` settings. |
||
97 | * |
||
98 | * @param array $args |
||
99 | */ |
||
100 | public function render_remove_on_uninstall_settings( $args ) { |
||
121 | |||
122 | /** |
||
123 | * Sanitize Remove on uninstall value. |
||
124 | * |
||
125 | * @param string $value User entered value. |
||
126 | * |
||
127 | * @return string Sanitized value. |
||
128 | */ |
||
129 | public function sanitize_remove_on_uninstall( $value ) { |
||
132 | |||
133 | /** |
||
134 | * Allowed user role list option is added. |
||
135 | * |
||
136 | * @param string $option Option name. |
||
137 | * @param array $value Option value. |
||
138 | */ |
||
139 | public function allowed_user_roles_added( $option, $value ) { |
||
140 | $this->allowed_user_roles_changed( array(), $value ); |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * Allowed user role list option was update. |
||
145 | * |
||
146 | * Change user role capabilities when the allowed user role list is changed. |
||
147 | * |
||
148 | * @param array $old_value Old Value. |
||
149 | * @param array $new_value New Value. |
||
150 | */ |
||
151 | public function allowed_user_roles_changed( $old_value, $new_value ) { |
||
152 | $old_roles = $this->get_user_roles( $old_value ); |
||
153 | $new_roles = $this->get_user_roles( $new_value ); |
||
154 | |||
155 | /** |
||
156 | * The user roles who can manage email log list is changed. |
||
157 | * |
||
158 | * @since 2.1.0 |
||
159 | * |
||
160 | * @param array $old_roles Old user roles. |
||
161 | * @param array $new_roles New user roles. |
||
162 | */ |
||
163 | do_action( 'el-log-list-manage-user-roles-changed', $old_roles, $new_roles ); |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * Get User roles from option value. |
||
168 | * |
||
169 | * @access protected |
||
170 | * |
||
171 | * @param array $option Option value |
||
172 | * |
||
173 | * @return array User roles. |
||
174 | */ |
||
175 | protected function get_user_roles( $option ) { |
||
187 | } |
||
188 |