Advertisement
arie_cristianD

remove cpt on spesific user

Feb 4th, 2025
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. /**
  2.  * Remove CPT menu on spesific roles.
  3.  */
  4. function restrict_cpt_on_dashboard() {
  5.     if ( is_admin() ) {
  6.         $user             = wp_get_current_user();
  7.         $restricted_roles = array( 'author', 'contributor' );
  8.         if ( array_intersect( $restricted_roles, $user->roles ) ) {
  9.             remove_menu_page( 'edit.php?post_type=elementor_library' ); /* remove elementor library */
  10.         }
  11.     }
  12. }
  13.  
  14. /**
  15.  * Remove CPT on menu bar on spesific roles.
  16.  */
  17. function remove_cpt_on_menu_bar( $wp_admin_bar ) {
  18.     $user             = wp_get_current_user();
  19.     $restricted_roles = array( 'author', 'contributor' );
  20.     if ( array_intersect( $restricted_roles, $user->roles ) ) {
  21.         $wp_admin_bar->remove_node( 'new-e-floating-buttons' ); /* remove floating elements */
  22.         $wp_admin_bar->remove_node( 'new-elementor_library' ); /* remove elementor library */
  23.     }
  24. }
  25.  
  26. add_action( 'admin_menu', 'restrict_cpt_on_dashboard', 999 );
  27. add_action( 'admin_bar_menu', 'remove_cpt_on_menu_bar', 999 );
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement