我正在学习插件开发,我一直在保存插件选项表单数据。
我有一个插件选项页面,其中有三个字段要求编码视频数量、高度和宽度。
当我在其中输入值并点击save时,它只保存一个值,即视频数。
这是我的密码
<?php
add_action(\'admin_init\', \'ozh_sampleoptions_init\' );
add_action(\'admin_menu\', \'ozh_sampleoptions_add_page\');
// Init plugin options to white list our options
function ozh_sampleoptions_init(){
register_setting( \'ozh_sampleoptions_options\', \'ozh_sample\', \'ozh_sampleoptions_validate\' );
}
// Add menu page
function ozh_sampleoptions_add_page() {
add_options_page(\'Youtube Video Settings\', \'Youtube Video Settings\', \'manage_options\', \'ozh_sampleoptions\', \'ozh_sampleoptions_do_page\');
}
// Draw the menu page itself
function ozh_sampleoptions_do_page() {
?>
<div class="wrap">
<h2>Youtube Video Setting Options</h2>
<form method="post" action="options.php">
<?php settings_fields(\'ozh_sampleoptions_options\'); ?>
<?php $options = get_option(\'ozh_sample\'); ?>
<table class="form-table">
<tr valign="top"><th scope="row">No of videos:</th>
<td><input type="text" name="ozh_sample[sometext]" value="<?php echo $options[\'sometext\']; ?>" /></td>
</tr>
<tr valign="top"><th scope="row">Height:</th>
<td><input type="text" name="ozh_sample[hgt]" value="<?php echo $options[\'hgt\']; ?>" /></td>
</tr>
<tr valign="top"><th scope="row">Width:</th>
<td><input type="text" name="ozh_sample[wid]" value="<?php echo $options[\'wid\']; ?>" /></td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e(\'Save Changes\') ?>" />
</p>
</form>
</div>
<?php
}
// Sanitize and validate input. Accepts an array, return a sanitized array.
function ozh_sampleoptions_validate($input) {
// Our first value is either 0 or 1
//$input[\'option1\'] = ( $input[\'option1\'] == 1 ? 1 : 0 );
// Say our second option must be safe text with no HTML tags
$input[\'sometext\'] = wp_filter_nohtml_kses($input[\'sometext\']);
$input[\'hgt\'] = wp_filter_nohtml_kses($input[\'hgt\']);
$input[\'wid\'] = wp_filter_nohtml_kses($input[\'wid\']);
return $input;
}
$myoptions = get_option( \'ozh_sampleoptions_options\' );
echo \'Niraj\';
echo $options[\'sometext\'];
?>
它不能节省高度和宽度。我知道我必须努力<input type=\'hidden\' name=\'page_options\' value=\'vidNO\'/>
代码,但没有得到它,
有人能帮我吗???