dongyong8071 2019-04-18 12:32
浏览 69

试图在多站点中为管理员获取非对象的属性“ID”

I'm using QAengine theme on my wordpress multisite. Here is the first part of the code used to avoid getting administrators listed within top users of the blog

function widget( $args, $instance ) {
    global $wpdb;

    $admins_id = array();
    $admins    = get_users( 'role=administrator' );
    //normal site
    if(!empty($admins)){
        foreach ($admins as $admin) {
            $admins_id[] = $admin->ID;
        }
    }
    //multisites
    if(is_multisite()){
        $super_admins = get_super_admins();
        if(!empty($super_admins)){
            foreach ($super_admins as $admin) {
                $admin       = get_user_by( 'slug', $admin );
                $admins_id[] = $admin->ID;  //$admin['ID'];
            }
        }
    }

}

I'm getting the error message "Trying to get property 'ID' of non-object" at the top of the 'top users list',which is due to $admins_id[] = $admin->ID;. Replacing $admin->ID by $admin['ID']; results in a blank page.

and this what I get for var_dump($admins)

array(1) { [0]=> object(WP_User)#5237 (8) { ["data"]=> object(stdClass)#5236 (12) { ["ID"]=> string(1) "1" ["user_login"]=> string(5) "admin" ["user_pass"]=> string(34) "$P$BByirivlLnImmFrkUwGXorARgM6yFY/" ["user_nicename"]=> string(4) "dmin" ["user_email"]=> string(27) "hamed.benyahia.01@gmail.com" ["user_url"]=> string(0) "" ["user_registered"]=> string(19) "2018-01-14 11:17:25" ["user_activation_key"]=> string(0) "" ["user_status"]=> string(1) "0" ["display_name"]=> string(5) "admin" ["spam"]=> string(1) "0" ["deleted"]=> string(1) "0" } ["ID"]=> int(1) ["caps"]=> array(1) { ["administrator"]=> bool(true) } ["cap_key"]=> string(15) "wp_capabilities" ["roles"]=> array(1) { [0]=> string(13) "administrator" } ["allcaps"]=> array(62) { ["switch_themes"]=> bool(true) ["edit_themes"]=> bool(true) ["activate_plugins"]=> bool(true) ["edit_plugins"]=> bool(true) ["edit_users"]=> bool(true) ["edit_files"]=> bool(true) ["manage_options"]=> bool(true) ["moderate_comments"]=> bool(true) ["manage_categories"]=> bool(true) ["manage_links"]=> bool(true) ["upload_files"]=> bool(true) ["import"]=> bool(true) ["unfiltered_html"]=> bool(true) ["edit_posts"]=> bool(true) ["edit_others_posts"]=> bool(true) ["edit_published_posts"]=> bool(true) ["publish_posts"]=> bool(true) ["edit_pages"]=> bool(true) ["read"]=> bool(true) ["level_10"]=> bool(true) ["level_9"]=> bool(true) ["level_8"]=> bool(true) ["level_7"]=> bool(true) ["level_6"]=> bool(true) ["level_5"]=> bool(true) ["level_4"]=> bool(true) ["level_3"]=> bool(true) ["level_2"]=> bool(true) ["level_1"]=> bool(true) ["level_0"]=> bool(true) ["edit_others_pages"]=> bool(true) ["edit_published_pages"]=> bool(true) ["publish_pages"]=> bool(true) ["delete_pages"]=> bool(true) ["delete_others_pages"]=> bool(true) ["delete_published_pages"]=> bool(true) ["delete_posts"]=> bool(true) ["delete_others_posts"]=> bool(true) ["delete_published_posts"]=> bool(true) ["delete_private_posts"]=> bool(true) ["edit_private_posts"]=> bool(true) ["read_private_posts"]=> bool(true) ["delete_private_pages"]=> bool(true) ["edit_private_pages"]=> bool(true) ["read_private_pages"]=> bool(true) ["delete_users"]=> bool(true) ["create_users"]=> bool(true) ["unfiltered_upload"]=> bool(true) ["edit_dashboard"]=> bool(true) ["update_plugins"]=> bool(true) ["delete_plugins"]=> bool(true) ["install_plugins"]=> bool(true) ["update_themes"]=> bool(true) ["install_themes"]=> bool(true) ["update_core"]=> bool(true) ["list_users"]=> bool(true) ["remove_users"]=> bool(true) ["promote_users"]=> bool(true) ["edit_theme_options"]=> bool(true) ["delete_themes"]=> bool(true) ["export"]=> bool(true) ["administrator"]=> bool(true) } ["filter"]=> NULL ["site_id":"WP_User":private]=> int(1) } }

How to deal with a such problem?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看