dwnload / wp-settings-api
一个PHP类抽象,它消除了WordPress设置API的烦恼,并即时构建了一个漂亮的选项面板。
v3.11.1
2024-04-25 16:12 UTC
Requires
- php: ^8.0
- ext-json: *
- thefrosty/wp-utilities: ^3.0
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^1.0
- inpsyde/php-coding-standards: dev-development
- phpcompatibility/php-compatibility: *
- phpunit/php-code-coverage: ^9
- phpunit/phpunit: ^9
- roave/security-advisories: dev-master
- roots/wordpress: ~6.5
- slevomat/coding-standard: ~8.12
- squizlabs/php_codesniffer: ^3.2
- wp-phpunit/wp-phpunit: ~6.5
- yoast/phpunit-polyfills: ^2.0
Suggests
- frontpack/composer-assets-plugin: Composer plugin for copying of frontend assets into public directory.
- dev-develop
- v3.11.1
- v3.11.0
- v3.10.0
- v3.9.0
- v3.8.2
- v3.8.1
- v3.8.0
- v3.7.0
- v3.6.1
- v3.6.0
- v3.5.0
- v3.4.1
- v3.4.0
- v3.3.2
- v3.3.1
- 3.3.0
- 3.2.3
- 3.2.2
- 3.2.0
- 3.1.1
- 3.1.0
- 3.0.0
- 2.6.0
- 2.5.1
- 2.5.0
- 2.4.5
- 2.4.3
- 2.4.2
- 2.4.0
- 2.2.0
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.3
- 2.0.2
- 2.0.1
- dev-dependabot/composer/develop/yoast/phpunit-polyfills-tw-3.0
This package is auto-updated.
Last update: 2024-09-09 05:31:11 UTC
README
这是一个用于处理WordPress 设置API的PHP类包装器。
包安装(通过Composer)
要安装此包,编辑您的composer.json
文件
{ "require": { "dwnload/wp-settings-api": "^3.8" } }
现在运行
$ composer install dwnload/wp-settings-api
使用示例
@see examples/Example.php
推荐包
⭐️ frontpack/composer-assets-plugin
自v3.2.1起,这不再需要(除非您只过滤本地资源)。资源现在将通过jsdelivr CDN加载。
否则,由于这是一个PHP包而不是WordPress插件,因此包含的资源无法正确加载。为了使设置页面继承样式并使用正确的JS,您必须将/assets
目录复制到您的插件或主题中。然后,将以下内容添加到过滤资产源到您的目录的过滤器中
<?php declare(strict_types=1); namespace Vendor\Package; use Dwnload\WpSettingsApi\Api\Script; use Dwnload\WpSettingsApi\Api\Style; use Dwnload\WpSettingsApi\WpSettingsApi; use TheFrosty\WpUtilities\Plugin\AbstractHookProvider; use TheFrosty\WpUtilities\Plugin\HooksTrait; /** * Class WpSettingsApi * * @package Dwnload\WpSettingsApi */ class WpSettingsApiScripts extends AbstractHookProvider { public function addHooks(array $scripts): void { \add_filter(WpSettingsApi::FILTER_PREFIX . 'admin_scripts', [$this, 'adminScripts']); \add_filter(WpSettingsApi::FILTER_PREFIX . 'admin_styles', [$this, 'adminStyles']); } /** * The default script needs to be moved from the vendor directory somewhere into our app since the * vendor directory is outside of the doc root. * @param Script[] $scripts * @return array */ public function adminScripts(array $scripts): array { \array_walk($scripts, function (Script $script, int $key) use (&$scripts) { switch ($script->getHandle()) { case WpSettingsApi::ADMIN_SCRIPT_HANDLE: /** * If you're not using the `TheFrosty\WpUtilities\Plugin\AbstractHookProvider` * use `plugins_url()` in place of the `$this->getPlugin()->getUrl` or any other WP * function that will point to the asset. * (Should match `frontpack/composer-assets-plugin configs`) */ $scripts[$key]->setSrc($this->getPlugin()->getUrl('assets/js/admin.js')); break; case WpSettingsApi::ADMIN_MEDIA_HANDLE: /** * If you're not using the `TheFrosty\WpUtilities\Plugin\AbstractHookProvider` * use `plugins_url()` in place of the `$this->getPlugin()->getUrl` or any other WP * function that will point to the asset. * (Should match `frontpack/composer-assets-plugin configs`) */ $scripts[$key]->setSrc($this->getPlugin()->getUrl('assets/js/wp-media-uploader.js')); break; } $this->registerScript($script); }); return $scripts; } /** * The default style needs to be moved from the vendor directory somewhere into our app since the * vendor directory is outside of the doc root. * @param Style[] $styles * @return array */ public function adminStyles(array $styles): array { \array_walk($styles, function (Style $style, int $key) use (&$styles) { if ($style->getHandle() === WpSettingsApi::ADMIN_STYLE_HANDLE) { /** * If you're not using the `TheFrosty\WpUtilities\Plugin\AbstractHookProvider` * use `plugins_url()` in place of the `$this->getPlugin()->getUrl` or any other WP * function that will point to the asset. */ $styles[$key]->setSrc($this->getPlugin()->getUrl('assets/css/admin.css')); $this->registerStyle($style); } }); return $styles; } /** * If the script is not registered before being returned back to the filter the src still uses * the vendor directory file path. * @param Script $script */ private function registerScript(Script $script): void { \wp_register_script( $script->getHandle(), $script->getSrc(), $script->getDependencies(), $script->getVersion(), $script->getInFooter() ); } /** * If the style is not registered before being returned back to the filter the src still uses * the vendor directory file path. * @param Style $style */ private function registerStyle(Style $style): void { \wp_register_style( $style->getHandle(), $style->getSrc(), $style->getDependencies(), $style->getVersion(), $style->getMedia() ); } }