My apologies for being rude and not supplying adequate information. I am using a role manager plugin and I added this bit of code.
Note: This isn't an ideal fix as you must edit core WordPress files but I couldn't find another way
wp-includes/nav-menu-template.php
<?php
...
class Walker_Nav_Menu extends Walker {
...
function start_el(&$output, $item, $depth, $args) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="' . esc_attr( $class_names ) . '"';
// Check to see if the user is logged in
if ( get_post_meta( $item->object_id , '_members_only' , true ) == 'true' ) {
if ( is_user_logged_in() )
{
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
}
}
else
{
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
}
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= '';
$item_output .= $args->after;
// Check to see if the user is logged in
if ( get_post_meta( $item->object_id , '_members_only' , true ) == 'true' ) {
if ( is_user_logged_in() )
{
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
else
{
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
}
...
That checks for a meta value called _members_only and if it has a value of 'true' then the page is only displayed in the navigation if you're logged in. You'll need to add similar code to your page template files, as well as this in functions.php or a plugin
wp-content/themes/your-theme/functions.php
<?php
function ibew2010_add_sidebar_meta_box() {
add_meta_box( 'ibew_sidebar_text' , 'Sidebar Content' , 'create_ibew2010_sidebar_meta' , 'page' , 'normal' , 'high' );
add_meta_box( 'ibew_member_ony' , 'Members Only' , 'create_ibew2010_members_meta' , 'page' , 'side' , 'high' );
}
add_action( 'add_meta_boxes' , 'ibew2010_add_sidebar_meta_box' );
function create_ibew2010_sidebar_meta() {
global $post;
$meta_box_value = get_post_meta( $post->ID , '_sidebar_content_ibew' , true );
echo '<input type="hidden" name="ibew2010_sidebar_nonce" id="ibew2010_sidebar_nonce" value="' . wp_create_nonce( 'ibew2010_sidebar' ) . '" />';
the_editor( $meta_box_value , 'sidebar_content_ibew' , 'title' , false );
echo '<div style="height:13px;width:100%;"> </div>';
}
function create_ibew2010_members_meta() {
global $post;
$meta_box_value = get_post_meta( $post->ID , '_members_only' , true );
if ( $meta_box_value == 'true' ) {
$meta_box_value = 'checked="checked"';
}
echo '<input type="checkbox" name="members_only" id="members_only" value="true" '.$meta_box_value .' /> Restrict To Members?';
}
/* When the post is saved, saves our custom data */
function ibew2010_save_postdata( $post_id )
{
// verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times
if ( !wp_verify_nonce( $_POST['ibew2010_sidebar_nonce'], 'ibew2010_sidebar' ) )
{
return $post_id;
}
// verify if this is an auto save routine. If it is our form has not been submitted, so we dont want
// to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return $post_id;
// Save
update_post_meta( $post_id , '_sidebar_content_ibew' , $_POST['sidebar_content_ibew'] );
update_post_meta( $post_id , '_members_only' , $_POST['members_only'] );
return $post_id;
}
add_action( 'save_post' , 'ibew2010_save_postdata' );
I didn't change the name of my functions as anybody who needs this code can.