Skip to content

Instantly share code, notes, and snippets.

@KustomDeveloper
Created December 19, 2017 15:45
Show Gist options
  • Save KustomDeveloper/b5e3d4275feabf5e7cb5e633b4d6dc2e to your computer and use it in GitHub Desktop.
Save KustomDeveloper/b5e3d4275feabf5e7cb5e633b4d6dc2e to your computer and use it in GitHub Desktop.
<?php
add_action( 'admin_menu', 'wpto_add_admin_menu' );
add_action( 'admin_init', 'wpto_settings_init' );
function wpto_add_admin_menu( ) {
add_options_page( 'Theme Options ', 'Theme Options ', 'manage_options', 'theme_options_', 'wpto_options_page' );
}
function wpto_settings_init( ) {
register_setting( 'pluginPage', 'wpto_settings' );
add_settings_section(
'wpto_pluginPage_section',
__( 'Your section description', 'wordpress' ),
'wpto_settings_section_callback',
'pluginPage'
);
add_settings_field(
'wpto_text_field_0',
__( 'Settings field description', 'wordpress' ),
'wpto_text_field_0_render',
'pluginPage',
'wpto_pluginPage_section'
);
add_settings_field(
'wpto_text_field_1',
__( 'Settings field description', 'wordpress' ),
'wpto_text_field_1_render',
'pluginPage',
'wpto_pluginPage_section'
);
add_settings_field(
'wpto_text_field_2',
__( 'Settings field description', 'wordpress' ),
'wpto_text_field_2_render',
'pluginPage',
'wpto_pluginPage_section'
);
add_settings_field(
'wpto_text_field_3',
__( 'Settings field description', 'wordpress' ),
'wpto_text_field_3_render',
'pluginPage',
'wpto_pluginPage_section'
);
}
function wpto_text_field_0_render( ) {
$options = get_option( 'wpto_settings' );
?>
<input type='text' name='wpto_settings[wpto_text_field_0]' value='<?php echo $options['wpto_text_field_0']; ?>'>
<?php
}
function wpto_text_field_1_render( ) {
$options = get_option( 'wpto_settings' );
?>
<input type='text' name='wpto_settings[wpto_text_field_1]' value='<?php echo $options['wpto_text_field_1']; ?>'>
<?php
}
function wpto_text_field_2_render( ) {
$options = get_option( 'wpto_settings' );
?>
<input type='text' name='wpto_settings[wpto_text_field_2]' value='<?php echo $options['wpto_text_field_2']; ?>'>
<?php
}
function wpto_text_field_3_render( ) {
$options = get_option( 'wpto_settings' );
?>
<input type='text' name='wpto_settings[wpto_text_field_3]' value='<?php echo $options['wpto_text_field_3']; ?>'>
<?php
}
function wpto_settings_section_callback( ) {
echo __( 'This section description', 'wordpress' );
}
function wpto_options_page( ) {
?>
<form action='options.php' method='post'>
<h2>Theme Options </h2>
<?php
settings_fields( 'pluginPage' );
do_settings_sections( 'pluginPage' );
submit_button();
?>
</form>
<?php
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment