Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Modify the Theme My Login widget title and user links displayed when using the Memberlite theme (https://memberlitetheme.com).
<?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
You can’t perform that action at this time.