use long array syntax

For some reason short syntax is discouraged in the latest WPCS ruleset.
To stay in line with WPCS we use long syntax now.
This commit is contained in:
Stefan Kalscheuer 2020-01-07 19:24:38 +01:00
parent 4c9d96e5a0
commit ebc44c722e
2 changed files with 23 additions and 23 deletions

View File

@ -64,7 +64,7 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
// Sanitize referer list. // Sanitize referer list.
$given_referer = $options['referer']['blacklist']; $given_referer = $options['referer']['blacklist'];
$invalid_referer = []; $invalid_referer = array();
if ( self::MODE_NORMAL === $options['referer']['regexp'] ) { if ( self::MODE_NORMAL === $options['referer']['regexp'] ) {
// Sanitize URLs and remove empty inputs. // Sanitize URLs and remove empty inputs.
$sanitized_referer = self::sanitize_urls( $given_referer ); $sanitized_referer = self::sanitize_urls( $given_referer );
@ -78,7 +78,7 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
// Sanitize target list. // Sanitize target list.
$given_target = $options['target']['blacklist']; $given_target = $options['target']['blacklist'];
$invalid_target = []; $invalid_target = array();
if ( self::MODE_REGEX === $options['target']['regexp'] || self::MODE_REGEX_CI === $options['target']['regexp'] ) { if ( self::MODE_REGEX === $options['target']['regexp'] || self::MODE_REGEX_CI === $options['target']['regexp'] ) {
$sanitized_target = $given_target; $sanitized_target = $given_target;
// Check regular expressions. // Check regular expressions.
@ -92,22 +92,22 @@ class StatifyBlacklist_Admin extends StatifyBlacklist {
$sanitized_ip = self::sanitize_ips( $given_ip ); $sanitized_ip = self::sanitize_ips( $given_ip );
// Abort on errors. // Abort on errors.
$errors = [ $errors = array(
'referer' => [ 'referer' => array(
'sanitized' => $sanitized_referer, 'sanitized' => $sanitized_referer,
'diff' => array_diff( $given_referer, $sanitized_referer ), 'diff' => array_diff( $given_referer, $sanitized_referer ),
'invalid' => $invalid_referer, 'invalid' => $invalid_referer,
], ),
'target' => [ 'target' => array(
'sanitized' => $sanitized_target, 'sanitized' => $sanitized_target,
'diff' => array_diff( $given_target, $sanitized_target ), 'diff' => array_diff( $given_target, $sanitized_target ),
'invalid' => $invalid_target, 'invalid' => $invalid_target,
], ),
'ip' => [ 'ip' => array(
'sanitized' => $sanitized_ip, 'sanitized' => $sanitized_ip,
'diff' => array_diff( $given_ip, $sanitized_ip ), 'diff' => array_diff( $given_ip, $sanitized_ip ),
], ),
]; );
if ( ! empty( $errors['referer']['diff'] ) if ( ! empty( $errors['referer']['diff'] )
|| ! empty( $errors['referer']['invalid'] ) || ! empty( $errors['referer']['invalid'] )
|| ! empty( $errors['target']['diff'] ) || ! empty( $errors['target']['diff'] )

View File

@ -33,7 +33,7 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
$referer_str = sanitize_textarea_field( wp_unslash( $_POST['statifyblacklist']['referer']['blacklist'] ) ); $referer_str = sanitize_textarea_field( wp_unslash( $_POST['statifyblacklist']['referer']['blacklist'] ) );
} }
if ( empty( trim( $referer_str ) ) ) { if ( empty( trim( $referer_str ) ) ) {
$referer = []; $referer = array();
} else { } else {
$referer = array_filter( $referer = array_filter(
array_map( array_map(
@ -53,7 +53,7 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
$target_str = sanitize_textarea_field( wp_unslash( $_POST['statifyblacklist']['target']['blacklist'] ) ); $target_str = sanitize_textarea_field( wp_unslash( $_POST['statifyblacklist']['target']['blacklist'] ) );
} }
if ( empty( trim( $target_str ) ) ) { if ( empty( trim( $target_str ) ) ) {
$target = []; $target = array();
} else { } else {
$target = array_filter( $target = array_filter(
array_map( array_map(
@ -73,7 +73,7 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
$ip_str = sanitize_textarea_field( wp_unslash( $_POST['statifyblacklist']['ip']['blacklist'] ) ); $ip_str = sanitize_textarea_field( wp_unslash( $_POST['statifyblacklist']['ip']['blacklist'] ) );
} }
if ( empty( trim( $ip_str ) ) ) { if ( empty( trim( $ip_str ) ) ) {
$ip = []; $ip = array();
} else { } else {
$ip = array_filter( $ip = array_filter(
array_map( array_map(
@ -90,8 +90,8 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
// Update options (data will be sanitized). // Update options (data will be sanitized).
$statifyblacklist_update_result = StatifyBlacklist_Admin::update_options( $statifyblacklist_update_result = StatifyBlacklist_Admin::update_options(
[ array(
'referer' => [ 'referer' => array(
'active' => isset( $_POST['statifyblacklist']['referer']['active'] ) 'active' => isset( $_POST['statifyblacklist']['referer']['active'] )
? (int) $_POST['statifyblacklist']['referer']['active'] : 0, ? (int) $_POST['statifyblacklist']['referer']['active'] : 0,
'cron' => isset( $_POST['statifyblacklist']['referer']['cron'] ) 'cron' => isset( $_POST['statifyblacklist']['referer']['cron'] )
@ -99,8 +99,8 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
'regexp' => isset( $_POST['statifyblacklist']['referer']['regexp'] ) 'regexp' => isset( $_POST['statifyblacklist']['referer']['regexp'] )
? (int) $_POST['statifyblacklist']['referer']['regexp'] : 0, ? (int) $_POST['statifyblacklist']['referer']['regexp'] : 0,
'blacklist' => array_flip( $referer ), 'blacklist' => array_flip( $referer ),
], ),
'target' => [ 'target' => array(
'active' => isset( $_POST['statifyblacklist']['target']['active'] ) 'active' => isset( $_POST['statifyblacklist']['target']['active'] )
? (int) $_POST['statifyblacklist']['target']['active'] : 0, ? (int) $_POST['statifyblacklist']['target']['active'] : 0,
'cron' => isset( $_POST['statifyblacklist']['target']['cron'] ) 'cron' => isset( $_POST['statifyblacklist']['target']['cron'] )
@ -108,19 +108,19 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
'regexp' => isset( $_POST['statifyblacklist']['target']['regexp'] ) 'regexp' => isset( $_POST['statifyblacklist']['target']['regexp'] )
? (int) $_POST['statifyblacklist']['target']['regexp'] : 0, ? (int) $_POST['statifyblacklist']['target']['regexp'] : 0,
'blacklist' => array_flip( $target ), 'blacklist' => array_flip( $target ),
], ),
'ip' => [ 'ip' => array(
'active' => isset( $_POST['statifyblacklist']['ip']['active'] ) 'active' => isset( $_POST['statifyblacklist']['ip']['active'] )
? (int) $_POST['statifyblacklist']['ip']['active'] : 0, ? (int) $_POST['statifyblacklist']['ip']['active'] : 0,
'blacklist' => $ip, 'blacklist' => $ip,
], ),
'version' => StatifyBlacklist::VERSION_MAIN, 'version' => StatifyBlacklist::VERSION_MAIN,
] )
); );
// Generate messages. // Generate messages.
if ( false !== $statifyblacklist_update_result ) { if ( false !== $statifyblacklist_update_result ) {
$statifyblacklist_post_warning = []; $statifyblacklist_post_warning = array();
if ( ! empty( $statifyblacklist_update_result['referer']['diff'] ) ) { if ( ! empty( $statifyblacklist_update_result['referer']['diff'] ) ) {
$statifyblacklist_post_warning[] = __( 'Some URLs are invalid and have been sanitized.', 'statify-blacklist' ); $statifyblacklist_post_warning[] = __( 'Some URLs are invalid and have been sanitized.', 'statify-blacklist' );
} }
@ -156,7 +156,7 @@ if ( ! empty( $_POST['statifyblacklist'] ) ) {
if ( isset( $statifyblacklist_post_warning ) ) { if ( isset( $statifyblacklist_post_warning ) ) {
foreach ( $statifyblacklist_post_warning as $w ) { foreach ( $statifyblacklist_post_warning as $w ) {
print '<div class="notice notice-warning"><p>' . print '<div class="notice notice-warning"><p>' .
wp_kses( $w, [ 'br' => [] ] ) . wp_kses( $w, array( 'br' => array() ) ) .
'</p></div>'; '</p></div>';
} }
print '<div class="notice notice-warning"><p>' . esc_html( 'Settings have not been saved yet.', 'statify-blacklist' ) . '</p></div>'; print '<div class="notice notice-warning"><p>' . esc_html( 'Settings have not been saved yet.', 'statify-blacklist' ) . '</p></div>';