Skip to content

Commit

Permalink
Sanitization optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Feb 20, 2017
1 parent cd142e2 commit 952f976
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 16 additions & 9 deletions classes/Setting/FrequencySetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,24 @@ public function settings_field_frequency() {
* @since 2.0.0
* @access public
*
* @param array $value The POST da.
* @param mixed $value The unsanitized value.
*
* @return array The sanitized frequency option.
*/
public function sanitize_frequency_option( array $value ) {
if ( 'daily' !== $value['period'] ) {
$value['period'] = 'weekly';
public function sanitize_frequency_option( $value ) {
$value = (array) $value;
$new_value = array();

$new_value['period'] = isset( $value['period'] ) ? $value['period'] : 'weekly';
$new_value['hour'] = isset( $value['hour'] ) ? $value['hour'] : 18;
$new_value['day'] = isset( $value['day'] ) ? $value['day'] : get_option( 'start_of_week', 0 );

if ( 'daily' !== $new_value['period'] ) {
$new_value['period'] = 'weekly';
}

$value['hour'] = filter_var(
$value['hour'],
$new_value['hour'] = filter_var(
$new_value['hour'],
FILTER_VALIDATE_INT,
array(
'options' => array(
Expand All @@ -143,8 +150,8 @@ public function sanitize_frequency_option( array $value ) {
)
);

$value['day'] = filter_var(
$value['day'],
$new_value['day'] = filter_var(
$new_value['day'],
FILTER_VALIDATE_INT,
array(
'options' => array(
Expand All @@ -155,7 +162,7 @@ public function sanitize_frequency_option( array $value ) {
)
);

return $value;
return $new_value;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ public function data_sanitize_frequency_option() {
* @param array $actual
*/
public function test_sanitize_frequency_option( $expected, $actual ) {
$this->assertEqualSets( $expected, self::$frequency_setting->sanitize_frequency_option( $actual ) );
$this->assertEqualSetsWithIndex( $expected, self::$frequency_setting->sanitize_frequency_option( $actual ) );
}
}

0 comments on commit 952f976

Please sign in to comment.