Skip to content

Instantly share code, notes, and snippets.

@vikastyagi87
Last active July 20, 2020 18:51
Show Gist options
  • Save vikastyagi87/444b0ad791fd0fe47d4ff15fb48705fe to your computer and use it in GitHub Desktop.
Save vikastyagi87/444b0ad791fd0fe47d4ff15fb48705fe to your computer and use it in GitHub Desktop.
Load js file from in wp-admin only shop manager user through functions.php file
$user = wp_get_current_user();
$allowed_roles = array('shop_manager');
if( array_intersect($allowed_roles, $user->roles ) ) {
//Load JavaScript for admin panel (wp-admin/backend)
add_action( 'admin_enqueue_scripts', 'hide_admin_menu_load_custom_script' );
function hide_admin_menu_load_custom_script() {
wp_enqueue_script('custom_js', get_stylesheet_directory_uri() .'/js/custom.js', array('jquery'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment