問題描述

我正在管理 Wordpress 網路,並希望將 unfiltered_html 使用者功能新增到已預定義的使用者角色 Admin 中。在 Wordpress 的標準安裝中,管理員帳戶已經具有此功能,但是在 MU 安裝中,只有超級管理員才能獲得此功能。 WordPress Roles and Capabilities

如何從主題或外掛中增加管理角色?

最佳解決辦法

你可以使用 WP_Role 類,

// get the the role object
$role_object = get_role( $role_name );

// add $cap capability to this role object
$role_object->add_cap( $capability_name );

// remove $cap capability from this role object
$role_object->remove_cap( $capability_name );

因此,為瞭解決您的原始問題,關於如何使管理員將 SCRIPT 和 IFRAME 標籤輸入到帖子內容中,您正在尋找’unfiltered_html’ 功能,其中多個站點僅授予超級管理員。

// get the the role object
$admin_role = get_role( 'administrator' );
// grant the unfiltered_html capability
$admin_role->add_cap( 'unfiltered_html', true );

或者您可以在您的功能中執行一次:

/* Roles & Capabilities */
add_role('professional', 'Professional User', array(
    'read' => true, // True allows that capability, False specifically removes it.
    'edit_posts' => true,
    'delete_posts' => true,
    //'edit_published_posts' => true,
    //'publish_posts' => true,
    //'edit_files' => true,
    'upload_files' => true //last in array needs no comma!
));

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。