arraypress/wp-post-type-utils
Composer 安装命令:
composer require arraypress/wp-post-type-utils
包简介
A lean WordPress library for working with post types and post type operations
README 文档
README
A lightweight WordPress library for working with post types and post type operations. Provides clean APIs for post type information retrieval, capability checking, and search functionality with value/label formatting perfect for forms and admin interfaces.
Features
- 🎯 Clean API: WordPress-style snake_case methods with consistent interfaces
- 🔍 Built-in Search: Post type search with value/label formatting
- 📋 Form-Ready Options: Perfect value/label arrays for selects and forms
- 🛠️ Feature Detection: Check post type capabilities and feature support
- 📊 Information Retrieval: Access labels, capabilities, and properties
- 🎨 Flexible Filtering: Filter by features, hierarchical status, etc.
- 🔗 Taxonomy Relationships: Easy taxonomy-post type relationship checking
- ⚡ Status Checking: Built-in, public, hierarchical, and REST API status checks
Requirements
- PHP 7.4 or later
- WordPress 5.0 or later
Installation
composer require arraypress/wp-post-type-utils
Basic Usage
Working with Single Post Types
use ArrayPress\PostTypeUtils\PostType; // Check if post type exists if ( PostType::exists( 'product' ) ) { // Post type exists } // Get post type object $post_type_obj = PostType::get( 'product' ); // Get labels $singular = PostType::get_singular_label( 'product' ); $plural = PostType::get_plural_label( 'product' ); $custom_label = PostType::get_label( 'product', 'add_new_item' ); $description = PostType::get_description( 'product' ); // Check properties and status if ( PostType::is_hierarchical( 'product' ) ) { // Post type is hierarchical } if ( PostType::is_public( 'product' ) ) { // Post type is public } if ( PostType::is_built_in( 'product' ) ) { // Post type is built-in (core) } if ( PostType::has_archive( 'product' ) ) { // Post type has archive pages } if ( PostType::show_in_rest( 'product' ) ) { // Post type appears in REST API } // Check feature support if ( PostType::supports_feature( 'product', 'thumbnail' ) ) { // Supports featured images } // Quick feature checks if ( PostType::supports_thumbnails( 'product' ) ) { // Supports thumbnails } if ( PostType::supports_comments( 'product' ) ) { // Supports comments } if ( PostType::supports_revisions( 'product' ) ) { // Supports revisions } // Get taxonomies $taxonomies = PostType::get_taxonomies( 'product' ); $taxonomy_objects = PostType::get_taxonomies( 'product', 'objects' ); // Check taxonomy registration if ( PostType::is_registered_for_taxonomy( 'product', 'product_category' ) ) { // Product post type uses product_category taxonomy } // Get capabilities $capabilities = PostType::get_capabilities( 'product' ); // Get admin info $menu_position = PostType::get_menu_position( 'product' ); // Get archive info $archive_url = PostType::get_archive_url( 'product' ); $archive_slug = PostType::get_archive_slug( 'product' ); // REST API $rest_base = PostType::get_rest_base( 'product' ); // Count posts $published_count = PostType::count_posts( 'product', 'publish' ); $draft_count = PostType::count_posts( 'product', 'draft' );
Working with Multiple Post Types
// Check existence $existing = PostTypes::exists( [ 'post', 'page', 'invalid' ] ); // Returns: ['post', 'page'] // Get multiple post type objects $post_type_objects = PostTypes::get( [ 'post', 'page', 'product' ] ); // Get all registered post types $all_types = PostTypes::get_all(); $public_types = PostTypes::get_public(); $hierarchical_types = PostTypes::get_hierarchical(); // Get custom post types only (exclude built-in) $custom_types = PostTypes::get_custom(); // Get post types by taxonomy $types_with_categories = PostTypes::get_by_taxonomy( 'category' ); // Search post types $search_results = PostTypes::search( 'product' ); // Search post types and get options $options = PostTypes::search_options( 'product' ); // Returns: [['value' => 'product', 'label' => 'Products'], ...] // Get all post types as options $all_options = PostTypes::get_options(); // Returns: ['post' => 'Posts', 'page' => 'Pages', ...] // Exclude default post types from options $custom_options = PostTypes::get_options( [], true ); // Use different label field $options_with_plural = PostTypes::get_options( [], false, 'name' );
Feature Detection and Analysis
// Get post types by specific features $editor_types = PostTypes::get_by_feature( 'editor' ); $thumbnail_types = PostTypes::get_by_feature( 'thumbnail' ); // Check which types support a feature $thumbnail_supported = PostTypes::supports_feature( [ 'post', 'page', 'product' ], 'thumbnail' ); // Get Gutenberg-supported types $gutenberg_types = PostTypes::get_gutenberg_supported(); // Single post type feature checks $supports_editor = PostType::supports_feature( 'product', 'editor' ); $supports_thumbnail = PostType::supports_feature( 'product', 'thumbnail' ); $supports_custom_fields = PostType::supports_feature( 'product', 'custom-fields' );
Labels and Capabilities
// Get specific labels for single post type $add_new = PostType::get_label( 'product', 'add_new' ); $edit_item = PostType::get_label( 'product', 'edit_item' ); $view_item = PostType::get_label( 'product', 'view_item' ); // Get capabilities for single post type $caps = PostType::get_capabilities( 'product' ); // Access like: $caps->edit_posts, $caps->delete_posts // Get labels for multiple post types $labels = PostTypes::get_labels( [ 'post', 'page' ], 'singular_name' ); $all_labels = PostTypes::get_labels( [ 'post', 'page' ] ); // All labels // Get capabilities for multiple post types $capabilities = PostTypes::get_capabilities( [ 'post', 'page', 'product' ] );
Advanced Usage Examples
// Build admin interface options function get_content_type_options() { return PostTypes::get_options( [ 'public' => true, 'show_ui' => true ], true, 'singular_name' ); // Exclude defaults, use singular names } // Check if post type is suitable for content management function is_manageable_post_type( $post_type ) { return PostType::exists( $post_type ) && PostType::is_public( $post_type ) && PostType::supports_feature( $post_type, 'editor' ); } // Get post types that can have featured images $thumbnail_types = PostTypes::get_by_feature( 'thumbnail' ); // Get all custom post types with archives $custom_with_archives = array_filter( PostTypes::get_custom(), fn( $type ) => PostType::has_archive( $type ) ); // Find post types that support both comments and revisions $advanced_types = array_intersect( PostTypes::get_by_feature( 'comments' ), PostTypes::get_by_feature( 'revisions' ) );
API Reference
PostType Class (Single Post Types)
Core Retrieval:
exists( string $post_type ): boolget( string $post_type ): ?WP_Post_Type
Labels & Information:
get_labels( string $post_type ): ?objectget_label( string $post_type, string $label ): ?stringget_singular_label( string $post_type ): ?stringget_plural_label( string $post_type ): ?stringget_description( string $post_type ): ?stringget_menu_position( string $post_type ): ?int
Properties & Status:
is_hierarchical( string $post_type ): boolis_public( string $post_type ): boolis_built_in( string $post_type ): boolhas_archive( string $post_type ): boolshow_in_rest( string $post_type ): bool
Features & Support:
supports_feature( string $post_type, string $feature ): boolsupports_thumbnails( string $post_type ): boolsupports_comments( string $post_type ): boolsupports_revisions( string $post_type ): bool
Capabilities:
get_capabilities( string $post_type ): ?object
Taxonomies & Relationships:
get_taxonomies( string $post_type, string $output = 'names' ): arrayis_registered_for_taxonomy( string $post_type, string $taxonomy ): bool
URLs & Archives:
get_archive_url( string $post_type )get_archive_slug( string $post_type ): ?string
REST API:
get_rest_base( string $post_type ): ?string
Post Counts & Stats:
count_posts( string $post_type, string $status = 'publish' ): int
PostTypes Class (Multiple Post Types)
Core Retrieval:
exists( array $post_types ): arrayget( array $post_types, bool $include_nonexistent = false ): arrayget_all( array $args = [], string $output = 'names', bool $exclude_defaults = false ): arrayget_public( string $output = 'names' ): arrayget_hierarchical( string $output = 'names' ): arrayget_custom( string $output = 'names' ): arrayget_by_taxonomy( string $taxonomy ): array
Search & Options:
search( string $search, array $args = [] ): arraysearch_options( string $search, array $args = [] ): arrayget_options( array $args = [], bool $exclude_defaults = false, string $label_field = 'singular_name' ): array
Feature Analysis:
get_by_feature( string $feature ): arraysupports_feature( array $post_types, string $feature ): arrayget_gutenberg_supported(): array
Labels & Capabilities:
get_labels( array $post_types, string $label = '' ): arrayget_capabilities( array $post_types ): array
Key Features
- Value/Label Format: Perfect for forms and selects
- Feature Detection: Comprehensive capability checking
- Search Functionality: Built-in post type search with formatting
- Flexible Filtering: Multiple filtering options by features, status, etc.
- Information Access: Easy access to all post type properties
- Status Checking: Built-in, public, hierarchical, and REST API status
- Taxonomy Relationships: Easy taxonomy-post type relationship management
- Custom vs Built-in: Clear separation between custom and core post types
Requirements
- PHP 7.4+
- WordPress 5.0+
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the GPL-2.0-or-later License.
Support
arraypress/wp-post-type-utils 适用场景与选型建议
arraypress/wp-post-type-utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 09 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「search」 「wordpress」 「options」 「capabilities」 「wp」 「post-types」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 arraypress/wp-post-type-utils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 arraypress/wp-post-type-utils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 arraypress/wp-post-type-utils 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Lightweight configuration interfaces and utilities
A Laravel package to retrieve data from Google Search Console
This extension provide application configuration support stored in database.
Indexed Search Autocomplete - Extends the TYPO3 Core Extension Indexed_Search searchform with an autocomplete feature.
Array wrapper that eases the retrieval of values. Has parameters, options and settings and traits for inclusion in other libraries.
Abstraction Layer to index and search entities
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2025-09-02