admin管理员组文章数量:1327843
I want to add more post type and more role to the code below. The code is working great for single post type or role, any idea how to do that without breaking its function?
//Remove CSS custom post-types GRUP
add_action('admin_head', 'grup_custom_admin_post_css');
function grup_custom_admin_post_css() {
$current_user = wp_get_current_user();
if ( $current_user->roles[0] === 'custom_role' )
global $post_type;
if ($post_type == 'custom_post_types') {
echo "<style></style>";
}
}
Thanks for your help
I want to add more post type and more role to the code below. The code is working great for single post type or role, any idea how to do that without breaking its function?
//Remove CSS custom post-types GRUP
add_action('admin_head', 'grup_custom_admin_post_css');
function grup_custom_admin_post_css() {
$current_user = wp_get_current_user();
if ( $current_user->roles[0] === 'custom_role' )
global $post_type;
if ($post_type == 'custom_post_types') {
echo "<style></style>";
}
}
Thanks for your help
Share Improve this question asked Jul 31, 2020 at 12:00 jasawebjasaweb 519 bronze badges 2 |1 Answer
Reset to default 2its better to include your assets with admin_enqueue_scripts
for your question
add_action('admin_head', 'grup_custom_admin_post_css');
function grup_custom_admin_post_css()
{
$allow_post_types = array('custom_role', 'custom_role_2', 'etc');
$allow_roles = array('post_type', 'post_typ_2');
$current_user = wp_get_current_user();
if (array_intersect($current_user->roles, $allow_roles)) { // do something if user have one of these roles
global $post_type;
if ($post_type && in_array($post_type, $allow_post_types)) {
echo "<style></style>";
}
}
}
本文标签: plugin developmentadd more custom post types and custom role to the code
版权声明:本文标题:plugin development - add more custom post types and custom role to the code 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742218847a2435067.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$post_type
variable A or B or C or D etc, you don't need WP expertise to answer this, anybody with basic programming knowledge can solve the problem – Tom J Nowell ♦ Commented Jul 31, 2020 at 12:42