WordPress.org

Ready to get started?Download WordPress

Forums

Saving Theme Options (1 post)

  1. studioburst
    Member
    Posted 1 year ago #

    I've been using theme options in my themes for a while, and want to extend them by basically replicating them as a sub-menu so I can add further options.

    I believe the problem is caused in the way I have added the sub-menu, and how it's saving them (can you tell I'm not experienced in this area?) note the "functions.php" part, I think I'm going wrong here.

    Original theme options:

    function mytheme_add_admin() {
    		global $themename, $shortname, $options;
    		$optionvar = array();
    if ( isset($_GET['page']) && $_GET['page'] == basename(__FILE__) )  {
            if ( isset($_REQUEST['action']) && 'save' == $_REQUEST['action'] ) {
                    foreach ($options as $value) {
                        update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
                    foreach ($options as $value) {
                                if( isset( $_REQUEST[ $value['id'] ] ) ) {
                                                            $optionvar[$value['id']] = $_REQUEST[ $value['id']];
                                                    } else {
                                                            $optionvar[$value['id']] = null;
                                                    }
                                            }
                                    update_option( $shortname."_options", $optionvar  );
                                    header("Location: admin.php?page=functions.php&saved=true");
                    die;
    
            } else if( isset($_REQUEST['action']) && 'reset' == $_REQUEST['action'] ) {
    
                foreach ($options as $value) {
                    delete_option( $value['id'] ); }
    
                header("Location: admin.php?page=functions.php&reset=true");
                die;
    
            }
        }
    
        add_menu_page("MYOPTIONS", "MYOPTIONS", 'edit_themes', 'functions.php', 'mytheme_admin');
    }

    Replicated the above into a seperate sub-menu under the above main admin item, it works perfectly but just fails to save these extra options (no errors):

    function xxmytheme_add_admin() {
    		global $xxthemename, $xxshortname, $xxoptions;
    		$xxoptionvar = array();
    if ( isset($_GET['page']) && $_GET['page'] == basename(__FILE__) )  {
            if ( isset($_REQUEST['action']) && 'save' == $_REQUEST['action'] ) {
                    foreach ($xxoptions as $xxvalue) {
                        update_option( $xxvalue['id'], $_REQUEST[ $xxvalue['id'] ] ); }
                    foreach ($xxoptions as $xxvalue) {
                                if( isset( $_REQUEST[ $xxvalue['id'] ] ) ) {
                                                            $xxoptionvar[$xxvalue['id']] = $_REQUEST[ $xxvalue['id']];
                                                    } else {
                                                            $xxoptionvar[$xxvalue['id']] = null;
                                                    }
                                            }
                                    update_option( $xxshortname."_options", $xxoptionvar  );
                                    header("Location: admin.php?page=functions.php?page=extra&saved=true");
                    die;
    
            } else if( isset($_REQUEST['action']) && 'reset' == $_REQUEST['action'] ) {
    
                foreach ($xxoptions as $xxvalue) {
                    delete_option( $xxvalue['id'] ); }
    
                header("Location: admin.php?page=functions.php?page=extra&reset=true");
                die;
    
            }
        }
    
    add_submenu_page( 'functions.php', 'MYEXTRAOPTIONS', 'MYEXTRAOPTIONS', 'edit_themes', 'functions.php?page=extra', 'xxmytheme_admin' );  
    
    }

    These are only portions of the code but I believe it's where the problem lies.

    Can anyone spot where I've made a mistake, would really appreciate it as this would help me develop a much larger project.

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic