Created
August 4, 2018 15:46
-
-
Save kimcoleman/64afa4be872e6f2eb92ece7643615baf to your computer and use it in GitHub Desktop.
Modify the Theme My Login widget title and user links displayed when using the Memberlite theme (https://memberlitetheme.com).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php //Do not copy this PHP tag into your code. | |
/** | |
* Modify the Theme My Login widget title and user links displayed when using the Memberlite theme | |
* https://memberlitetheme.com | |
* | |
* This code recipe changes the widget's title to "Welcome, Display_Name" for logged in users. | |
* | |
* It also removes the default user links included in the widget and replaces it with | |
* the same links as your "Members" menu as assigned under Appearance > Menus when using Memberlite. | |
* under Memberships > Pages. | |
* | |
* Add this code below to a plugin for theme customizations. | |
*/ | |
//Replace the Theme My Login widget's title with "Welcome, Display_Name" for logged in users. | |
function modify_tml_widget_title( $title, $instance, $id_base ) { | |
global $current_user, $pmpro_pages; | |
if ( is_user_logged_in() && $id_base === 'theme-my-login' ) { | |
$user_ID = $current_user->ID; | |
if ( ! empty( $pmpro_pages ) ) { | |
$account_page = get_post( $pmpro_pages['account'] ); | |
$user_account_link = '<a href="' . esc_url( pmpro_url( 'account' ) ) . '">' . preg_replace( '/\@.*/', '', $current_user->display_name ) . '</a>'; | |
} else { | |
$user_account_link = '<a href="' . esc_url( admin_url( 'profile.php' ) ) . '">' . preg_replace( '/\@.*/', '', $current_user->display_name ) . '</a>'; | |
} | |
$title = sprintf( __( 'Welcome, %s', 'memberlite' ), $user_account_link ); | |
} | |
return $title; | |
} | |
add_filter( 'widget_title', 'modify_tml_widget_title', 10, 3 ); | |
// Remove all user_links added via the Theme My Login widget's default logic. | |
function hide_tml_widget_user_links( $links ) { | |
$links = ''; | |
return $links; | |
} | |
add_filter ('tml_widget_user_links', 'hide_tml_widget_user_links' ); | |
// Display the "Members" menu as assigned under Appearance > Menus when using Memberlite. | |
function show_member_menu_tml_widget_user_panel( ) { | |
global $current_user; | |
$user_ID = $current_user->ID; | |
if ( $user_ID ) { | |
$member_menu_defaults = array( | |
'theme_location' => 'member', | |
'container' => 'nav', | |
'container_id' => 'member-navigation', | |
'container_class' => 'member-navigation', | |
'fallback_cb' => 'memberlite_member_menu_cb', | |
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', | |
); | |
} else { | |
$member_menu_defaults = array( | |
'theme_location' => 'member-logged-out', | |
'container' => 'nav', | |
'container_id' => 'member-navigation', | |
'container_class' => 'member-navigation', | |
'fallback_cb' => 'memberlite_member_menu_cb', | |
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', | |
); | |
} | |
wp_nav_menu( $member_menu_defaults ); | |
} | |
add_action( 'tml_widget_user_panel', 'show_member_menu_tml_widget_user_panel' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment