Skip to content

Commit

Permalink
use only remote_addr to get user ip
Browse files Browse the repository at this point in the history
  • Loading branch information
filipecsweb committed Feb 19, 2024
1 parent 3f1c435 commit 615357f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/Common/MaintenanceMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function fswpma_maintenance_page() {
if ( ! empty( wpManutencao()->settings->getOption( 'ips' ) ) ) {
$ips = explode( ',', wpManutencao()->settings->getOption( 'ips' ) );
$ips = array_map( 'trim', $ips );
if ( in_array( wpManutencao()->utils->getTheUserIp(), $ips ) ) {
if ( in_array( wpManutencao()->utils->getTheUserIp(), $ips, true ) ) {
return;
}
}
Expand Down
11 changes: 4 additions & 7 deletions app/Common/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@ public function loadTemplate( string $template_name, array $args = [] ) {
* @return string
*/
public function getTheUserIp() {
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
$ip = '';
if ( ! empty( $_SERVER['REMOTE_ADDR'] ) ) {
$ip = sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) );
}

return $ip;
return $ip ?: '';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Tags: manutenção, maintenance, em breve, coming soon, construction, constructi
Tested up to: 6.4
Requires at least: 5.4
Requires PHP: 7.4
Stable tag: 1.0.6
Stable tag: 1.0.7
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand Down
4 changes: 2 additions & 2 deletions wordpress-manutencao.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Coloque seu site em manutenção ou redirecione-o para uma URL. Administradores logados podem ver o site. É possível liberar acesso a IPs.
* Author: Filipe Seabra
* Author URI: https://filipeseabra.me/
* Version: 1.0.6
* Version: 1.0.7
* Text Domain: wp-manutencao
* Domain Path: /languages/
*/
Expand All @@ -29,7 +29,7 @@
define( 'WP_MANUTENCAO_PATH', plugin_dir_path( __FILE__ ) );
define( 'WP_MANUTENCAO_URL', plugin_dir_url( __FILE__ ) );
define( 'WP_MANUTENCAO_BASENAME', plugin_basename( __FILE__ ) );
define( 'WP_MANUTENCAO_VERSION', '1.0.6' );
define( 'WP_MANUTENCAO_VERSION', '1.0.7' );
define( 'WP_MANUTENCAO_SLUG', 'wp-manutencao' );

/**
Expand Down

0 comments on commit 615357f

Please sign in to comment.