redux框架面板外更新选项

Most of the time, options for your theme or plugin will be set via the options panel. But what if you have a need to update an option someplace else? Perhaps an option would need to be changed behind the scenes, based on certain conditions, can it be done?

大部分时间,你的主题或者插件的选项是通过将设置选项面板。但如果你有一个需要更新一someplace其他选项吗?一个选择可能会改变,需要的是背后的场景,基于一定的条件下,它能做什么?

You better believe it!你最好相信它!

SETting it all up 设置它起来

The Redux core includes a function titled set, which allows one to change any option on the fly. But to access this function we need to make one small change to your config file (sample-config.php by default, and what we’ll use in this example).

核心包括一个 set  函数,允许改变任何选项。要访问这个函数,我们需要稍微修改您的配置文件(这个例子中我们将使用默认sample-config.php)。

In the sample-config.php file, toward the bottom is the line new Redux_Framework_sample_config();. This is where the sample-config creates an object itself. We’ll need to assign this object to a global variable.

sample-config.php中,位于  new Redux_Framework_sample_config(); 这行。

配置文件创建了一个自己的项目,我们需要对这个对象设置全局变量。

修改这行

1
new Redux_Framework_sample_config();

1
2
3
global $sampleReduxFramework ;
 
$sampleReduxFramework = new Redux_Framework_sample_config();

Ready, SET, Go! 各就各位,预备,跑!

With the change made to the sample-config to hold an instance of itself in a global variable, we can now call set anywhere in the project, specifically to update a previously以前 set/saved option. The set function takes two parameters. The first is $opt_name, which accepts a string value representing the option name, set via the id argument of the options field array. The second parameter accepts the new value in mixed format (string, int, bool, etc). Before using the set function, the global variable representing the config class must be declared. In the above example, it would be $sampleReduxFramework. Then, use the ReduxFramework object to call set, as shown below:

用修改的配置文件实例了自身的一个变量,我们可以在任何地方调用设置的项目,具体到以前设置的更新/保存选项。该set函数需要两个参数集。第一个是$opt_name 通过选项字段的ID参数的数组。第二个参数接受新值以混合格式(字符串,整数,布尔等)。在使用set集合函数之前,全局变量的类的配置必须符合。在上面的例子,这将是$sampleReduxFramework。然后,使用该对象呼叫设置,下面的显示:

1
2
3
global $sampleReduxFramework
 
$sampleReduxFramework ->ReduxFramework->set( 'my_option' , 'its_value' );

That’s all there is to it. 这就是所有了。

Tagged: update option

Related Articles

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值