如何在Wordpress中获取多站点的所有管理员 [英] How to get all admins of multisite in wordpress

查看:49
本文介绍了如何在Wordpress中获取多站点的所有管理员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在wordpress中获取所有多站点管理员.我为此创建自定义插件我被困在自定义代码中,以获取主网站中所有多站点管理员.对于前.我的主要网站是wyz.com,第二个网站是xyz.com/demo.主网站管理员是"abc","xyz.com/demo"的网站管理员是"abcde".现在,我如何在主网站上获得"abcde"管理员.

How to get all admins of multisite in wordpress. I am create custom plugin for this I am stuck in custom code for get all the admins of multisite in main website. for ex. my main website is : wyz.com and my second site is : xyz.com/demo. main website admin is "abc" and for " xyz.com/demo" site admin is "abcde". Now how i get "abcde" admin in my main website .

在我的实时网站上,我目前有6k管理员.所以我很难得到这个.我是多站点wordpress的新手.

In my live site i have currently 6k admins. So i difficult to get this . I am new in multisite wordpress.

推荐答案

要从任何子站点获取数据,您首先需要使用 restore_current_blog()函数来还原它.

To get the data from any of the sub site, you first need to switch to that site using switch_to_blog() function. Then whatever the query you fire, it will give records from that site only. Don't forget to restore it to current site, once you get the data from sub-site. You can restore it using restore_current_blog() function.

要获取所有站点的所有管理员用户,您需要执行以下操作:

To get the all admin users of all the sites, you need to perform the followings:

1)使用 wp_get_sites()函数获取所有网站.

1) Use wp_get_sites() function to get the blog_id of all the sites.

2)一旦获得blog_id,就需要执行以下循环以获取每个站点的管理员用户.

2) Once you get the blog_id, You need to perform the following loop to get the admin user of each the sites.

假设您从 wp_get_sites()函数

foreach ($blogs as $blog) 
    {
        switch_to_blog( $blog->blog_id ); // blog id which u got from wp_get_sites() function
        $users_query = new WP_User_Query( array( 
                    'role' => 'administrator', 
                    'orderby' => 'display_name'
                    ) );  // query to get admin users
        $results = $users_query->get_results();
        $site_admins .= 'Blog ID: ' . $blog->blog_id . '<pre>' . print_r($results,true) . '</pre>';
    }
    restore_current_blog();

这篇关于如何在Wordpress中获取多站点的所有管理员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆