uo_login_menu_item_process
Filters the login menu item arguments before processing to allow for modification.
add_filter( 'uo_login_menu_item_process', $callback, 10, 2 );
Description
Filters login menu items. Allows modification or removal of menu items before they are displayed. You can alter item properties or return an empty array to remove all items. Access and modify the menu item object and its arguments.
Usage
add_filter( 'uo_login_menu_item_process', 'your_function_name', 10, 2 );
Parameters
-
$menu_item(mixed) - This parameter holds the original array of menu items that will be processed.
-
$menu_args(mixed) - This parameter is the current menu item object being processed, containing details like its URL, title, and classes.
Return Value
The filtered value.
Examples
/**
* Example usage of the uo_login_menu_item_process filter.
*
* This filter allows you to modify the processing of login menu items.
* In this example, we'll conditionally remove a login menu item
* if the user is already logged in, and if it's not a modal login link.
*
* @param bool $should_process Whether to proceed with processing the menu item.
* @param object $menu_item The current menu item object.
* @param array $menu_args Arguments passed to the menu.
* @return bool Modified value of $should_process.
*/
function my_custom_login_menu_processing( $should_process, $menu_item, $menu_args ) {
// If the user is logged in, we might not want to show a "Login" link.
// This example assumes a standard WordPress login link.
// Adjust the condition if your login link is different.
if ( is_user_logged_in() ) {
// Check if the menu item URL is for logging in and not a modal.
if ( strpos( $menu_item->url, 'wp-login.php?action=logout' ) === false && // Exclude logout links
strpos( $menu_item->url, 'wp-login.php' ) !== false &&
strpos( $menu_item->url, '#ult-modal-open' ) === false ) { // Exclude modal login links
return false; // Do not process this menu item (effectively hide it)
}
}
// You can also add other conditional logic here.
// For example, only apply modifications on specific pages or for specific user roles.
// if ( is_page( 'my-specific-page' ) ) {
// // ... do something specific ...
// }
return $should_process; // Return the original or modified value
}
add_filter( 'uo_login_menu_item_process', 'my_custom_login_menu_processing', 10, 3 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/frontend-login-plus.php:3950
public static function uo_login_menu_items( $menu_items, $menu_args = array() ) {
global $post;
foreach ( $menu_items as $menu_key => &$menu_item ) {
if ( ( ! isset( $menu_item->url ) ) || ( empty( $menu_item->url ) ) || ( ! isset( $menu_item->classes ) ) || ( ! is_array( $menu_item->classes ) ) || ( empty( $menu_item->classes ) ) ) {
continue;
}
// Replace default wp-login.php with hash
/*if ( ( strpos( $menu_item->url, 'wp-login.php' ) !== false ) ) {
$login_page_id = self::get_login_redirect_page_id();
$login_page = '#ult-modal-open----ult-login';
if ( $login_page_id ) {
$login_page = get_permalink( $login_page_id ) . $login_page;
} else {
$login_page = site_url( 'wp-login.php' ) . $login_page;
}
$menu_item->url = $login_page;
}*/
if ( ( strpos( $menu_item->url, '#ult-modal-open' ) !== false ) ) {
if ( ! isset( $post->ID ) || $post->ID !== self::get_login_redirect_page_id() ) {
if ( apply_filters( 'uo_login_menu_item_process', true, $menu_item, $menu_args ) ) {
add_action(
'wp_footer',
array(
__CLASS__,
'load_login_modal',
)
);
}
}
}
}
return $menu_items;
}