ardent.intent / wp-settings-adapter
一个抽象层,用于简化WordPress设置API的使用。
0.3.1
2022-10-05 21:04 UTC
Requires
- php: >=7.4
- ardent.intent/asingleton: ^1.0
- ardent.intent/blade: ^1.0.0
- danielgsims/php-collections: ^2.2
Requires (Dev)
- brain/monkey: ^2.6
- phpunit/phpunit: ^9.5
README
适配器是WordPress设置API的声明性外观。它旨在处理背后的复杂性,并让你专注于真正重要的事情。
忽略混乱的糟糕代码,轻松将主题或插件可选化!
使用示例
use \ArdentIntent\WpSettingsAdapter\Adapter; global $pluginOptions; ($pluginOptions = Adapter::createPage( 'Theme Options', 'Not spaghetti.', 'manage_options', 'adapter-test', 'general', 'dashicons-flag', 2 ))->withSections([ ($general = $pluginOptions->createSection('general'))->withSettings([ $general->createSetting( 'test-1', 'An example text setting description.' )->ofType()->text(), $general->createSetting('test-2')->ofType()->color(), $general->createSetting('test-5')->ofType()->text(), ]), ($special = $pluginOptions->createSection('special'))->withSettings([ $special->createSetting( 'test-6', 'A short description of this setting.' )->ofType()->text(), $special->createSetting( 'test-3', 'An example select setting.' )->ofType()->select()->withValues([ 'apple' => 'Apple', 'pear' => 'Pear', 'pineapple' => 'Pineapple' ]), $special->createSetting('test-4')->ofType()->toggle(), ]) ])->withSubPages([ ($subPageOne = $pluginOptions->createSubPage( 'Subpage One', 'An example sub-page.', 'manage_options', 'adapter-test-sub-one', 'general', 1 ))->withSections([ ($general = $subPageOne->createSection('general'))->withSettings([ $general->createSetting('general-1')->ofType()->toggle(), $general->createSetting('general-2')->ofType()->select()->withValues([ 'go', 'touch', 'grass' ]) ]), ($social = $subPageOne->createSection('social'))->withSettings([ $general->createSetting('social-1', 'Social link 1.')->ofType()->text(), $general->createSetting('social-2', 'Social link 2.')->ofType()->text(), $general->createSetting('social-3')->ofType()->select()->withValues([ 'on' => 'On', 'off' => 'Off' ]) ]) ]), ($subPageTwo = $pluginOptions->createSubPage( 'Subpage Two', 'An example sub-page.', 'manage_options', 'adapter-test-sub-two', 'general', 2 ))->withSections([ ($whatever = $subPageTwo->createSection('whatever'))->withSettings([ $whatever->createSetting('what', 'Life is suffering.')->ofType()->toggle(), $whatever->createSetting('ever', 'No one understands me.')->ofType()->toggle() ]) ]) ])->register();
开发模式
你可以通过调用以下方法启用开发模式: Adapter::enableDevMode();
启用开发模式会导致选项以可粘贴的代码片段形式渲染,这些代码片段获取各自选项的值。