objectivco/wordpress-simple-settings 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

objectivco/wordpress-simple-settings

Composer 安装命令:

composer require objectivco/wordpress-simple-settings

包简介

A minimalist framework for managing WordPress plugin or theme settings.

README 文档

README

A minimalist framework for managing WordPress plugin or theme settings.

What Is This

This is a super simple framework for managing options in your WordPress plugin or theme. No cumbersome field section registration or other overhead is required. Just add some settings, update them, get them. Whatever.

It handles nonces, field names, and etc magically!

How Does It Work

WordPress Simple Settings is an abstract class which you extend in your own plugin class, theme class, or wherever you need it.

It takes a prefix, set by you and builds a settings object which is stored in a single option in the database.

This last bit should be a clue to what type of data you should store using this API: small amounts!

Just like the built-in Options API (which this framework uses!), you only want to use this for small bits of data. Don't try to store your customer database here!

Installation

The best way is to use composer: composer require objectivco/wordpress-simple-settings

You can also clone the repository into your lib or inc directory and require wordpress-simple-settings.php. But composer is better.

You can get a quick idea of how to implement in our example plugin: examples/awesome-plugin.

The gist is, you'll instantiate your plugin class as extension of WP_SimpleSettings. You'll then set a prefix as a class variable called $prefix.

If you don't set $prefix, the framework will try to use your child class name. But this will only work in PHP 5.3+. So, really, just set a prefix ok?

Change Log

0.7.2

  • Pass NULL as old value if there isn't an old value.

0.7.1

  • WordPress coding standards
  • Don't save to db for reach setting on save_settings(). Defer to the end.
  • Add action {$this->prefix}update_setting{$setting} that receives the old and new values during setting update.
  • Ignore .idea folder

0.3.0

  • Added $delimeter variable to allow switching array delimeter from semi-colon (default) to something else.

0.2.2

  • Added delete_setting.

0.2.1

  • Fix location of {$this->prefix}_settings_saved action to prevent inappropriate firing.

0.2

  • Improves storage and handling of array values.
  • Adds do_action("{$this->prefix}_settings_saved") hook for adding your own actions after plugin settings are saved.

0.1

  • Initial version.

Usage

Here are the basic functions available to you within your plugin.

add_setting($option_name, $value)

This is essentially a wrapper for update_setting that respectfully does not make any changes if the option in question is already set.

You'll most frequently use this in your activation hook.

delete_setting($option_name)

Removes setting.

get_setting($option_name, $type)

Retrieves a specific option. Returns string by default. If you specify array as $type, it will treat the value as a delimited string (default semi-colon) and return an array.

update_setting($option_name, $new_value)

Updates a specific option.

get_field_name($option_name, $type)

Gets an HTML field name. If you set $type to array, the field value will be treated as a delimited string (default semi-colon) and stored as an array.

the_nonce()

Call $YourPluginInstance->the_nonce() somewhere in your admin form to generate the nonce used to validate / save settings.

save_settings()

There is no need to call this unless you want to override the default functionality. This function will be called on admin_init and automagically saves settings, if the right nonce and $_REQUEST is set.

Settings Object

One of my goals in building this framework was to have an easily accessible settings object that can be used directly when the getters / setters are inconvenient. This is done by simply using $this->settings[$option_name].

Obviously this should be used in read-only applications. Setting values here will not update them in the database.

Feedback

I'm in no way claiming to have the perfect, final answer to managing options in WordPress themes or plugins.

The goal of this minimalist approach is that you can simply build your plugin rather than contorting it to work with more demanding APIs.

If you have any ideas for how I can improve on what I have here, please let me know!

objectivco/wordpress-simple-settings 适用场景与选型建议

objectivco/wordpress-simple-settings 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.09k 次下载、GitHub Stars 达 47, 最近一次更新时间为 2017 年 02 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 objectivco/wordpress-simple-settings 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 objectivco/wordpress-simple-settings 我们能提供哪些服务?
定制开发 / 二次开发

基于 objectivco/wordpress-simple-settings 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8.09k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 47
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 47
  • Watchers: 6
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2017-02-07