• Hello,
    I’m working on adding some Theme Options on a new theme I’m creating but I have a little problem creating more than one page for them.
    I’d like to have 2 or more pages for better organization but I’m not able to make it work. All my options appear on the same page although I have managed to create 2 menu points under “Appearance”
    This is the code that I have upto now.

    <?php
    $themename = "someThemeName";
    $shortname = "someShortName";
    $themeOptions   = array (
    
    //arrays, arrays, arrays
    
    );
    
    $cartOptions   = array (
    
    //arrays, arrays, arrays
    
    );
    
    function mytheme_add_themeOptions_admin() {
    
        global $themename, $shortname, $themeOptions;
    
        if ( $_GET['page'] == basename(__FILE__) ) {
    
            if ( 'save' == $_REQUEST['action'] ) {
    
                    foreach ($themeOptions as $value) {
                        update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
    
                    foreach ($themeOptions as $value) {
                        if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
    
                    header("Location: themes.php?page=functions.php&saved=true");
                    die;
    
            } else if( 'reset' == $_REQUEST['action'] ) {
    
                foreach ($themeOptions as $value) {
                    delete_option( $value['id'] ); }
    
                header("Location: themes.php?page=functions.php&reset=true");
                die;
    
            }
        }
    
    	add_theme_page($themename." Theme Options", "".$themename." Theme Options", 'edit_themes', basename(__FILE__), 'themeOptions_admin');
    
    }
    
    function mytheme_add_cartOptions_admin() {
    
        global $themename, $shortname, $cartOptions;
    
        if ( $_GET['page'] == basename(__FILE__) ) {
    
            if ( 'save' == $_REQUEST['action'] ) {
    
                    foreach ($cartOptions as $value) {
                        update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
    
                    foreach ($cartOptions as $value) {
                        if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ]  ); } else { delete_option( $value['id'] ); } }
    
                    header("Location: themes.php?page=functions.php&saved=true");
                    die;
    
            } else if( 'reset' == $_REQUEST['action'] ) {
    
                foreach ($cartOptions as $value) {
                    delete_option( $value['id'] ); }
    
                header("Location: themes.php?page=functions.php&reset=true");
                die;
    
            }
        }
    
    	add_theme_page($themename." Cart Options", "".$themename." Cart Options", 'edit_themes', basename(__FILE__), 'cartOptions_admin');
    }
    
    function themeOptions_admin() {
    
        global $themename, $shortname, $themeOptions;
    
        if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
        if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
    
    ?>
    <div class="wrap">
    <!-- my html output -->
    </div>
    <?php
    }
    
    function cartOptions_admin() {
    
        global $themename, $shortname, $cartOptions;
    
        if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>';
        if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>';
    
    ?>
    <div class="wrap">
    <!-- my html output -->
    </div>
    <?php
    }
    
    add_action('admin_menu', 'mytheme_add_themeOptions_admin');
    add_action('admin_menu', 'mytheme_add_cartOptions_admin');

    Please, can anybody help?

  • The topic ‘adding administration menus’ is closed to new replies.