Adding a Theme Options Panel, Not Writing to Database (add_option not working)

Just getting into developing a Theme Options panel and have it up and running but I’m trying to return a default and I’m not getting anything. When checking PHPMyAdmin I’m not getting anything written to the database, although the database has been created (‘my_theme_options’). Here is the code within my functions.php that is

if (get_option('my_theme_options')) {
 $theme_options = get_option('my_theme_options');
} else {
 add_option('my_theme_options', array(
    'footer_text' => 'MADE BY BEN STEWART'
 ));
 $theme_options = get_option('my_theme_options');
}

and then the code that creates the theme options panel itself:

add_action('admin_menu', 'theme_page_add');

function theme_page_add () {
add_submenu_page('themes.php', 'My Theme Options', 'Theme Options', 8, 
'themeoptions', 'theme_page_options');
}

function theme_page_options () {       
    global $theme_options;
    echo '<h2>Theme Options</h2>';
?>

<form action="themes.php?page=themeoptions" method="post">

<label for="footer_text">Footer Text: </label><input name="footer_text" id="footer_text" value="<?php echo $theme_options['footer_text']; ?>" /><br /><br />

<input type="submit" value="Update Options" name="submit" />

</form>
<?php
}

Again the panel loads fine, no errors anywhere ,just not getting anything written to the database, default values included. Once I’m able to start writing to the database I’m confident I’ll be able to implement the custom values into the theme, I’m just trying to get off the ground. Thank you!

Read more here: Adding a Theme Options Panel, Not Writing to Database (add_option not working)

Leave a Reply

Your email address will not be published. Required fields are marked *