Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display X-Geo-Country info #40

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions includes/public/class-jj4t3-404-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ class JJ4T3_404_Data {
*/
public $time = '';

/**
* Visitor's Country (available through a CDN, which must send the info in the X-Geo-Country header)
*
* @var string
* @access public
*/
public $geo_country = '';

/**
* Initialize the class.
*
Expand All @@ -72,6 +80,7 @@ public function __construct() {
$this->set_ua();
$this->set_url();
$this->set_time();
$this->set_geo_country(); // if available through the X-Geo-Country header
}

/**
Expand Down Expand Up @@ -202,6 +211,29 @@ private function set_time() {
$this->time = apply_filters( 'jj4t3_404_time', current_time( 'mysql' ) );
}

/**
* Set the visitor's country if available through the X-Geo-Country HTTP header.
*
* @since 3.0.0
* @access private
*
* @return void
*/

private function set_geo_country() {

if ( isset( $_SERVER['HTTP_X_GEO_COUNTRY'] ) ) {
$geo_country = esc_geo_country( $_SERVER['HTTP_X_GEO_COUNTRY'] );
} else {
$geo_country = 'N/A';
}

$this->geo_country = apply_filters( 'jj4t3_404_geo_country', $geo_country);

}



/**
* Exclude specified paths from 404.
*
Expand Down
5 changes: 5 additions & 0 deletions includes/public/class-jj4t3-404-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ private function set_body() {
$message .= '<th align="left">' . __( 'IP Address', JJ4T3_DOMAIN ) . '</th>';
$message .= '<td align="left">' . $this->error_data->ip . '</td>';
$message .= '</tr>';
// Visitor's country if available through X-Geo-Country HTTP header.
$message .= '<tr>';
$message .= '<th align="left">' . __('Visitor Country', JJ4T3_DOMAIN ) . '</th>';
$message .= '<td align="left">' . $this->error_data->geo_country . '</td>';
$message .= '</tr>';
// Date and time.
$message .= '<tr>';
$message .= '<th align="left">' . __( 'Time', JJ4T3_DOMAIN ) . '</th>';
Expand Down
4 changes: 3 additions & 1 deletion includes/public/class-jj4t3-404-logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ public function log_error() {
*/
private function get_data() {

// Set error data fields.
// Set error data fields.
$data = array(
'date' => $this->data->time,
'ip' => $this->data->ip,
'url' => $this->data->url,
'ref' => $this->data->ref,
'ua' => $this->data->ua,
// New geo_country field
'geo_country' => $this->data->geo_country,
);

// If a custom redirect is set.
Expand Down