wordpress - How to change author list in Authors dropdown in edit page display all user role if user logged as admin type of rol

Author dropdownI am using classic editor and in edit page herer is a 'Author' dropdown and I

Author dropdown

I am using classic editor and in edit page herer is a 'Author' dropdown and I want to modify value of this edit page (post type = 'page') authors dropdown. I want to show all users in this author dropdown of in edit page only when user logged as Admin/Administrator role type.

Want to change the list of users in the Author select dropdown on the edit page for Admin/Administrator role type users. I tried but not working for post type page.

I have 3 admin role user and when i logged as one of admin role type user i want all users are show in this author dropdown so admin can set any type of user as page(post type = page) author. currently by default only editors names are displaying in this author dropdown and i want to show all users.

I tried this without check user role but is not working for me in edit page in worpdress.

add_filter( 'wp_dropdown_users_args', 'change_user_dropdown', 10, 2 );

function change_user_dropdown( $query_args, $r ){
    // get screen object
    $screen = get_current_screen();

    // list users whose role is e.g. 'Author' for 'post' post type
    if( $screen->post_type == 'page' ):
        $query_args['role'] = array('Author');

        // unset default role 
        unset( $query_args['who'] );
    endif;

    

    return $query_args;
}

Author dropdown

I am using classic editor and in edit page herer is a 'Author' dropdown and I want to modify value of this edit page (post type = 'page') authors dropdown. I want to show all users in this author dropdown of in edit page only when user logged as Admin/Administrator role type.

Want to change the list of users in the Author select dropdown on the edit page for Admin/Administrator role type users. I tried but not working for post type page.

I have 3 admin role user and when i logged as one of admin role type user i want all users are show in this author dropdown so admin can set any type of user as page(post type = page) author. currently by default only editors names are displaying in this author dropdown and i want to show all users.

I tried this without check user role but is not working for me in edit page in worpdress.

add_filter( 'wp_dropdown_users_args', 'change_user_dropdown', 10, 2 );

function change_user_dropdown( $query_args, $r ){
    // get screen object
    $screen = get_current_screen();

    // list users whose role is e.g. 'Author' for 'post' post type
    if( $screen->post_type == 'page' ):
        $query_args['role'] = array('Author');

        // unset default role 
        unset( $query_args['who'] );
    endif;

    

    return $query_args;
}
Share Improve this question edited Nov 20, 2024 at 4:33 Sunshine asked Nov 18, 2024 at 11:20 SunshineSunshine 32 bronze badges 2
  • what do you need in this dropdown is the user is not administrator ? – mmm Commented Nov 18, 2024 at 12:49
  • I have 3 admin role user and when i logged as one of admin role type user i want all users are show in this author dropdown so admin can set any type of user as page(post type page) author. currently by default admin can see editors name in this author dropdown. – Sunshine Commented Nov 19, 2024 at 4:04
Add a comment  | 

2 Answers 2

Reset to default 0
add_filter('wp_dropdown_users_args', function ($query_args, $r) {
if (current_user_can('administrator')) {
    unset($query_args['who']);
}
return $query_args;
}, 10, 2);

as you don't explain if there is something to change when non administrator users edit a page, here is my answer to change the author list when the connected user has the capability edit_others_pages. you can change it according to your needs.

note also that the filter wp_dropdown_users_args works only on classical editor (like we see it on your screenshot) and not on gutenberg editor.

add_filter("wp_dropdown_users_args", function ($query_args, $parsed_args) {
    
    // the capability "edit_others_pages" can be change to another linked at the reason of the customisation
    if (current_user_can("edit_others_pages")) {
        
        // remove the filter on capabilities to return all users
        unset($query_args["capability"]);
        
    }
    
    
    return $query_args;
    
}, 10, 2);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745622347a4636595.html

相关推荐

  • 面试官:从三万英尺角度谈一下Ceph架构设计(1)

    把面试官当陪练,在找工作中才会越战越勇大家好我是小义同学,这是大厂面试拆解——项目实战系列的第3篇文章,如果有误,请指正。本文主要解决的一个问题,Ceph为例子 如何描述项目的架构。一句话描述:主要矛盾发生变化10年前的技术和方案,放到10

    1小时前
    00
  • 如何打造高效AI智能体?

    作者|Barry Zhang, Anthropic地址|出品|码个蛋(ID:codeegg)整理|陈宇明最近看到了 Anthropic 那篇著名的《Building effective agents》作者之一 Barry Zhang 在 2

    1小时前
    00
  • 20 万 POC,直接拿来用,这不是测试,这是拒绝服务!!!

    之前看到很多人分享 github 上的一个项目,自动收录全网 nuclei 模板文件,目前已经 19 万了,如果直接拿来对目标进行漏洞探测,无疑会对目标造成巨大伤害,意味着可能要对目标发起十九万次请求以上,可以说是一次小型的 DDoS 攻击

    1小时前
    00
  • 电脑开机会默认一件GHOST

    关于电脑开机会自己重装系统 前段时间电脑一开机就遇到会自己ghost的问题,而且一直再重复同样的操作,我点击restart的时候到开启页面又会自动ghost,而且此页面停留

    1小时前
    00
  • Prometheus配置docker采集器

    Prometheus 配置 Docker 采集器Prometheus 是一个开源的监控系统和时间序列数据库,广泛用于容器化环境中。通过监控 Docker 容器,用户可以实时获取服务性能、资源使用情况等信息。本文将介绍如何为 Docker 容

    56分钟前
    00
  • Power BI 无公式实现帕累托图表

    帕累托分析(Pareto Analysis),也被称为8020法则、关键少数法则,是一种常用的管理工具,用于识别和处理影响业务的主要因素。看到李伟坚老师在Excel使用Vega实现了花式帕累托(参考:Excel 零公式实现高级帕累托图表)

    52分钟前
    00
  • Go 语言 Mock 实践

    Mock 是软件测试中的一项关键技术,尤其在单元测试领域,可谓是“顶梁柱”般的存在,几乎不可或缺。它通过模拟真实对象的行为,使我们能在不依赖外部系统的情况下,专注测试代码的核心逻辑。对于测试开发、自动化测试,乃至性能测试中的某些场景,合理使

    50分钟前
    00
  • 3、win10重装系统后Mysql环境和数据的恢复

    因为电脑是机哥的原因,重装了好几次电脑,因为我习惯把软件都装在D盘。所以很多东西都还比较好恢复,在网上学会了怎么不卸载重装数据库,自己记录以备后面自己查

    47分钟前
    00
  • UCB的硅光MEMS OCS控制技术

    昨天写的旭创与nEye合作了一个64端口硅光OCS一、光电路交换技术概述(一)电交换与分组交换电路交换的概念源于早期的电话交换机,通过物理连接实现设备间的通信,就像早期打电话时,接线员手动连接线路一样。而分组交换则是

    40分钟前
    00
  • 重装系统只影响C盘吗?深入解析系统重装的全过程

    重装系统只影响C盘吗?深入解析系统重装的全过程 在计算机的日常使用中,重装系统是一个常见的操作,尤其是在系统出现故障、感染病毒或需要优化系统性能时。然而,许多用户对于重装系统的具体过程和影响存在误解,认为重装系统仅仅是对C盘进行清空和重置

    35分钟前
    10
  • 大模型驱动金融数据应用的实战探索

    近年来,人工智能技术的飞速发展正在重塑全球各行各业的生态格局,金融行业作为数据密集型领域,更是首当其冲。大模型凭借其强大的自然语言处理、逻辑推理和生成能力,逐渐成为金融数据应用的核心驱动力。本文将从行业背景与趋势、核心场景重构、产品能力提升

    34分钟前
    00
  • maxwell遇到的一则问题

    结论和原因maxwell的元数据库里面没有存储全部的schema数据(就是少数据了),导致相关表的DDL校验失败。PS:我这里maxwell的作用只是采集库表修改情况的统计粗粒度指标,因为之前maxwell在运行报错的时候,直接修改了pos

    31分钟前
    00
  • Windows Server20192022 Evaluation评估版未激活导致关机问题

    摘要:在安装Windows Server 20192022后,会出现系统版本为 Evaluation 评估版情况,如提示Windows许可证已到期,就

    29分钟前
    00
  • windows新建open ai密钥

    api链接 openai的api需要付费才能使用但好像系统变量不知道为啥用不了打印出来,获取到的是None可以用了

    26分钟前
    00
  • Windows系统密钥检测工具PIDKey 2.1中文版

    Windows系统密钥检测工具PIDKey 2.1中文版 【下载地址】Windows系统密钥检测工具PIDKey2.1中文版 Windows系统密钥检测工具PIDKey 2.1中文版是一款功能强大的工具,专为管理Win

    23分钟前
    00
  • 1.54G 雨晨 26100.3775 Windows 11 IoT 企业版 LTSC 24H2 极速版

    精简AERO外主题并增加一套壁纸主题(默认启用)误杀导致功能界面空白、因WMIC被默认移除系统可能会多次重启。 拒止连接 www.5909 拒止连接 www.mnpc 拒止连接 quark 拒止

    21分钟前
    00
  • 雨晨 26200.5516 Windows 11 IoT 企业版 LTSC 2024 轻装版

    简述:以下为YCDISM (雨晨作品自2025年03月25日起通用介绍,若无重大更改不再额外敖述) 全程由最新YCDISM2025脱机装载26100.1742_zh-cn_windows_11_

    19分钟前
    00
  • Java&Activiti7实战:轻松构建你的第一个工作流

    本文已收录在Github,关注我,紧跟本系列专栏文章,咱们下篇再续!

    17分钟前
    00
  • 用Xshell8配置密钥登陆

    1.首先在服务端查看root.sshauthorized_keys是否存在,这是存储公钥的文件,若不存在需新建此文件 2. 打开Xshell8,选择"新建",选择"新建用户密钥生成向导" 给用户

    15分钟前
    00
  • 设计模式:工厂方法模式(Factory Method)(2)

    当年做一个项目时,还不懂什么是设计模式,仅仅是按照经验完成了需求。回头看看,就是暗合桥接模式。但是,在整个需求实现过程中,甲方需要我在已经设计好的标准业务逻辑中添加非标的需求,因为,在他们眼里,从业务角度来看,是自然的拓展。如果当年我知道还

    10分钟前
    00

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信