italystrap/settings

WordPress 设置 API

0.0.5 2020-01-21 07:10 UTC

This package is auto-updated.

Last update: 2024-08-29 04:08:54 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License PHP from Packagist

以面向对象的方式使用 WordPress 设置 API

进行中: 该项目目前处于测试阶段,直到被认为可用。在发布 1.0.0 版本之前,此存储库中的代码可能不稳定。预期在次要版本之间(0.1.x -> 0.2.x)会有破坏向后兼容性的更改。

目录

安装

通过 Composer 使用此包是最佳方式

composer require italystrap/settings

此包遵循 SemVer 规范,并在次要版本之间完全向后兼容。

结构想法

  • 插件必须有一个选项存储(调用 get_option 一次,获取所有选项)
  • 插件可以有一个或多个设置页面,有自己的菜单链接(父级和/或子级)
  • 设置页面可以包含 0、1 或多个部分
  • 部分必须至少包含 1 个字段
  • 部分由标签页分隔
  • 插件可以包含 0、1 或多个在 plugins.php 页面上的链接

基本用法

使用它的最简单方法是实例化 Builder 并添加所需的内容。

您可以在 example.php 文件中找到最后更新的代码

use ItalyStrap\Settings\Page;
use ItalyStrap\Settings\SettingsBuilder;

$text_domain = 'ItalyStrap';
$option_name = 'italystrap';
$settings_config = \ItalyStrap\Config\ConfigFactory::make(
	require __DIR__ . '/tests/_data/fixtures/config/settings.php'
);

// Initialize the builder
$settings = new SettingsBuilder(
	$option_name,
	ITALYSTRAP_BASENAME,
	ITALYSTRAP_FILE
);

// You can add configuration via the \ItalyStrap\Config\ConfigFactory::class
$settings->addPage(
	$settings_config->get( 'page' ),
	$settings_config->get( 'sections' )
);

// Ora manually
// The section parameter is optional
// Not every page need a section with fields
// For example in a docs page
// Manu title and slug are mandatory
$settings->addPage(
	[
		Page::PARENT		=> 'italystrap-dashboard',
		Page::PAGE_TITLE	=> \__( 'Dashboard 2', 'italystrap' ),
		Page::MENU_TITLE	=> \__( 'Child1', 'italystrap' ),
		Page::SLUG			=> 'slug-for-child-page',
		Page::VIEW			=> __DIR__ . '/tests/_data/fixtures/view/empty_form.php',
	]
);

// You can also add a sub page either for you parent page or for the WP admin pages
$settings->addPage(
	[
		Page::PARENT		=> 'options-general.php',
//		Page::PAGE_TITLE	=> \__( 'ItalyStrap Dashboard 2', 'italystrap' ),
		Page::MENU_TITLE	=> \__( 'Child-general', 'italystrap' ),
		Page::SLUG			=> 'slug-for-child-general',
		Page::VIEW			=> __DIR__ . '/tests/_data/fixtures/view/empty_form.php',
	]
);

// You can also add a link to the plugins.php page in your plugin link for activation
// For example if you want to add an external link to your docs.
$settings->addCustomPluginLink(
	'key-for-css',
	'http://localhost.com',
	'Custom',
	[ 'target' => '_blank' ]
);

// After you added pages[?section] and/or link call the build() method.
$settings->build();

高级用法

待办事项

贡献

欢迎所有反馈/错误报告/拉取请求。

许可

版权(c)2019 Enea Overclokk,ItalyStrap

此代码根据 MIT 许可。

致谢

待办事项