jjgrainger/posttypes
Composer 安装命令:
composer require jjgrainger/posttypes
包简介
Simple WordPress custom post types.
关键字:
README 文档
README
Modern PHP abstractions for WordPress post types and taxonomies.
Migrating from v2 to v3
Important: v3.0 is a breaking release. Existing v2 post type and taxonomy definitions will not work without modification. Please review the migration guide in the documentation on how to upgrade to version 3.
Requirements
Installation
Install with composer
Run the following in your terminal to install PostTypes with Composer.
$ composer require jjgrainger/posttypes
PostTypes uses PSR-4 autoloading and can be used with the Composer's autoloader. See Composer's basic usage guide for details on working with Composer and autoloading.
Basic Usage
Create a custom post type
Custom post types are defined as classes that extend the base PostType class. At a minimum, the name method must be implemented to define the post type slug. All other methods are optional and allow you to configure labels, options, taxonomies, admin columns, filters, and more as needed.
<?php use PostTypes\PostType; use PostTypes\Columns; class Book extends PostType { /** * Define the Post Type name. */ public function name(): string { return 'book'; } /** * Define the Post Type labels. */ public function labels(): array { return [ 'name' => __( 'Book', 'text-domain' ), 'singular_name' => __( 'Book', 'text-domain' ), 'menu_name' => __( 'Books', 'text-domain' ), 'all_items' => __( 'Books', 'text-domain' ), 'add_new' => __( 'Add New', 'text-domain' ), 'add_new_item' => __( 'Add New Book', 'text-domain' ), 'edit_item' => __( 'Edit Book', 'text-domain' ), 'new_item' => __( 'New Book', 'text-domain' ), 'view_item' => __( 'View Book', 'text-domain' ), 'search_items' => __( 'Search Books', 'text-domain' ), 'not_found' => __( 'No Books found', 'text-domain' ), 'not_found_in_trash' => __( 'No Books found in Trash', 'text-domain' ), 'parent_item_colon' => __( 'Parent Book', 'text-domain' ), ]; } /** * Define Post Type feature supports. */ public function supports(): array { return [ 'title', 'editor', 'thumbnail', 'custom-fields', ]; } /** * Define Taxonomies associated with the Post Type. */ public function taxonomies(): array { return [ 'genre', 'category', ]; } /** * Set the menu icon for the Post Type. */ public function icon(): string { return 'dashicons-book'; } /** * Set the admin post table filters. */ public function filters(): array { return [ 'genre', 'category', ]; } /** * Define the columns for the admin post table. */ public function columns(Columns $columns): Columns { // Remove the author and date column. $columns->remove( [ 'author', 'date' ] ); // Add a Rating column. $columns->add( 'rating', __( 'Rating', 'post-types' ) ); // Populate the rating column. $columns->populate( 'rating', function( $post_id ) { echo get_post_meta( $post_id, 'rating', true ); } ); return $columns; } }
Register a custom post type
Once the custom post type class is created it can be registered to WordPress by instantiating and call the register method.
// Instantiate the Book PostType class. $book = new Book; // Register the Book PostType to WordPress. $book->register();
Notes
- The full documentation can be found online at posttypes.jjgrainger.co.uk
- Licensed under the MIT License
- Maintained under the Semantic Versioning Guide
Author
Joe Grainger
jjgrainger/posttypes 适用场景与选型建议
jjgrainger/posttypes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 599.5k 次下载、GitHub Stars 达 375, 最近一次更新时间为 2016 年 08 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wordpress」 「post-types」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jjgrainger/posttypes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jjgrainger/posttypes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jjgrainger/posttypes 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Must-use plugin integrating WordPress with the Upsun platform: environment awareness, router-cache friendliness, safe preview clones, deploy migrations, Site Health checks, and a wp upsun CLI command.
Inertia.js server-side adapter for PHP. Handles full visits, Inertia XHR visits, asset-version 409 handshakes and partial reloads. Framework-agnostic, with transparent WordPress integration.
Adds Cache-Tag HTTP response headers for singular WordPress content and purges Cloudflare by tag when content changes.
AI Chatbot & Helpdesk Agent for WooCommerce. Connects your store to Egentify for AI-powered chat, order tracking, email, and ticketing.
MIDDAG's reference architecture for a WordPress plugin — composes the OSS framework/wordpress/ui libraries end to end.
Assets helper package for the Hybrid Core framework.
统计信息
- 总下载量: 599.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 383
- 点击次数: 23
- 依赖项目数: 14
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2016-08-16