martinsluters/wpregistrars
Composer 安装命令:
composer require martinsluters/wpregistrars
包简介
A library that allows to register WordPress post types and taxonomies in bulk.
README 文档
README
Introduction
In a nutshell the WP Registrars is a small PHP library which allows to register WordPress post types and taxonomies in bulk. Labels are made in plural form and uppercase where required to make development faster.
Minimum Requirements
- PHP: 7.4
- PHP 8.0 and 8.1 are supported
- WordPress: Tested up to WP 5.9
Installation
You can install the WP Registrars with composer:
composer require martinsluters/wpregistrars
Usage
It is relatively easy to use the library, you can use factories martinsluters\WPRegistrars\Factories\BulkRegistrarPostTypesFactory and martinsluters\WPRegistrars\Factories\BulkRegistrarTaxonomiesFactory
to create new
martinsluters\WPRegistrars\Registrars\BulkRegistrarPostTypes and martinsluters\WPRegistrars\Registrars\BulkRegistrarTaxonomies registrar instances.
use martinsluters\WPRegistrars\Factories\{ BulkRegistrarPostTypesFactory, BulkRegistrarTaxonomiesFactory }; ( new BulkRegistrarPostTypesFactory() ) ->withArguments( [ 'report', 'guide', 'resource' ] ) ->create() ->register(); ( new BulkRegistrarTaxonomiesFactory() ) ->withArguments( [ 'resource_type' => [ 'object_type' => [ 'resource' ] ] 'guide_language' => [ 'object_type' => [ 'guide' ] ] 'my-random-taxonomy' ] ) ->create() ->register();
Note: This documentation will not cover the appropriate place and time in WordPress action execution order to use the library.
Hint: Post type and taxonomy registrations should not be hooked before the ‘init’ action.
Usage of factory build methods
withArguments( array $arguments )
It is mandatory to use this method to register custom post type or custom taxonomy.
At the most minimal configuration it requires an indexed array passed with at least one element with a string type value.
withArguments( [ 'report' ] ) The string is considered as the post type or taxonomy key. You can pass in theory an unlimited number of elements.
It is possible to pass additional registration arguments. By setting an array element with a string type key (to be considered as post type or taxonomy key) and array type element value. Array passed to the value is what you would normally pass when registering a post type and taxonomy.
withArguments( [ 'report' => [ 'public' => true ] ] )
To pass object type(s) when registering a taxonomy use the following
withArguments( [ 'guide_language' => [ 'object_type' => [ 'guide', 'report' ] ] ] )
Arguments passed to withArguments takes over arguments passed to withDefaultRegistrationArguments.
withDefaultRegistrationArguments( array $default_registration_arguments )
It is possible to set default registration arguments that will be applied to all post types or taxonomies. Array passed is what you would normally pass when registering a post type and taxonomy.
withDefaultRegistrationArguments( [ 'public' => true ] )
An exception is passing taxonomy registration object type(s). You can pass them along with registration arguments array using the following format
withDefaultRegistrationArguments( [ 'object_type' => [ 'guide', 'report' ] ] )
Arguments passed to withArguments takes over arguments passed to withDefaultRegistrationArguments.
shouldAutoPluralize( bool $should_auto_pluralize_label )
By default labels of post type or taxonomy are made in plural form where it is required using post type or taxonomy key as source. It is possible to disable the feature using shouldAutoPluralize( false ) .
If withDefaultRegistrationArguments or withArguments provides array element label then shouldAutoPluralize has no effect.
withPluralizer( PluralizerInterface $pluralizer )
By default labels of post type and taxonomy are made in plural English form using Doctrine\Inflector\Inflector that is a dependency for the library.
It is possible to change the language used by providing a different language using Doctrine\Inflector\Language
use martinsluters\WPRegistrars\Factories\BulkRegistrarPostTypesFactory; use martinsluters\WPRegistrars\PluralizerDoctrineInflectorAdapter; use Doctrine\Inflector\{ InflectorFactory, Inflector, Language }; $doctrine_inflector_spanish = ( new InflectorFactory( Language::SPANISH ) ) ->create() ->build(); $pluralizer_spanish = new PluralizerDoctrineInflectorAdapter( $doctrine_inflector_spanish ); ( new BulkRegistrarPostTypesFactory() ) ->withPluralizer( $pluralizer_spanish ) ->withDefaultRegistrationArguments( ['public' => true] ) ->withArguments( [ 'escuela' ] ) ->create() ->register();
Note: Please see the official documentation of Doctrine\Inflector to find the supported languages.
You can use a different tool to make words in a plural form and disregard Doctrine\Inflector completely.
To do so you must provide to withPluralizer an adapter that implements martinsluters\WPRegistrars\PluralizerInterface.
shouldAutoCapitalize( bool $should_auto_capitalize_label )
By default labels of post type or taxonomy are made in a way that first character of each word in string is capitalized, if that character is alphabetic. The source of label is post type or taxonomy key. It is possible to disable the feature using shouldAutoCapitalize( false ).
If withDefaultRegistrationArguments or withArguments provides array element label then shouldAutoCapitalize has no effect.
create()
Creates registrar instance if it is possible.
Usage of registrar methods
register()
Registers either post types or taxonomies.
License
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.
martinsluters/wpregistrars 适用场景与选型建议
martinsluters/wpregistrars 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 01 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「taxonomy」 「register」 「bulk」 「post type」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 martinsluters/wpregistrars 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 martinsluters/wpregistrars 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 martinsluters/wpregistrars 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Rinvex Authy is a simple wrapper for Authy TOTP, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest API for developers and a strong authentication platform for the enterprise.
CakePHP behavior plugin for easily generating some complicated queries like (bulk) insert/upsert etc.
This package provides a generic registry class to register any type of data under a identifier (key/value).
Icon support for Silverstripe taxonomy terms
Elemental Taxonomy module, provides a list of taxonomy terms under a selected type
Uniondrug Register Client Component for uniondrug/framework
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0
- 更新时间: 2022-01-30