0


我刚开始使用 Wordpress (v. 3.6.1)。
我安装了 OptionTree,它似乎处理了主题选项页面。我想在用户保存此页面的更改后立即运行我的功能(在插件中或其他任何地方)。

到目前为止,我发现option-tree/includes/ot-settings-api.php生成表单并将表单操作设置为options.php(这是一个 wordpress 核心文件)。我正在考虑将操作更改为我的自定义 php 文件并处理保存过程,最后运行我自己的函数。但是这个解决方案看起来很丑陋。
我想知道是否有另一种方法可以完成工作。
谢谢。

4

1 回答 1

1

Thanks to @Sheikh Heera link (tutsplus) I could find a solution.
I think this is some kind of hack and I still don't know if it is the best way. Anyway I did this:

  1. Create a file your-theme-settings.php in your theme lib folder.
  2. Let Wordpress knows about your file by adding this code in your theme functions.php:

    include_once('lib/your-theme-settings.php');
    
  3. Add this code to your-theme-settings.php:

    function your_theme_register_settings() {
        register_setting('option_tree', 'option_tree', 'your_theme_validate_options');
    }
    
    function your_theme_validate_options($input) {
        // do whatever you have to do with $input.
    }
    
    add_action('admin_init', 'your_theme_register_settings');
    

In step 3, I put 'option_tree' as 1st and 2nd argument of register_settings function, because I noticed that the Option Group and Option Name of OptionTree plugin is option_tree.

I'm not sure if this is the best solution, so I would be glad if you shares your ideas.

于 2013-09-28T12:28:39.750 回答