Skip to content

Instantly share code, notes, and snippets.

@mattiasghodsian
Last active April 28, 2023 08:34
Show Gist options
  • Save mattiasghodsian/3ceff7a0d0dfb0216308fe1e65414ad7 to your computer and use it in GitHub Desktop.
Save mattiasghodsian/3ceff7a0d0dfb0216308fe1e65414ad7 to your computer and use it in GitHub Desktop.
[WordPress] Menu change link source by user role
/**
* 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