new value. * * @return array */ public static function preview() { $out = array(); $num = static function ( $name ) { $v = get_option( $name, null ); return is_numeric( $v ) ? (int) $v : null; }; $retries = $num( 'limit_login_allowed_retries' ); if ( null !== $retries ) { $out['retries'] = $retries; } $lockout = $num( 'limit_login_lockout_duration' ); if ( null !== $lockout ) { $out['lockout_minutes'] = (int) round( $lockout / MINUTE_IN_SECONDS ); } $lockouts = $num( 'limit_login_allowed_lockouts' ); if ( null !== $lockouts ) { $out['lockouts_to_long'] = $lockouts; } $long = $num( 'limit_login_long_duration' ); if ( null !== $long ) { $out['long_hours'] = (int) round( $long / HOUR_IN_SECONDS ); } $valid = $num( 'limit_login_valid_duration' ); if ( null !== $valid ) { $out['window_hours'] = (int) round( $valid / HOUR_IN_SECONDS ); } if ( 'HTTP_X_FORWARDED_FOR' === get_option( 'limit_login_client_type' ) ) { $out['ip_source'] = 'xff'; } foreach ( array( 'allowlist' => 'limit_login_whitelist', 'denylist' => 'limit_login_blacklist', ) as $key => $option ) { $list = get_option( $option, array() ); if ( is_array( $list ) && $list ) { $out[ $key ] = implode( "\n", Ip::parse_list( implode( "\n", array_map( 'strval', $list ) ) ) ); } } return $out; } /** * Applies the import, merging allow/block lists with the current ones. * * @param Settings $settings Settings. * @return int Number of settings imported. */ public static function run( Settings $settings ) { $incoming = self::preview(); if ( ! $incoming ) { return 0; } $current = $settings->all(); foreach ( array( 'allowlist', 'denylist' ) as $key ) { if ( isset( $incoming[ $key ] ) ) { $incoming[ $key ] = implode( "\n", Ip::parse_list( $current[ $key ] . "\n" . $incoming[ $key ] ) ); } } $merged = $settings->sanitize( array_merge( $current, $incoming ) ); update_option( CCLG_OPTION, $merged ); $settings->reload(); return count( $incoming ); } }