對於我所使用的特定用戶名的權利:
//give the right to deactivate sites to 'username' if the user doesn't have it already
$user = new WP_User('username');
if (! $user->has_prop('can_manage_sites')) {
$user->add_cap('can_manage_sites');
}
if (! $user->has_prop('username')) {
$user->add_cap('manage_sites');
}
//ofcourse replace 'username' with the username you need
在我看來,我只是使用if語句來檢查網站是否激活或不知道要使用哪個鏈接(激活/停用)
//deactivated, show activate link
if(get_blog_status($site->blog_id, 'deleted') == '1'){
echo '<span class="dashicons dashicons-no" style="color:red;"></span> Niet actief <br/>';
echo '<a href="' . esc_url(wp_nonce_url(network_admin_url('sites.php?action=confirm&action2=activateblog&id=' . $site->blog_id), 'activateblog_' . $site->blog_id)) . '">' . __('Activate') . '</a>';
}
//activated, show deactivate link
else {
echo '<span class="dashicons dashicons-yes" style="color: green;"></span> Actief<br/>';
echo '<a style="color:red;" href="' . esc_url(wp_nonce_url(network_admin_url('sites.php?action=confirm&action2=deactivateblog&id=' . $site->blog_id), 'deactivateblog_' . $site->blog_id)) . '">' . __('Deactivate') . '</a>';
}
此代碼會爲您提供您需要的鏈接(de)激活網站,您將會看到一個確認頁面。在此確認頁面中,用戶可以在菜單中看到一個'sites'標籤,當他們點擊它時有mu中所有網站的選項。這對我來說並不重要,因爲將使用此功能的人是同事,並且知道他們不應該去那裏。 但是你可能想要隱藏,如果它涉及那些不應該能夠看到的人
檢查是否可以幫助https://www.role-editor.com/wordpress-multisite-super-admin-特權/ –
謝謝。但那不是我想要實現的,我不想讓這個角色訪問'網絡'部分。我只想顯示每個mu上的(de)激活鏈接,對於該角色可見:) – Maartje
找到這兩個動作功能:https://developer.wordpress.org/reference/hooks/deactivate_blog/和https:// developer .wordpress.org/reference/hooks/activate_blog /。現在我只是尋找一些功能或選項來查看該網站是否處於活動狀態。就像is_active_mu? – Maartje