latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Menu items :: change based on member access?

Home Forums Community Forum Menu items :: change based on member access?

This topic contains 4 replies, has 3 voices. Last updated by  David Welch 4 years, 6 months ago.

Topic Author Topic
Posted: Friday Jun 15th, 2012 at 3:43 pm #16606
mike king
Username: mrking

Hi,

I am just wondering if s2Member allows for new menu bar items to appear after a member logs in?

Example

Everyone sees:
Home | Contact | News

One a user pays for access and logs in, the main menu would then read:
Home | Member Resources | Contact | News

Noting that I would like to use the ‘Appearance>>Menus’ functionality of WordPress.

Thanks,

Michael

List Of Topic Replies

Viewing 4 replies - 1 through 4 (of 4 total)
Author Replies
Author Replies
Posted: Friday Jun 15th, 2012 at 11:12 pm #16637

I’d love an answer for this one myself.

Posted: Saturday Jun 16th, 2012 at 12:21 am #16639
David Welch
Username: dwbiz05

Well, there are a couple of ways you can do this.

1. Create a separate custom menu for each.
2. Load the correct menu in your template file using the wp_nav_menu function like this:

<?php
//functions.php in your theme
add_action( 'init', 'register_my_menus' );

function register_my_menus() {

  register_nav_menus(

    array( 'public-menu' => __( 'Public Menu' ), 
    		'member-menu-1' => __( 'Member Menu 1' ),  
    		'member-menu-2' => __( 'Member Menu 2' ), 
    		'member-menu-3' => __( 'Member Menu 3' ))
  );

}
?>

Place something like this in your theme where the menu goes:

<?php 
if(current_user_can("access_s2member_level2")){
	wp_nav_menu(array('theme_location' => 'member-menu-2'));
}
else if(current_user_can("access_s2member_level1")){
	wp_nav_menu(array('theme_location' => 'member-menu-1'));
}
else {
	wp_nav_menu( array( 'theme_location' => 'public-menu' ) );
}
?>

Another option would be to use the wp_nav_menu_objects filter to add items to an existing menu like this in your functions.php file in your theme:

<?php
add_filter( 'wp_nav_menu_objects', 'add_menu_items', 10, 2 );

function add_menu_items( $sorted_menu_items, $args )
{
    $link1 = array (
        'title'            => 'Extra Page 1',
        'menu_item_parent' => 0,
        'ID'               => '',
        'db_id'            => '',
        'url'              => site_url('extra-page-1'); //basic site_url() with page or post slug
    );
    
    $link2 = array (
        'title'            => 'Extra Page 2',
        'menu_item_parent' => 0,
        'ID'               => '',
        'db_id'            => '',
        'url'              => site_url('extra-page-2'); //basic site_url() with page or post slug
    );

  	if(current_user_can("access_s2member_level1")){
		$sorted_menu_items[] = (object) $link1;
	}
	if(current_user_can("access_s2member_level2")){
		$sorted_menu_items[] = (object) $link2;
	}

	return $sorted_menu_items;
}
?>

Hope that helps,

Dave

Posted: Saturday Jun 16th, 2012 at 1:07 am #16640

Dude, you rock my face off! Thanks

Posted: Saturday Jun 16th, 2012 at 1:33 am #16641
David Welch
Username: dwbiz05

I did it quickly so if it doesn’t work, let me know.

Dave

Viewing 4 replies - 1 through 4 (of 4 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.