I'm working on a WordPress site where I want to hide just one page from the navigation until the visitor agrees to the "terms and conditions". The sidebar has a single checkbox, and submit button, on the homepage for the user to agree to the terms. Once agreed, I want the hidden page to show on the navigation, and the sidebar to disappear for the remainder of that session.
I think I'm close, but I've been staring at this TOO long, and you know how that goes! Here are the relevant sections (site is myresultz.us/)...
...in the Main Index Template...
<?php
session_start();
// If session vars aren't set, try to set them with a cookie
if (!isset($_SESSION['tcagreed'])) {
if (isset($_COOKIE['tcagreed']) {
$_SESSION['tcagreed'] = $_COOKIE['tcagreed'];
}
}
get_header();
?>
...in the header...
<div class="right">
<?php
if (isset ($_POST['submit'])) {
//grab the form data from the POST
$tcagreed = $_POST['tcagreed'];
echo '$tcagreed';
if (!empty($tcagreed)) {
setcookie('tcagreed');
}
}
if (isset($_COOKIE['tcagreed'])) {
wp_page_menu(array('menu_class' => 'nav'));
}
else {
wp_page_menu(array('menu_class' => 'nav', 'exclude' => 'Keywords' ));
}
?>
</div>
...on the home page...
<form id="tc" action="index.php" method="post">
<table>
<tbody>
<tr>
<td style="padding-bottom: 8px;"><input type="checkbox" name="tcagreed" value="tcagreed" />I've read, and agree to, the Terms and Conditions.</td>
</tr>
<tr>
<td><input name="submit" type="submit" value="Submit" /></td>
</tr>
</tbody>
</table>
</form></div>
Would greatly appreciate anyone taking the time to give me a fresh perspective on the coding.