Last active
April 28, 2023 08:34
-
-
Save mattiasghodsian/3ceff7a0d0dfb0216308fe1e65414ad7 to your computer and use it in GitHub Desktop.
[WordPress] Menu change link source by user role
This file contains 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
/** | |
* Title: Menu change link source by user role | |
* Description: Changes source(href) list all venues link by user role | |
* Author: Mattias Ghodsian | |
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian | |
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5 | |
*/ | |
add_filter( 'nav_menu_item_args', 'change_menu_link_by_user_role', 10, 2 ); | |
function change_menu_link_by_user_role( $args, $item ) { | |
// if ( 'primary' !== $args->theme_location ) { | |
// return $args; | |
// } | |
$is_role1 = current_user_can( '???' ); | |
$is_role2 = current_user_can( '???' ); | |
if ( $is_role1 or $is_role2 ) { | |
if ( strtolower( $item->post_title ) === 'list all venues' ) { | |
$item->url = get_home_url() . '/something'; | |
} | |
} | |
return $args; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment