Ok so I have having trouble creating a custom admin page. I can create a custom page that saves the information no problem, however when I then create a submenu page as below and fill in the infromation through the wordpress dashboard it wipes the other previously saved data. Is this something to do with registering the settings?
Please note, code is tidier are uses require once in the fucntions but thought I would lay it out on here.
Thanks in advance
/* ======== Default Values ======== */
$blav_options = array(
'first_name' => 'Photographers First Name',
'surname' => 'Photographers Surname',
'city' => 'City',
'facebook' => 'Facebook',
'google' => 'Google',
'twitter' => 'twitter',
);
/* ======== Validations ======== */
function blav_validate_options( $input ) {
global $blav_options;
$settings = get_option( 'blav_options', $blav_options );
$input['first_name'] = wp_filter_nohtml_kses( $input['first_name'] );
$input['surname'] = wp_filter_nohtml_kses( $input['surname'] );
$input['city'] = wp_filter_nohtml_kses( $input['city'] );
$input['facebook'] = wp_filter_nohtml_kses( $input['facebook'] );
$input['google'] = wp_filter_nohtml_kses( $input['google'] );
$input['twitter'] = wp_filter_nohtml_kses( $input['twitter'] );
return $input;
}
/* ======== Add Actions ======== */
add_action( 'admin_init', 'theme_settings_init' );
add_action( 'network_admin_menu', 'blavou' );
add_action( 'admin_menu', 'master' );
/* ======== Add Pages to Master Menu ======== */
function master() {
add_menu_page( __( 'Blavou' ), __( 'Blavou'), 'manage_options', 'blav-index- sites', 'blavou_index_sites');
add_submenu_page( 'blav-index-sites', 'Setup Index', 'Setup Index', 'manage_options', 'blav-setup-index', 'blavou_setup_index');
add_submenu_page( 'blav-index-sites', 'Setup Address', 'Setup Address', 'manage_options', 'blav-setup-address', 'blavou_setup_address');
}
/* ======== Register Settings ======== */
function theme_settings_init(){
register_setting( 'blav_theme_options', 'blav_options', 'blav_validate_options' );
}
/* ======== Content for Pages ======== */
function blavou_existing_sites() {
echo '<div id="blav-wrapper">';
echo '<div class="blav-nav-wrapper">';
echo '<ul class="blav-drop">';
echo '<form action="../">';
echo '<select name="mySelectbox" id="mySelectbox">';
echo '<option value="">Choose Existing</option>';
$sites = wp_get_sites();
foreach ($sites as $site) {
$details = get_blog_details($site['blog_id']);
printf( '<option value="%s">%s</option>', 'http://'.$site['domain'].'/wp-admin/', $details->blogname );
}
echo '</select>';
echo '<input type="button" onclick="window.open(this.form.mySelectbox.options[this.form.mySelectbox.selectedIndex].value,\'_top\')" value="Confirm">';
echo '</form>';
echo '</ul>';
echo '</div>';
echo '</div>';
}
function blavou_setup_index() {
global $blav_options;
if ( ! isset( $_REQUEST['updated'] ) )
$_REQUEST['updated'] = false;
?>
='updated'<p>Settings Saved. <a href='?page=blav-setup-address'>Continue Setup</a>.</p></div>";
} ?>
<div id="blav-wrapper">
<div class="blav-nav-wrapper">
<h5 class="standard-title">General Information</h5>
<form method="post" action="options.php" class="standard-form">
= get_option(
<input type="text" name="blav_options[first_name]" value="<?php esc_attr_e($settings['first_name']); ?>" ></input>
<input type="text" name="blav_options[surname]" value="<?php esc_attr_e($settings['surname']); ?>"></input>
<input type="text" name="blav_options[city]" value="<?php esc_attr_e($settings['city']); ?>"></input>
<input type="submit" value="Save"></input>
</form>
</div>
</div>
= false;
?
='updated'<p>Settings Saved. <a href='?page=blav-setup-social'>Continue Setup</a>.</p></div>";
} ?>
<div id="blav-wrapper">
<div class="blav-nav-wrapper">
<h5 class="standard-title">Facebook, Google and Twitter</h5>
<form method="post" action="options.php" class="standard-form">
= get_option(
<input type="text" name="blav_options[facebook]" value="<?php esc_attr_e($settings_address['facebook']); ?>"></input>
<input type="text" name="blav_options[google]" value="<?php esc_attr_e($settings_address['google']); ?>"></input>
<input type="text" name="blav_options[twitter]" value="<?php esc_attr_e($settings_address['twitter']); ?>"></input>
<input type="submit" value="Save"></input>
</form>
</div>
</div>
All the best