挂接设置API init的位置

时间:2013-12-30 作者:Chris

我在主题检查器中收到了一堆关于设置api init函数的通知。这些通知都是针对$\\u请求数组中的“未定义索引”的。代码如下:

<?php

function typesetter_settings_api_init () {

    if ($_REQUEST[\'update-settings\']) {
        typesetter_save_settings();
    }
    register_sections();

    $current = $_REQUEST[\'tab\'] ? $_REQUEST[\'tab\'] : \'page\';
    $page = \'typesetter_options_\'.$current;

    $callback = \'typesetter_render_settings_field\';
    foreach ( typesetter_get_sections() as $section ) {
        foreach ( typesetter_get_settings_fields($section) as $field ) {
            add_settings_field(
                $field[\'id\'], // $id
                $field[\'title\'], // $title
                $callback, // $callback
                $page, // $page
                $field[\'section\'], // $section
                array(
                    \'id\' => $field[\'id\'],
                    \'type\' => $field[\'type\'],
                    \'choices\' => $field[\'choices\'],
                    \'desc\' => $field[\'desc\'],
                    \'class\' => $field[\'class\'],
                    \'std\' => $field[\'std\']
                )
            );
            // Register my setting so that $_POST handling is done
            register_setting($page, $field[\'id\']);

        }
    }

}// typesetter_settings_api_init()

?>
我将其挂接到“admin init”中。我是在做傻事吗?我要把它挂在别的地方吗?我应该无视这些通知吗?

1 个回复
最合适的回答,由SO网友:tfrommen 整理而成

可以这样尝试:

if (isset($_REQUEST[\'tab\']) && $_REQUEST[\'tab\']) {
    typesetter_save_settings();
}
register_sections();

$current = isset($_REQUEST[\'tab\']) ? $_REQUEST[\'tab\'] : \'page\';
您必须检查$_REQUEST (或$_POST 访问之前&mdash;否则会收到警告。

结束

相关推荐