Skip to content

Commit

Permalink
Add sanitization for the new RRM v2 settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
hussain-t committed Jan 13, 2025
1 parent eb45bea commit 95fd012
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions includes/Modules/Reader_Revenue_Manager/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,56 @@ protected function get_sanitize_callback() {
}
}

if ( Feature_Flags::enabled( 'rrmModuleV2' ) ) {
if ( isset( $option['snippetMode'] ) ) {
$valid_snippet_modes = array( 'post_types', 'per_post', 'sitewide' );
if ( ! in_array( $option['snippetMode'], $valid_snippet_modes, true ) ) {
$option['snippetMode'] = 'post_types';
}
}

if ( isset( $option['postTypes'] ) ) {
if ( ! is_array( $option['postTypes'] ) ) {
$option['postTypes'] = array( 'post' );
} else {
$filtered_post_types = array_values(
array_filter(
$option['postTypes'],
'is_string'
)
);
$option['postTypes'] = ! empty( $filtered_post_types )
? $filtered_post_types
: array( 'post' );
}
}

if ( isset( $option['productID'] ) ) {
if ( ! is_string( $option['productID'] ) ) {
$option['productID'] = 'openaccess';
}
}

if ( isset( $option['productIDs'] ) ) {
if ( ! is_array( $option['productIDs'] ) ) {
$option['productIDs'] = array();
} else {
$option['productIDs'] = array_values(
array_filter(
$option['productIDs'],
'is_string'
)
);
}
}

if ( isset( $option['paymentOption'] ) ) {
if ( ! is_string( $option['paymentOption'] ) ) {
$option['paymentOption'] = '';
}
}
}

return $option;
};
}
Expand Down

0 comments on commit 95fd012

Please sign in to comment.