Skip to content

Commit 180b266

Browse files
committed
Validate required field
1 parent c9ae1f3 commit 180b266

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

class-cliowp-settings-page.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public function add_settings() {
224224
$this->option_group,
225225
'cliowp_sp_input1',
226226
array(
227-
'sanitize_callback' => 'sanitize_text_field',
227+
'sanitize_callback' => array( $this, 'sanitize_input1' ),
228228
'default' => 'input1 test',
229229
)
230230
);
@@ -293,6 +293,24 @@ public function input1_html() {
293293
<?php
294294
}
295295

296+
/**
297+
* Undocumented function
298+
*
299+
* @param string $input The input value.
300+
*/
301+
public function sanitize_input1( $input ) {
302+
if ( true === empty( $input ) ) {
303+
add_settings_error(
304+
'cliowp_sp_input1',
305+
'cliowp_sp_input1_error',
306+
__( 'Input1 cannot be empty', 'cliowp-settings-page' ),
307+
);
308+
return get_option( 'cliowp_sp_input1' );
309+
}
310+
311+
return sanitize_text_field( $input );
312+
}
313+
296314
/**
297315
* Undocumented function
298316
*/

0 commit comments

Comments
 (0)