I am trying to add some code to a theme that will allow the user to change the logo or have some text instead. I managed to find some code that otto posted to do the file upload.
I have added what I thought was how to add the other fields but they do not save for some reason and I am sure it is something very simple I have missed:
add_action('admin_init', 'ld_admin_init');
function ld_admin_init() {
register_setting( 'ld_options', 'ld_options', 'ld_options_validate' );
add_settings_section('ld_main', 'Upload', 'ld_section_text', 'ld');
add_settings_field('ld_setting_checkbox', 'Use image', 'ld_setting_checkbox', 'ld', 'ld_main');
add_settings_field('ld_setting_string', 'Logo text', 'ld_setting_string', 'ld', 'ld_main');
add_settings_field('ld_filename', 'File:', 'ld_setting_filename', 'ld', 'ld_main');
}
// add the admin options page
add_action('admin_menu', 'ld_admin_add_page');
function ld_admin_add_page() {
$mypage = add_theme_page('Logo', 'Logo', 'manage_options', 'ld', 'ld_options_page');
}
// display the admin options page
function ld_options_page() {
?>
<div class="wrap">
<h2>Logo settings</h2>
<p>You can upload a new logo.</p>
<form method="post" enctype="multipart/form-data" action="options.php">
<?php settings_fields('ld_options'); ?>
<?php do_settings_sections('ld'); ?>
<p class="submit">
<input type="submit" name="Submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" />
</p>
</form>
</div>
<?php
}
function ld_section_text() {
$options = get_option('ld_options');
echo '<p>Upload your file here:</p>';
if ($file = $options['file']) {
//var_dump($file);
echo "<img src='{$file['url']}' />";
}
}
function ld_setting_filename() {
echo '<input type="file" name="ld_filename" size="40" />';
}
function ld_setting_checkbox() {
$usetext = get_option('ld_options');
if($usetext['chkbox1']) { $checked = ' checked="checked" '; }
echo "<input ".$checked." id='plugin_chk1' name='ld_options[chkbox1]' type='checkbox' />";
}
function ld_setting_string() {
$logotext = get_option('ld_options');
echo "<input id='ld_logo_text' name='ld_options[text_string]' size='40' type='text' value='{$logotext['text_string']}' />";
}
function ld_options_validate($input) {
$newinput = array();
if ($_FILES['ld_filename']) {
$overrides = array('test_form' => false);
$file = wp_handle_upload($_FILES['ld_filename'], $overrides);
$newinput['file'] = $file;
}
return $newinput;
}
I would like to be able to set it up so they can upload the image and if the box is ticked the image is used for the logo else the text is displayed. I jsut need to get the info saved so i can use it in the output.