I am getting a bunch of notices in Theme-Checker for my settings api init function. The notices are all for ‘undefined index’ in the $_REQUEST array. Here is the code :
<?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()
?>
I hook this into ‘admin-init’. Am I doing something silly here? Do I hook it somewhere else? Should I just ignore the notices?
Try it like this:
You have to check for a certain field of
$_REQUEST
(or$_POST
etc.) before accessing it—or you get warnings.