承接 martinsluters/wpregistrars 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 martinsluters/wpregistrars 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2022-01-30