Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Last active April 9, 2018 18:57
Show Gist options
  • Save kimcoleman/c0f199f06fdb0ffd97b3a3c9b253556b to your computer and use it in GitHub Desktop.
Save kimcoleman/c0f199f06fdb0ffd97b3a3c9b253556b to your computer and use it in GitHub Desktop.
Allows all users to see the 'Member Menu' not only those with a level via Paid Memberships Pro.
<?php
/**
* Remove Memberlite's wp_nav_menu_items filter.
*/
function remove_memberlite_wp_nav_menu_items_filter() {
remove_filter( 'wp_nav_menu_items', 'memberlite_menus', 10, 2 );
}
add_action( 'after_setup_theme', 'remove_memberlite_wp_nav_menu_items_filter' );
/**
* Show Member Menu to all Logged In Users.
*
* Allows all users to see the 'Member Menu' not only those with a level via Paid Memberships Pro.
*/
function custom_memberlite_menus( $items, $args ) {
//is this the member menu location?
if ( $args->theme_location == 'member' ) {
if ( is_user_logged_in() ) {
//user is logged in and has a membership level
$items .= '<li><a href="'. esc_url( wp_logout_url() ) .'">' . __('Log Out','memberlite') . '</a></li>';
} else {
//not logged in
$items = '<li><a href="'. esc_url( wp_login_url() ) .'">' . __('Log In','memberlite') . '</a></li>';
$items .= '<li><a href="'. esc_url( wp_registration_url() ) .'">' . __('Register','memberlite') . '</a></li>';
}
}
//is this the primary menu location?
if ( $args->theme_location == 'primary' ) {
$nav_menu_search = get_theme_mod( 'nav_menu_search', false );
if ( ! empty( $nav_menu_search ) ) {
$items .= get_search_form( false );
}
}
return $items;
}
add_filter( 'wp_nav_menu_items', 'custom_memberlite_menus', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment