如果你在改动WordPress源码或者添加插件时需要一些变量,这时候可以选择在“设置”菜单下加一个子菜单,然后把要设置的内容放在这里。
[codesyntax lang="php"]
add_action('admin_menu', 'test_options_add_page');
function test_options_add_page()
{
add_options_page('SuRenPI', 'SuRenPI', 'administrator', 'SuRenPISetting', 'for_test_page');
}
add_action( 'admin_init', 'suren_admin_init' );
function suren_admin_init()
{
register_setting( 'suren_options_group', 'suren' );
}
function for_test_page()
{
$GLOBALS['suren'] = get_option('suren');
?>
<form method="post" action="options.php">
<?php settings_fields('suren_options_group');?>
<input type='text' name='suren[mail_user]' value='<?php echo $GLOBALS['suren']['mail_user'] ?>' />
<input type='text' name='suren[mail_password]' value='<?php echo $GLOBALS['suren']['mail_password'] ?>' />
<table>
<tr>
<td>Allow File Type:</td>
<td><input type='text' name='suren[allow_file_type]' value='<?php echo $GLOBALS['suren']['allow_file_type'] ?>' size='120' /></td>
</tr>
</table>
<input type='hidden' name="action" value='update' />
<input type='submit' value='submit' />
</form>
<?php
}
[/codesyntax]
[codesyntax lang="php"]
function suren_upload_mimes($existing_mimes = array())
{
$suren_opt = get_option('suren');
$suren_opt = $suren_opt['allow_file_type'];
$suren_opt = explode(',', $suren_opt);
for($index = 0; $index < count($suren_opt); $index++)
{
$mime = $suren_opt[$index];
$type = 'application/';
$type .= $mime;
$existing_mimes[$mime] = $type;
}
return $existing_mimes;
}
[/codesyntax]