WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Theme option page reset button (1 post)

  1. Carla Izumi Bamford
    Member
    Posted 1 year ago #

    I'm debugging my theme options and I seem to have a small issue with the reset button:

    Notice: Undefined index: id in /home/sites/heteml/users47/0/0/0/000/web/work/wordpress/wp-content/themes/simplenotes/functions.php on line 198
    
    Notice: Undefined index: id in /home/sites/heteml/users47/0/0/0/000/web/work/wordpress/wp-content/themes/simplenotes/functions.php on line 198
    
    Notice: Undefined index: id in /home/sites/heteml/users47/0/0/0/000/web/work/wordpress/wp-content/themes/simplenotes/functions.php on line 198
    
    Warning: Cannot modify header information - headers already sent by (output started at /home/sites/heteml/users47/0/0/0/000/web/work/wordpress/wp-content/themes/simplenotes/functions.php:198) in /home/sites/heteml/users47/0/0/0/000/web/work/wordpress/wp-content/themes/simplenotes/functions.php on line 199

    I get the above errors when I try to reset the settings. I know I need to fix delete_option but I'm not sure how...
    Here's the code:

    <?php
    $themename = "Simplenotes";
    $shortname = "simplenotes";
    $options = array (
    	array(	"name" => "Theme option page",
    	"type" => "title"),
    	array(	"type" => "open"),
    "std" => __(""),
    
    	array(	"name" => "Twitter Account",
    	"desc" => "Enter your Twitter URL.",
    	"id" => $shortname."_twitter",
    	"type" => "text"),
    	"std" => "false",
    
    	array(	"name" => "Facebook Account",
    	"desc" => "Enter your Facebook URL.",
    	"id" => $shortname."_facebook",
    	"type" => "text"),
    	"std" => "false",
    
    	array(	"type" => "close")
    );
    function mytheme_add_admin() {
        global $themename, $shortname, $options;
        if ( isset($_GET['page']) && $_GET['page'] == basename(__FILE__) ) {
            if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'save' ) {
                    foreach ($options as $value) {
    			if( isset( $value['id'], $_REQUEST[ $value['id'] ] ) ) {
    				update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } }
                    foreach ($options as $value) {
    			if( isset( $value['id'], $_REQUEST[ $value['id'] ] ) ) {
    				update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); }
    		else {  } }
                    header("Location: themes.php?page=functions.php&saved=true");
                    die;
            } else if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'reset' ) {
                foreach ($options as $value) {
                     delete_option( $value['id'] ); }
                header("Location: themes.php?page=functions.php&reset=true");
                die;
            }
        }
        add_theme_page($themename." Options", "".$themename." Options", 'edit_themes', basename(__FILE__), 'mytheme_admin');
    }
    function mytheme_admin() {
        global $themename, $shortname, $options;
        if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'saved' ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
        if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'reset' ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
    ?>
    <div class="wrap">
    <h2><?php echo $themename; ?> settings</h2>
    <form method="post">
    <?php foreach ($options as $value) {
    	switch ( $value['type'] ) {
    		case "open":
    		?>
            <table width="100%" border="0" style="background-color:#eef5fb; padding:10px;">
    		<?php break;
    		case "close":
    		?>
            </table><br />
    		<?php break;
    		case "title":
    		?>
    		<table width="100%" border="0" style="background-color:#; padding:5px 10px;"><tr>
            	<td colspan="2"><h3 style="font-family:Georgia,'Times New Roman',Times,serif;"><?php echo $value['name']; ?></h3></td>
            </tr>
    		<?php break;
    		case 'text':
    		?>
            <tr>
                <td width="20%" rowspan="2" valign="middle"><strong><?php echo $value['name']; ?></strong></td>
                <td width="80%"><input style="width:400px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_option( $value['id'] ) != "") { echo get_option( $value['id'] ); } else { } ?>" /></td>
            </tr>
                <tr>
                    <td><small><?php echo $value['desc']; ?></small></td>
               </tr><tr><td colspan="2" style="margin-bottom:5px;border-bottom:1px solid #c0c0c0;">&nbsp;</td></tr><tr><td colspan="2">&nbsp;</td></tr>
            <?php 		break;
    }
    }
    ?>
    <!--</table>-->
    <p class="submit">
    <input name="save" type="submit" value="Save changes" />
    <input type="hidden" name="action" value="save" />
    </p>
    </form>
    <form method="post">
    <p class="submit">
    <input name="reset" type="submit" value="Reset" />
    <input type="hidden" name="action" value="reset" />
    </p>
    </form>
    <?php
    }
    add_action('admin_menu', 'mytheme_add_admin');
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 1 year ago by Carla Izumi Bamford
  • This topic is resolved
  • WordPress version: 3.5.1

Tags