This commit is contained in:
Yuri Karamian
2026-01-25 22:36:54 +01:00
parent 82ce7ccaf3
commit 6ed849214f
4 changed files with 187 additions and 6 deletions
+10 -6
View File
@@ -953,9 +953,9 @@ class WPSP_Admin {
<strong><?php esc_html_e( 'GeoIP Database Required', 'wp-security-pack' ); ?></strong><br>
<?php
printf(
/* translators: %s: Link to Geo Blocking tab */
/* translators: %s: Link to IP Control tab */
esc_html__( 'Country detection requires the GeoIP database. Please download it from the %s tab.', 'wp-security-pack' ),
'<a href="#" onclick="document.querySelector(\'a[href=\\\'#geo-blocking\\\']\').click(); return false;"><strong>' . esc_html__( 'Geo Blocking', 'wp-security-pack' ) . '</strong></a>'
'<a href="' . esc_url( admin_url( 'admin.php?page=wp-security-pack&tab=ip' ) ) . '"><strong>' . esc_html__( 'IP Control', 'wp-security-pack' ) . '</strong></a>'
);
?>
</p>
@@ -2610,11 +2610,15 @@ class WPSP_Admin {
<td><?php echo esc_html( WPSP_VERSION ); ?></td>
</tr>
<tr>
<td><strong><?php esc_html_e( 'Your IP Address', 'wp-security-pack' ); ?></strong></td>
<td><strong><?php esc_html_e( 'Server IP Address', 'wp-security-pack' ); ?></strong></td>
<td>
<code><?php echo esc_html( $current_ip ); ?></code>
<?php if ( $country_code ) : ?>
<?php echo esc_html( WPSP_Helper::get_country_flag( $country_code ) . ' ' . $country_code ); ?>
<?php
$server_ip = WPSP_Helper::get_server_ip();
if ( $server_ip ) :
?>
<code><?php echo esc_html( $server_ip ); ?></code>
<?php else : ?>
<em><?php esc_html_e( 'Unable to detect', 'wp-security-pack' ); ?></em>
<?php endif; ?>
</td>
</tr>
@@ -464,6 +464,55 @@ class WPSP_Helper {
return $slug;
}
/**
* Get the server's public IP address.
*
* Uses external service to determine the server's outbound IP.
* Result is cached for 1 hour to avoid excessive external requests.
*
* @return string|null Server IP or null on failure.
*/
public static function get_server_ip() {
$cached = get_transient( 'wpsp_server_ip' );
if ( false !== $cached ) {
return $cached;
}
// Try multiple services for reliability.
$services = array(
'https://api.ipify.org',
'https://ifconfig.me/ip',
'https://icanhazip.com',
);
$ip = null;
foreach ( $services as $service ) {
$response = wp_remote_get(
$service,
array(
'timeout' => 5,
'sslverify' => true,
)
);
if ( ! is_wp_error( $response ) && 200 === wp_remote_retrieve_response_code( $response ) ) {
$body = trim( wp_remote_retrieve_body( $response ) );
if ( filter_var( $body, FILTER_VALIDATE_IP ) ) {
$ip = $body;
break;
}
}
}
if ( $ip ) {
// Cache for 1 hour.
set_transient( 'wpsp_server_ip', $ip, HOUR_IN_SECONDS );
}
return $ip;
}
/**
* Get country flag emoji from country code.
*