amphibee / metabox-maker
以流畅的方式创建MetaBox字段。
dev-main
2024-05-11 07:17 UTC
Requires
- php: ^8.1.0
- laravel/pint: ^1.13
Requires (Dev)
- nunomaduro/phpinsights: ^2.8
- pestphp/pest: ^2.19
- rector/rector: ^1.0.0
This package is auto-updated.
Last update: 2024-09-09 11:54:55 UTC
README
MetaboxMaker是一个强大且灵活的WordPress扩展包,旨在简化自定义元盒和字段的创建和管理。它为开发者提供了一个面向对象的接口,以快速生成各种类型的字段,并能够无缝集成到WordPress主题或插件中。
功能
- 面向对象方法:利用现代PHP实践,提供干净且易于维护的代码库。
- 可扩展的字段类型:包括文本、数字、文件、图片、视频等多种字段类型。
- 可定制的选项:每种字段类型都提供可配置的设置,以满足不同的需求。
- 易于集成:易于与现有的WordPress设置集成,以最小的努力增强自定义内容类型。
- 高级字段配置:支持诸如强制删除、自定义上传目录和唯一的文件名回调等高级功能。
安装
要安装MetaboxMaker,您可以将composer包安装到WordPress插件或主题目录中。
composer require amphibee/metabox-maker
使用方法
基本使用
以下是一个创建带有文本和数字字段的自定义元盒的快速示例
<?php use AmphiBee\MetaboxMaker\Fields\Text; use AmphiBee\MetaboxMaker\Fields\Number; // Add fields to your metabox and display it in the post editor Metabox::make('User Information', 'user_info') ->fields([ Text::make('Username', 'username') ->placeholder('Enter your username'), Number::make('Age', 'age') ->min(18) ->max(100) ->step(1) ]) ->context('side') ->priority('high'); // Full Example use AmphiBee\MetaboxMaker\Fields\Group; use AmphiBee\MetaboxMaker\Fields\Text; use AmphiBee\MetaboxMaker\Metabox; use AmphiBee\MetaboxMaker\Location; Metabox::make('Test Fieldset', 'test_fieldset') ->fields([ Text::make('Main Text', 'main_text') ->placeholder('Enter main text'), Group::make('Sub group', 'sub_group') ->fields([ Text::make('Sub Text', 'sub_text') ->placeholder('Enter sub text'), ]), ]) ->priority('high') ->context('side') ->location(Location::where('post_type', ['post', 'page']));
高级功能
您还可以利用图像上传字段等高级功能,具有自定义设置
<?php use AmphiBee\MetaboxMaker\Fields\ImageUpload; $imageField = ImageUpload::make('Profile Picture', 'profile_picture') ->maxFileSize('5mb') ->imageSize('medium') ->forceDelete(true); Metabox::make('Profile', [$imageField]) ->context('normal') ->priority('default');
贡献
欢迎贡献!请随时提交拉取请求或创建有关错误和功能请求的问题。
许可
本项目采用MIT许可证 - 有关详细信息,请参阅LICENSE.md文件。