PHPackages                             arraypress/ipinfo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. arraypress/ipinfo

ActiveLibrary

arraypress/ipinfo
=================

A PHP library for integrating with the IPInfo.io API in WordPress, providing geolocation, ASN data, privacy detection, and hosting information. Features plan-aware responses and WordPress transient caching.

16PHP

Since Dec 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/arraypress/ipinfo)[ Packagist](https://packagist.org/packages/arraypress/ipinfo)[ RSS](/packages/arraypress-ipinfo/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

IPInfo Library for WordPress
============================

[](#ipinfo-library-for-wordpress)

A WordPress library for IPInfo.io API integration with smart caching and plan-aware responses.

Installation
------------

[](#installation)

Install via Composer:

```
composer require arraypress/ipinfo
```

Requirements
------------

[](#requirements)

- PHP 7.4 or later
- WordPress 6.7.1 or later
- IPInfo.io API key

Basic Usage
-----------

[](#basic-usage)

```
use ArrayPress\IPInfo\Client;

// Initialize with your API key/token
$client = new Client( 'your-api-key-here' );

// Single IP lookup
$info = $client->get_ip_info( '8.8.8.8' );

// Get specific field only
$country = $client->get_field( '8.8.8.8', 'country' );  // Returns: "US"
$city = $client->get_field( '8.8.8.8', 'city' );       // Returns: "Mountain View"

// Get multiple specific fields
$fields = $client->get_fields( '8.8.8.8', ['country', 'city', 'org'] );
// Returns: [ 'country' => 'US', 'city' => 'Mountain View', 'org' => 'Google LLC' ]

// Batch processing multiple IPs
$ips = [ '8.8.8.8', '1.1.1.1' ];
$batch_results = $client->get_batch_info( $ips );
foreach ( $batch_results as $ip => $info ) {
    echo "$ip is located in " . $info->get_city();
}
```

Available Methods
-----------------

[](#available-methods)

### Client Methods

[](#client-methods)

```
// Initialize client with options
$client = new Client(
    'your-token-here',    // API token
    true,                 // Enable caching (optional, default: true)
    3600                  // Cache duration in seconds (optional, default: 3600)
);

// Get complete information for an IP
$info = $client->get_ip_info( '8.8.8.8' );

// Get specific field
$field = $client->get_field( '8.8.8.8', 'country' );

// Get multiple fields
$fields = $client->get_fields( '8.8.8.8', [ 'country', 'city' ] );

// Process multiple IPs (max 1000)
$results = $client->get_batch_info(
    [ '8.8.8.8', '1.1.1.1' ], // IP addresses
    1000,                     // Batch size (optional, default: 1000)
    false,                    // Filter response (optional, default: false)
    5                         // Timeout in seconds (optional, default: 5)
);

// Cache management
$client->clear_cache( '8.8.8.8' );  // Clear specific IP
$client->clear_cache();             // Clear all cached data
```

### Response Methods

[](#response-methods)

#### Basic Information

[](#basic-information)

```
// Get IP address
$ip = $info->get_ip();
// Returns: "8.8.8.8"

// Get hostname (if available)
$hostname = $info->get_hostname();
// Returns: "dns.google"

// Check if IP is anycast
$is_anycast = $info->is_anycast();
// Returns: true/false

// Get city name
$city = $info->get_city();
// Returns: "Mountain View"

// Get region/state
$region = $info->get_region();
// Returns: "California"

// Get country information
$country_code = $info->get_country();      // Returns: "US"
$country_name = $info->get_country_name(); // Returns: "United States"

// Get coordinates
$coords = $info->get_coordinates();
// Returns: ['latitude' => 37.4056, 'longitude' => -122.0775]

// Individual coordinate access
$lat = $info->get_latitude();   // Returns: 37.4056
$long = $info->get_longitude(); // Returns: -122.0775

// Get postal code
$postal = $info->get_postal();
// Returns: "94043"

// Get timezone
$timezone = $info->get_timezone();
// Returns: "America/Los_Angeles"

// Get plan level
$plan = $info->get_plan();
// Returns: "Free", "Basic", "Business", or "Premium"

// Check feature availability
$has_asn = $info->has_feature( 'asn' );        // Basic plan and above
$has_privacy = $info->has_feature( 'privacy' ); // Business plan and above
$has_domains = $info->has_feature( 'domains' ); // Premium plan only

// Extended country information
$flag = $info->get_country_flag();
if ( $flag ) {
    $emoji = $flag->get_emoji();     // Returns: "🇺🇸"
    $unicode = $flag->get_unicode();  // Returns: "U+1F1FA U+1F1F8"
}

$currency = $info->get_country_currency();
if ( $currency ) {
    $code = $currency->get_code();    // Returns: "USD"
    $symbol = $currency->get_symbol(); // Returns: "$"
}

$continent = $info->get_continent();
if ( $continent ) {
    $name = $continent->get_name();   // Returns: "North America"
    $code = $continent->get_code();   // Returns: "NA"
}

$is_eu = $info->is_eu(); // Returns: true/false
```

### ASN Information (Basic Plan and Above)

[](#asn-information-basic-plan-and-above)

```
if ( $asn = $info->get_asn() ) {
    $asn_number = $asn->get_asn();      // Returns: "AS15169"
    $asn_name = $asn->get_name();       // Returns: "Google LLC"
    $asn_domain = $asn->get_domain();   // Returns: "google.com"
    $asn_route = $asn->get_route();     // Returns: "8.8.8.0/24"
    $asn_type = $asn->get_type();       // Returns: "hosting"
}
```

### Privacy Detection (Business/Premium Plans)

[](#privacy-detection-businesspremium-plans)

```
if ( $privacy = $info->get_privacy() ) {
    $is_vpn = $privacy->is_vpn();         // Returns: false
    $is_proxy = $privacy->is_proxy();      // Returns: false
    $is_tor = $privacy->is_tor();          // Returns: false
    $is_relay = $privacy->is_relay();      // Returns: false
    $is_hosting = $privacy->is_hosting();  // Returns: true
    $service = $privacy->get_service();    // Returns: null or service name
}
```

### Company Information (Business/Premium Plans)

[](#company-information-businesspremium-plans)

```
if ( $company = $info->get_company() ) {
    $name = $company->get_name();      // Returns: "Google LLC"
    $domain = $company->get_domain();  // Returns: "google.com"
    $type = $company->get_type();      // Returns: "hosting"
}
```

### Abuse Contact Information (Business/Premium Plans)

[](#abuse-contact-information-businesspremium-plans)

```
if ( $abuse = $info->get_abuse() ) {
    $email = $abuse->get_email();     // Returns: "network-abuse@google.com"
    $name = $abuse->get_name();       // Returns: "Google LLC"
    $phone = $abuse->get_phone();     // Returns: "+1-650-253-0000"
    $address = $abuse->get_address(); // Returns: "1600 Amphitheatre Parkway..."
    $country = $abuse->get_country(); // Returns: "US"
    $network = $abuse->get_network(); // Returns: "8.8.8.0/24"
}
```

### Domains Information (Premium Plan Only)

[](#domains-information-premium-plan-only)

```
if ( $domains = $info->get_domains() ) {
    $total = $domains->get_total();     // Returns: total number of domains
    $page = $domains->get_page();       // Returns: current page number
    $list = $domains->get_domains();    // Returns: array of domain names
}
```

Response Format Examples
------------------------

[](#response-format-examples)

### Raw Data Access

[](#raw-data-access)

```
// Get full raw data array
$raw_data = $info->get_all();

// Magic property access
$raw_data = $info->all;
```

### Basic Plan Response

[](#basic-plan-response)

```
[
    'ip' => '8.8.8.8',
    'city' => 'Mountain View',
    'region' => 'California',
    'country' => 'US',
    'loc' => '37.4056,-122.0775',
    'org' => 'AS15169 Google LLC',
    'postal' => '94043',
    'timezone' => 'America/Los_Angeles'
]
```

### Business Plan Additional Data

[](#business-plan-additional-data)

```
[
    // ... basic plan data ...
    'asn' => [
        'asn' => 'AS15169',
        'name' => 'Google LLC',
        'domain' => 'google.com',
        'route' => '8.8.8.0/24',
        'type' => 'hosting'
    ],
    'company' => [
        'name' => 'Google LLC',
        'domain' => 'google.com',
        'type' => 'hosting'
    ],
    'privacy' => [
        'vpn' => false,
        'proxy' => false,
        'tor' => false,
        'relay' => false,
        'hosting' => true,
        'service' => null
    ],
    'abuse' => [
        'address' => 'US, CA, Mountain View, 1600 Amphitheatre Parkway, 94043',
        'country' => 'US',
        'email' => 'network-abuse@google.com',
        'name' => 'Network Abuse',
        'network' => '8.8.8.0/24',
        'phone' => '+1-650-253-0000'
    ]
]
```

### Premium Plan Additional Data

[](#premium-plan-additional-data)

```
[
    // ... business plan data ...
    'domains' => [
        'total' => 2535948,
        'domains' => [
            'pub.dev',
            'virustotal.com',
            'blooket.com',
            'go.dev',
            'rytr.me'
        ]
    ]
]
```

### Batch Processing Response

[](#batch-processing-response)

```
$batch_results = $client->get_batch_info( [ '8.8.8.8', '1.1.1.1' ] );
// Returns:
[
    '8.8.8.8' => Response Object,
    '1.1.1.1' => Response Object
]
```

Error Handling
--------------

[](#error-handling)

The library uses WordPress's `WP_Error` for error handling:

```
$info = $client->get_ip_info( 'invalid-ip' );

if ( is_wp_error( $info ) ) {
    echo $info->get_error_message();
    // Output: "Invalid IP address: invalid-ip"
}
```

Common error cases:

- Invalid IP address
- Invalid API key/token
- API request failure
- Rate limit exceeded
- Invalid response format

Contributions
-------------

[](#contributions)

Contributions to this library are highly appreciated. Raise issues on GitHub or submit pull requests for bug fixes or new features. Share feedback and suggestions for improvements.

License: GPLv2 or later
-----------------------

[](#license-gplv2-or-later)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd6eb8aff0903d87eb674d1ba3c5f3653899c0d7661504eb0deb7798ed86b643?d=identicon)[arraypress](/maintainers/arraypress)

---

Top Contributors

[![arraypress](https://avatars.githubusercontent.com/u/22668877?v=4)](https://github.com/arraypress "arraypress (15 commits)")

### Embed Badge

![Health badge](/badges/arraypress-ipinfo/health.svg)

```
[![Health](https://phpackages.com/badges/arraypress-ipinfo/health.svg)](https://phpackages.com/packages/arraypress-ipinfo)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
