arraypress/wp-nationalities
Composer 安装命令:
composer require arraypress/wp-nationalities
包简介
A lightweight WordPress library for working with nationalities and demonyms.
README 文档
README
A lightweight PHP library for working with nationality/demonym data in WordPress. Simple, static methods for mapping country codes to nationalities with search and formatting utilities.
Features
- 🌍 Complete ISO 3166-1 alpha-2 mapped nationalities (250+ entries)
- 🔄 Common aliases and informal demonyms (Kiwi, Aussie, Canuck, etc.)
- 🎯 Simple static API - no instantiation needed
- 🔍 Search and validation utilities
- 🏳️ Emoji flag support
Installation
composer require arraypress/wp-nationalities
Basic Usage
use ArrayPress\Nationalities\Nationalities; // Get all nationalities $nationalities = Nationalities::all(); // Returns: ['AF' => 'Afghan', 'AL' => 'Albanian', ...] // Get nationality $name = Nationalities::get_name( 'US' ); // "American" // Get country code by nationality $code = Nationalities::get_code( 'German' ); // "DE" // Also works with aliases $code = Nationalities::get_code( 'Kiwi' ); // "NZ" // Check if nationality exists if ( Nationalities::exists( 'US' ) ) { // Valid country code with nationality } // Validate and sanitize user input $code = Nationalities::sanitize( $_POST['nationality'] ); // "US" or null
Formatting & Rendering
// Get emoji flag echo Nationalities::get_flag( 'US' ); // "🇺🇸" // Format as plain string echo Nationalities::format( 'US', true ); // "🇺🇸 American" echo Nationalities::format( 'US', false, true ); // "American (US)" echo Nationalities::format( 'US', true, true ); // "🇺🇸 American (US)" // Render as HTML (for admin tables, templates) echo Nationalities::render( 'US' ); // "🇺🇸 American" (escaped HTML) echo Nationalities::render( 'US', true, false ); // "🇺🇸" (flag only) echo Nationalities::render( 'US', false ); // "American" (name only) // Returns null for empty codes $html = Nationalities::render( '' ); // null
Aliases
// Lookup by informal demonym $code = Nationalities::get_code( 'Aussie' ); // "AU" $code = Nationalities::get_code( 'Canuck' ); // "CA" $code = Nationalities::get_code( 'Pinoy' ); // "PH" // Get all aliases $aliases = Nationalities::get_aliases(); // Returns: ['Aussie' => 'AU', 'Kiwi' => 'NZ', ...] // Get aliases for a specific country $aliases = Nationalities::get_aliases_for( 'PH' ); // Returns: ['Filipino', 'Filipina', 'Pinoy', 'Pinay']
Search
// Search by nationality or code $results = Nationalities::search( 'ish' ); // Returns: ['GB' => 'British', 'DK' => 'Danish', 'FI' => 'Finnish', ...] // Also searches aliases $results = Nationalities::search( 'kiwi' ); // Returns: ['NZ' => 'New Zealander'] // Limit results $results = Nationalities::search( 'an', 5 );
Helper Functions
Global functions are available for convenience:
// Get nationality $name = get_nationality_name( 'US' ); // "American" // Get emoji flag $flag = get_nationality_flag( 'US' ); // "🇺🇸" // Get all nationalities as code => name pairs $options = get_nationality_options(); // Render as HTML $html = render_nationality( 'US' ); // "🇺🇸 American" // Sanitize user input $code = sanitize_nationality_code( $_POST['nationality'] ); // "US" or null
API Reference
| Method | Description | Return |
|---|---|---|
all() |
Get all nationalities | array |
get_name($code) |
Get nationality name | string |
get_code($name) |
Get code by nationality | ?string |
exists($code) |
Check if exists | bool |
sanitize($code) |
Validate/sanitize | ?string |
search($term, $limit) |
Search nationalities | array |
format($code, $flag, $c) |
Format as plain string | string |
render($code, $flag, $n) |
Render as HTML | ?string |
get_flag($code) |
Get emoji flag | string |
get_aliases() |
Get all aliases | array |
get_aliases_for($code) |
Get aliases for country code | array |
Requirements
- PHP 7.4 or higher
- WordPress 6.0 or higher
License
GPL-2.0-or-later
arraypress/wp-nationalities 适用场景与选型建议
arraypress/wp-nationalities 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wordpress」 「wp」 「iso-3166」 「country-codes」 「nationalities」 「arraypress」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 arraypress/wp-nationalities 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arraypress/wp-nationalities 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 arraypress/wp-nationalities 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
GeoNames API Client
Ready-to-use Laravel models and relations for country (ISO 3166), language (ISO 639-1), and currency (ISO 4217) information with multi-language support.
Country Flag Emoji for PHP
Ready-to-use Laravel models and relations for country (ISO 3166), language (ISO 639-1), and currency (ISO 4217) information with multi-language support.
Ready-to-use Laravel models and relations for country (ISO 3166), language (ISO 639-1), and currency (ISO 4217) information with multi-language support.
A database with ISO country information in all configured translations
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2026-02-17