PHPackages                             arraypress/wp-countries - 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. [Localization &amp; i18n](/categories/localization)
4. /
5. arraypress/wp-countries

ActiveLibrary[Localization &amp; i18n](/categories/localization)

arraypress/wp-countries
=======================

A lightweight WordPress library for working with country codes and names with translation support.

035↓100%PHP

Since Feb 4Pushed 1mo agoCompare

[ Source](https://github.com/arraypress/wp-countries)[ Packagist](https://packagist.org/packages/arraypress/wp-countries)[ RSS](/packages/arraypress-wp-countries/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

WordPress Countries
===================

[](#wordpress-countries)

A lightweight PHP library for working with country data in WordPress. Simple, static methods for country codes, names, continents, and utilities.

Features
--------

[](#features)

- 🌍 Complete ISO 3166-1 alpha-2 country list (250+ countries)
- 🗺️ Continent mapping and EU membership detection
- 🎯 Simple static API - no instantiation needed
- 🔍 Search and validation utilities
- 🏳️ Emoji flag support
- ⚠️ Risk and sanctions categorization

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

[](#installation)

```
composer require arraypress/countries
```

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

[](#basic-usage)

```
use ArrayPress\Countries\Countries;

// Get all countries
$countries = Countries::all();
// Returns: ['AF' => 'Afghanistan', 'AL' => 'Albania', ...]

// Get country name
$name = Countries::get_name( 'US' ); // "United States"

// Get country code by name
$code = Countries::get_code( 'Germany' ); // "DE"

// Check if country exists
if ( Countries::exists( 'US' ) ) {
    // Valid country code
}

// Validate and sanitize user input
$country = Countries::sanitize( $_POST['country'] ); // "US" or null
```

Formatting &amp; Rendering
--------------------------

[](#formatting--rendering)

```
// Get emoji flag
echo Countries::get_flag( 'US' ); // "🇺🇸"

// Format as plain string
echo Countries::format( 'US', true ); // "🇺🇸 United States"
echo Countries::format( 'US', false, true ); // "United States (US)"
echo Countries::format( 'US', true, true ); // "🇺🇸 United States (US)"

// Render as HTML (for admin tables, templates)
echo Countries::render( 'US' ); // "🇺🇸 United States" (escaped HTML)
echo Countries::render( 'US', true, false ); // "🇺🇸" (flag only)
echo Countries::render( 'US', false ); // "United States" (name only)

// Returns null for empty codes
$html = Countries::render( '' ); // null
```

Geographic Regions
------------------

[](#geographic-regions)

```
// Get continent
$continent = Countries::get_continent( 'US' ); // "North America"
$continent = Countries::get_continent( 'DE' ); // "Europe"

// Get continent code
$code = Countries::get_country_continent_code( 'US' ); // "NA"

// Check continent
if ( Countries::is_continent( 'JP', 'Asia' ) ) {
    // Japan is in Asia
}

// Works with continent codes too
if ( Countries::is_continent( 'JP', 'AS' ) ) {
    // Also works
}

// Get all countries in a continent
$european = Countries::get_by_continent( 'Europe' );
$asian    = Countries::get_by_continent( 'AS' ); // Also accepts codes

// Get all continent codes
$continents = Countries::get_continent_codes();
// Returns: ['AF' => 'Africa', 'AN' => 'Antarctica', ...]
```

European Union
--------------

[](#european-union)

```
// EU membership
if ( Countries::is_eu( 'DE' ) ) {
    // Germany is in EU
}

// Get all EU countries
$eu_countries = Countries::get_eu_countries();
// Returns: ['AT' => 'Austria', 'BE' => 'Belgium', ...]
```

Risk Categories
---------------

[](#risk-categories)

```
// Check if country is high-risk
if ( Countries::is_high_risk( 'NG' ) ) {
    // Apply additional verification
}

// Get all high-risk countries
$high_risk = Countries::get_high_risk_countries();

// Check if country is under sanctions
if ( Countries::is_sanctioned( 'KP' ) ) {
    // Block transaction
}

// Get all sanctioned countries
$sanctioned = Countries::get_sanctioned_countries();
```

Search
------

[](#search)

```
// Search by name or code
$results = Countries::search( 'united' );
// Returns: ['AE' => 'United Arab Emirates', 'GB' => 'United Kingdom', 'US' => 'United States']

// Limit results
$results = Countries::search( 'island', 5 );
```

Helper Functions
----------------

[](#helper-functions)

Global functions are available for convenience:

```
// Get country name
$name = get_country_name( 'US' ); // "United States"

// Get emoji flag
$flag = get_country_flag( 'US' ); // "🇺🇸"

// Get all countries as code => name pairs
$options = get_country_options();

// Get continent
$continent = get_country_continent( 'US' ); // "North America"

// Render as HTML
$html = render_country( 'US' ); // "🇺🇸 United States"

// Sanitize user input
$code = sanitize_country_code( $_POST['country'] ); // "US" or null
```

API Reference
-------------

[](#api-reference)

MethodDescriptionReturn`all()`Get all countries`array``get_name($code)`Get country name`string``get_code($name)`Get code by name`?string``exists($code)`Check if exists`bool``sanitize($code)`Validate/sanitize`?string``search($term, $limit)`Search countries`array``format($code, $flag, $code)`Format as plain string`string``render($code, $flag, $name)`Render as HTML`?string``get_flag($code)`Get emoji flag`string``get_continent($code)`Get continent name`?string``get_continent_codes()`Get all continent codes`array``get_continent_code($name)`Continent name to code`?string``get_continent_name($code)`Continent code to name`?string``get_country_continent_code($code)`Country to continent code`?string``is_continent($code, $continent)`Check continent`bool``get_by_continent($continent)`Countries in continent`array``is_eu($code)`Check EU membership`bool``get_eu_countries()`Get EU countries`array``is_high_risk($code)`Check high-risk status`bool``get_high_risk_countries()`Get high-risk countries`array``is_sanctioned($code)`Check sanctions status`bool``get_sanctioned_countries()`Get sanctioned countries`array`Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- WordPress 6.0 or higher

License
-------

[](#license)

GPL-2.0-or-later

###  Health Score

22

—

LowBetter than 24% of packages

Maintenance60

Regular maintenance activity

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

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 (8 commits)")

### Embed Badge

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

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

###  Alternatives

[symfony/translation

Provides tools to internationalize your application

6.6k822.3M1.8k](/packages/symfony-translation)[commerceguys/addressing

Addressing library powered by CLDR and Google's address data.

95229.5M35](/packages/commerceguys-addressing)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

170648.9M4.3k](/packages/nesbot-carbon)[barryvdh/laravel-translation-manager

Manage Laravel Translations

1.7k3.5M16](/packages/barryvdh-laravel-translation-manager)[a2lix/translation-form-bundle

Translate your doctrine objects easily with some helpers

3436.9M37](/packages/a2lix-translation-form-bundle)[joedixon/laravel-translation

A tool for managing all of your Laravel translations

716892.4k8](/packages/joedixon-laravel-translation)

PHPackages © 2026

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