这是从我的functions.php
使用前缀rl
.
希望这对你有帮助。你可以做个假设current_user_can
如果只想让管理员看到此字段,如果为true,则运行rl_register_settings_area()
.
/**
* Adds a settings section to general settings in WordPress admin.
* @return null
*/
function rl_register_settings_area() {
add_settings_section( \'rl_settings_section\', get_bloginfo( \'name\' ) . \' Settings\', \'rl_setting_prepended_text\', \'general\');
add_settings_field( \'rl_setting_address1\', \'Address\', \'rl_create_settings_field\', \'general\', \'rl_settings_section\' );
register_setting( \'general\', \'rl_setting_address1\' );
register_setting( \'general\', \'rl_setting_address2\' );
register_setting( \'general\', \'rl_setting_address3\' );
register_setting( \'general\', \'rl_setting_address4\' );
register_setting( \'general\', \'rl_setting_address5\' );
}
add_action( \'admin_menu\', \'rl_register_settings_area\' );
function rl_create_settings_field() {
?>
<form>
<input name="rl_setting_address1" type="text" value="<?php echo get_option(\'rl_setting_address1\'); ?>" class="code" /> <br />
<input name="rl_setting_address2" type="text" value="<?php echo get_option(\'rl_setting_address2\'); ?>" class="code" /> <br />
<input name="rl_setting_address3" type="text" value="<?php echo get_option(\'rl_setting_address3\'); ?>" class="code" /> <br />
<input name="rl_setting_address4" type="text" value="<?php echo get_option(\'rl_setting_address4\'); ?>" class="code" /> <br />
<input name="rl_setting_address5" type="text" value="<?php echo get_option(\'rl_setting_address5\'); ?>" class="code" /> <br />
</form>
<?php
}
function rl_setting_prepended_text() {
echo \'Change address of your company\';
}