Parameter sanitization on config update reworked

Verify that checkbox value is actually present in POST value and fallback to 0.
This commit is contained in:
Stefan Kalscheuer 2018-01-07 14:59:33 +01:00
parent 8b9ce4c570
commit 9e3dc8fb86

View File

@ -51,19 +51,26 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
$statifyblacklist_update_result = StatifyBlacklist_Admin::update_options( $statifyblacklist_update_result = StatifyBlacklist_Admin::update_options(
array( array(
'referer' => array( 'referer' => array(
'active' => (int) $_POST['statifyblacklist']['referer']['active'], 'active' => isset( $_POST['statifyblacklist']['referer']['active'] )
'cron' => (int) $_POST['statifyblacklist']['referer']['cron'], ? (int) $_POST['statifyblacklist']['referer']['active'] : 0,
'regexp' => (int) $_POST['statifyblacklist']['referer']['regexp'], 'cron' => isset( $_POST['statifyblacklist']['referer']['cron'] )
? (int) $_POST['statifyblacklist']['referer']['cron'] : 0,
'regexp' => isset( $_POST['statifyblacklist']['referer']['regexp'] )
? (int) $_POST['statifyblacklist']['referer']['regexp'] : 0,
'blacklist' => array_flip( $referer ), 'blacklist' => array_flip( $referer ),
), ),
'target' => array( 'target' => array(
'active' => (int) $_POST['statifyblacklist']['target']['active'], 'active' => isset( $_POST['statifyblacklist']['target']['active'] )
'cron' => (int) $_POST['statifyblacklist']['target']['cron'], ? (int) $_POST['statifyblacklist']['target']['active'] : 0,
'regexp' => (int) $_POST['statifyblacklist']['target']['regexp'], 'cron' => isset( $_POST['statifyblacklist']['target']['cron'] )
? (int) $_POST['statifyblacklist']['target']['cron'] : 0,
'regexp' => isset( $_POST['statifyblacklist']['target']['regexp'] )
? (int) $_POST['statifyblacklist']['target']['regexp'] : 0,
'blacklist' => array_flip( $target ), 'blacklist' => array_flip( $target ),
), ),
'ip' => array( 'ip' => array(
'active' => (int) $_POST['statifyblacklist']['ip']['active'], 'active' => isset( $_POST['statifyblacklist']['ip']['active'] )
? (int) $_POST['statifyblacklist']['ip']['active'] : 0,
'blacklist' => $ip, 'blacklist' => $ip,
), ),
'version' => StatifyBlacklist::VERSION_MAIN, 'version' => StatifyBlacklist::VERSION_MAIN,
@ -90,7 +97,7 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
<?php <?php
if ( is_plugin_inactive( 'statify/statify.php' ) ) { if ( is_plugin_inactive( 'statify/statify.php' ) ) {
print '<div class="notice notice-warning"><p>'; print '<div class="notice notice-warning"><p>';
esc_html( 'Statify plugin is not active.' ); esc_html_e( 'Statify plugin is not active.', 'statify-blacklist' );
print '</p></div>'; print '</p></div>';
} }
if ( isset( $statifyblacklist_post_warning ) ) { if ( isset( $statifyblacklist_post_warning ) ) {