我正在为WordPress背面的主题创建一个选项面板。
目前它只是一个简单的形式。我收到错误警告:call_user_func()期望参数1是有效的回调,函数
'ea_display_section'未找到或无效的函数名称 第1260行的file / template.php
什么错了?这是我的代码
add_action( 'admin_init', 'ea_register_settings' );
function ea_register_settings()
{
register_setting( 'ea_theme_options', 'ea_theme_options', 'ea_validate_settings' );
// Add settings section
add_settings_section( 'ea_text_section', 'Text box Title', 'ea_display_section', 'ea_theme_options.php' );
// Create textbox field
$field_args = array(
'type' => 'text',
'id' => 'ea_textbox',
'name' => 'ea_textbox',
'desc' => 'Example of textbox description',
'std' => '',
'label_for' => 'ea_textbox',
'class' => 'css_class'
);
add_settings_field( 'example_textbox', 'Example Textbox', 'ea_display_setting', 'ea_theme_options.php', 'ea_text_section', $field_args );
}
function ea_display_setting($args)
{
extract( $args );
$option_name = 'ea_theme_options';
$options = get_option( $option_name );
switch ( $type ) {
case 'text':
$options[$id] = stripslashes($options[$id]);
$options[$id] = esc_attr( $options[$id]);
echo "<input class='regular-text$class' type='text' id='$id' name='" . $option_name . "[$id]' value='$options[$id]' />";
echo ($desc != '') ? "<br /><span class='description'>$desc</span>" : "";
break;
}
}
/**
* Callback function to the register_settings function will pass through an input variable
*/
function ea_validate_settings($input)
{
foreach($input as $k => $v)
{
$newinput[$k] = trim($v);
// Check the input is a letter or a number
if(!preg_match('/^[A-Z0-9 _]*$/i', $v)) {
$newinput[$k] = '';
}
}
return $newinput;
}