solutionbox/wordpress-settings-framework
Composer 安装命令:
composer require solutionbox/wordpress-settings-framework
包简介
README 文档
README
The WordPress Settings Framework aims to take the pain out of creating settings pages for your WordPress plugins by effectively creating a wrapper around the WordPress settings API and making it super simple to create and maintain settings pages.
This repo is actually a working plugin which demonstrates how to implement SBSA in your plugins. See src/sbsa-test.php
for details.
You can use this framework with composer if you are using auto loading in your plugin.
Installation
composer require solutionbox/wordpress-settings-framework
Setting Up Your Plugin
- Install the package via composer.
- Create a "settings" folder in your plugin root.
- Create a settings file in your new "settings" folder (e.g.
settings-general.php)
Now you can set up your plugin like:
use Solution_Box_Settings; class SBSATest { /** * @var string */ private $plugin_path; /** * @var WordPressSettingsFramework */ private $sbsa; /** * SBSATest constructor. */ function __construct() { $this->plugin_path = plugin_dir_path( __FILE__ ); $this->sbsa = new Solution_Box_Settings\SettingsAPI( $this->plugin_path . 'src/settings/example-settings.php', 'my_example_settings' ); // Add admin menu add_action( 'admin_menu', array( $this, 'add_settings_page' ), 20 ); // Add an optional settings validation filter (recommended) add_filter( $this->sbsa->get_option_group() . '_settings_validate', array( &$this, 'validate_settings' ) ); } /** * Add WooCommerce sub settings page. */ function add_settings_page() { $this->sbsa->add_settings_page( array( 'parent_slug' => 'woocommerce', 'page_title' => __( 'Page Title', 'text-domain' ), 'menu_title' => __( 'menu Title', 'text-domain' ), 'capability' => 'manage_woocommerce', ) ); } /** * Validate settings. * * @param $input * * @return mixed */ function validate_settings( $input ) { // Do your settings validation here // Same as $sanitize_callback from http://codex.wordpress.org/Function_Reference/register_setting return $input; } // ... }
Your settings values can be accessed like so:
// Get settings $this->sbsa->get_settings();
This will get either the saved setting values, or the default values that you set in your settings file.
Or by getting individual settings:
// Get individual setting $setting = Solution_Box_Settings\SettingsAPI::get_setting( 'prefix_settings_general', 'general', 'text' );
The Settings Files
The settings files work by filling the global $sbsa_settings array with data in the following format:
$sbsa_settings[] = array( 'section_id' => 'general', // The section ID (required) 'section_title' => 'General Settings', // The section title (required) 'section_description' => 'Some intro description about this section.', // The section description (optional) 'section_order' => 5, // The order of the section (required) 'fields' => array( array( 'id' => 'text', 'title' => 'Text', 'desc' => 'This is a description.', 'placeholder' => 'This is a placeholder.', 'type' => 'text', 'default' => 'This is the default value' ), array( 'id' => 'select', 'title' => 'Select', 'desc' => 'This is a description.', 'type' => 'select', 'default' => 'green', 'choices' => array( 'red' => 'Red', 'green' => 'Green', 'blue' => 'Blue' ) ), // add as many fields as you need... ) );
Valid fields values are:
id- Field IDtitle- Field titledesc- Field descriptionplaceholder- Field placeholdertype- Field type (text/password/textarea/select/radio/checkbox/checkboxes/color/file/editor/code_editor)default- Default value (or selected option)choices- Array of options (for select/radio/checkboxes)mimetype- Any valid mime type accepted by Code Mirror for syntax highlighting (for code_editor)
See settings/example-settings.php for an example of possible values.
API Details
new Solution_Box_Settings\SettingsAPI( string $settings_file [, string $option_group = ''] )
Creates a new settings option_group based on a settings file.
$settings_file- path to the settings file$option_group- optional "option_group" override (by default this will be set to the basename of the settings file)
Solution_Box_Settings\SettingsAPI::get_setting( $option_group, $section_id, $field_id )
Get a setting from an option group
$option_group- option group id.$section_id- section id (change to[{$tab_id}_{$section_id}]when using tabs.$field_id- field id.
Solution_Box_Settings\SettingsAPI::delete_settings( $option_group )
Delete all the saved settings from a option group
$option_group- option group id
Actions & Filters
Filters
sbsa_register_settings_[option_group]- The filter used to register your settings. Seesettings/example-settings.phpfor an example.[option_group]_settings_validate- Basically the$sanitize_callbackfrom register_setting. Use$sbsa->get_option_group()to get the option group id.sbsa_defaults_[option_group]- Default args for a settings field
Actions
sbsa_before_settings_page_[option_group]- Before setting page HTML is outputsbsa_after_settings_page_[option_group]- After setting page HTML is outputsbsa_before_settings_page_header_[option_group]- Before setting page header HTML is outputsbsa_after_settings_page_header_[option_group]- After setting page header HTML is outputsbsa_settings_sections_args_[option_group]- Section extra args for to wrap the section with HTML and extra class Moresbsa_before_field_[option_group]- Before a field HTML is outputsbsa_before_field_[option_group]_[field_id]- Before a field HTML is outputsbsa_after_field_[option_group]- After a field HTML is outputsbsa_after_field_[option_group]_[field_id]- After a field HTML is outputsbsa_before_settings_[option_group]- Before settings form HTML is outputsbsa_after_settings_[option_group]- After settings form HTML is outputsbsa_before_tabless_settings_[option_group]- Before settings section HTML is outputsbsa_after_tabless_settings_[option_group]- After settings section HTML is outputsbsa_before_settings_fields_[option_group]- Before settings form fields HTML is output (inside the<form>)sbsa_do_settings_sections_[option_group]- Settings form fields HTMLoutput (inside the<form>)sbsa_before_tab_links_[option_group]- Before tabs HTML is outputsbsa_after_tab_links_[option_group]- After tabs HTML is output
Examples
Credits
The WordPress Settings Framework was Cloned from iconicwp then converted into php package with more features.
Please contribute by reporting bugs and submitting pull requests.
Want to say thanks? Consider tipping me.
solutionbox/wordpress-settings-framework 适用场景与选型建议
solutionbox/wordpress-settings-framework 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 33 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 03 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wordpress-plugin」 「wordpress-settings」 「wordpress-settings-api」 「wordpess」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 solutionbox/wordpress-settings-framework 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 solutionbox/wordpress-settings-framework 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 solutionbox/wordpress-settings-framework 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Gutenberg like color palette field for ACF.
WordPress Plugin Framework
Helper class that lets you create options settings page securely and swiftly without dealing with WordPress Settings API.
~ Lightweight, Flexible & Rapid WP Development Framework ~
Wordpress plugin to change its password hashing mechanism with PHP native password_* set of functions.
Prevent SearchWP from logging searches when logged in eg. in the admin area
统计信息
- 总下载量: 33
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-23

