Advertisement
fauzanjeg

Add and Change Position of User Menu

Dec 23rd, 2020 (edited)
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. /* Add and Change Position of User Menu */
  2. add_filter('jnews_dropdown_link', 'jeg_nav_account_menu', 1);
  3.  
  4. function jeg_nav_account_menu($dropdown)
  5. {
  6.     if (is_user_logged_in()) {
  7.         /* If you need to get a list of roles */
  8.         // global $wp_roles;
  9.         // print("<pre>" . print_r($wp_roles->roles, true) . "</pre>");
  10.        
  11.         $roles = array('administrator', 'author', 'contributor'); /* Set Roles */
  12.         $user  = wp_get_current_user(); /* Get Role User */
  13.  
  14.         foreach ($roles as $role) {
  15.             if (in_array($role, $user->roles)) {
  16.                 $temp = $dropdown;
  17.                 unset($dropdown);
  18.  
  19.                 /* Set the position under this code. */
  20.  
  21.                 $dropdown['new_menu'] = array( /* New Menu */
  22.                     'text' => 'New Menu',
  23.                     'url' => 'http://jnews.io'
  24.                 );
  25.  
  26.                 $dropdown['account'] = true; /* Set Position of My Account || If not initialized or set to false, the position will always be at the top */
  27.  
  28.                 $dropdown['new_menu2'] = array( /* New Menu 2 */
  29.                     'text' => 'New Menu 2',
  30.                     'url' => 'http://jnews.io'
  31.                 );
  32.  
  33.                 $dropdown['logout'] = $temp['logout']; /* Set Position of logout || Don't delete this initialization, just move the position */
  34.  
  35.                 /* Finish adjusting the Position */
  36.  
  37.                 return $dropdown;
  38.             }
  39.         }
  40.         return $dropdown;
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement