I'm creating an options panel for a theme on my localhost that's stored within the options.php file. My options panel will have two main loops. The first is to list the different sections and the second will create those sections. I just wrote the first loop and it doesn't display anything upon running. The code for this loop with some surrounding html is:
<aside>
<nav>
<ul>
<?php
foreach ($options as $value){
switch ( $value['type'] ){
case 'section':
echo '<li><a>'.$value['name'].'</li></a>';
break;
}
}
?>
</ul>
</nav>
</aside>
I don't see anything wrong with this though. This brings me to believe that something is wrong with a different part of my code so here's the entire options.php file:
<?php
//theme vars
$themename = "Fuckin Round";
$shortname = "fuckinround";
$options = array();
function theme_options(){
global $themename, $shortname, $options;
$options = array (
array("name" => "General Settings",
"type" => "section"),
array("type" => "open"),
array("name" => "Type of Logo",
"desc" => "Select your logo type ( Image or Text )",
"id" => $shortname."_type_of_logo",
"type" => "select",
"options" => array("text", "logo"),
"std" => "text"),
array("name" => "Logo Upload",
"desc" => "Upload images using the native media uploader, or define the URL directly",
"id" => $shortname."_logo_upload",
"type" => "imageupload",
"std" => ""),
array("name" => "Logo Text",
"desc" => "Enter text for logo",
"id" => $shortname."_logo_text",
"type" => "text",
"std" => ""),
array("name" => "Logo Slogan",
"desc" => "Enter text for logo slogan",
"id" => $shortname."_logo_slogan",
"type" => "text",
"std" => ""),
array("name" => "Custom Favicon",
"desc" => "Upload a 16px x 16px Png/Gif image that will represent your website's favicon",
"id" => $shortname."_favicon_upload",
"type" => "imageupload",
"std" => ""),
array("type" => "close"),
array("name" => "Styling Options",
"type" => "section"),
array("type" => "open"),
array("name" => "Background Color",
"desc" => "Pick a color for the background",
"id" => $shortname."_background_color",
"type" => "color",
"std" => "#ffffff"),
array("name" => "Body Color",
"desc" => "Pick a color for the body",
"id" => $shortname."_body_color",
"type" => "color",
"std" => "#ffffff"),
array("type" => "close"),
array("name" => "Footer Options",
"type" => "section"),
array("type" => "open"),
array("name" => "Copyright Text",
"desc" => "Enter text for copyright in footer (if empty it will be removed)",
"id" => $shortname."_footer_text",
"type" => "text",
"std" => "Copyright TestSite.com"),
array("type" => "close")
);
}
//add options page
function fuckinround_add_admin(){
global $themename, $shortname, $options;
if ( $_GET['page'] == basename(__FILE__) ){
if ( 'save' == $_REQUEST['action'] ) {
//protect against request forgery
check_admin_referer('theme-save');
//save the options
foreach ($options as $value) {
if( isset( $_REQUEST[ $value['id'] ] ) ) {
update_option( $value['id'], $_REQUEST[ $value['id'] ] );
} else {
delete_option( $value['id'] );
}
}
header("Location: themes.php?page=options.php&saved=true");
die;
} else if ( 'reset' == $_REQUEST['action'] ) {
//protect against request forgery
check_admin_referer('theme-reset');
//delete the options
foreach ($option as $value) {
delete_option( $value['id'] );
}
header("Location: themes.php?page=options.php&reset=true");
die;
}
}
add_theme_page($themename." Options", "$themename Options", 'edit_themes', basename(__FILE__), 'fuckinround_admin');
}
add_action('admin_menu' , 'fuckinround_add_admin');
//main function
function fuckinround_admin() {
global $themename, $shortname, $options;
//saved or reset messages
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>';
//form
?>
<header>
<h1><?php echo $themename; ?></h1>
</header>
<aside>
<nav>
<ul>
<?php
foreach ($options as $value){
switch ( $value['type'] ){
case 'section':
echo '<li><a>'.$value['name'].'</li></a>';
break;
}
}
?>
</ul>
</nav>
</aside>
<main>
<?php
//loop 2
?>
</main>
<footer>
<form method="post">
<?php wp_nonce_field('theme-save'); ?>
<p class="submit">
<input name="save" type="submit" value="Save changes" class="button-primary" />
<input type="hidden" name="action" value="save" />
</p>
</form>
<form method="post">
<?php wp_nonce_field('theme-reset'); ?>
<p class="submit">
<input name="reset" type="submit" value="Reset changes" />
<input type="hidden" name="action" value="reset" />
</p>
</form>
</footer>
<?php
}
?>
I've read through this code multiple times and can't find anything that would cause the loop not to work properly. I'd appreciate it very much if you guys could give it a look and let me know if you find anything. Thanks in advance. Sorry about the immature theme name btw.
echo '<li><a>'.$value['name'].'</li></a>';
but obviously that isn't the issue. I haven't been through all of your code, but have you debugged? What doesvar_dump($options)
display if placed immediately insideforeach ($options as $value){
?