User Access 問題

UserAccess 不開放 manage_product_settings 權限的話,會導致無法進入 wp-admin
toolbar 則一定要是 Administrator 才會顯示。

WordPress 搜尋、檢閱排除敏感文件

搜尋排除敏感文件

現行的 Vantage Theme 有經過修改,才能讓 WordPress 內建搜尋排除敏感文件。
所以若有更新或重置,需要利用 Theme File Editor 手動編輯 Vantage 的 functions.php,新增下列程式碼:

//Hollen Appened on 2022
add_action( 'init', 'exclude_sensitive_doc_from_stranger_search', 99 );
function exclude_sensitive_doc_from_stranger_search() {
    global $wp_post_types;

    $user = wp_get_current_user();
    if ( in_array( 'author', (array) $user->roles ) ) {
        //The user has the "author" role
        return;
    }

    if ( post_type_exists( 'documentation' ) ) {
        // exclude from search results
        $wp_post_types['documentation']->exclude_from_search = true;
    }
}

此處我假定能看敏感文件的員工皆有 author 這個 UserRole,然後我再檢查使用者檢閱/搜尋的頁面是否為 "documentation" 的文章型別。

docuemtentaion 是自訂文章型别,我是透過現有 Plugin "Custom Post Type UI, aka CPTUI" 達到此一功能。

檢閱排除敏感文件

光是搜尋排除不夠,要連一般的點選閱覽也拒絕操作。
因此我借用了下列 Plugins: "Restrict User Access", "LoginWP"

Restrict User Access

針對不同的 UserRole,去做個別頁面、文章型別的瀏覽限制。

Automation 設定為當有會員取得 Author 角色時,給予權限。

設權限賦能 Read

當使用者條件不符合,Redirect 跳轉到 Authentication Failed 頁面 (我預先建立好的 Page)。

登入、登出跳轉

沒有特別設定的話,一般使用者登入之後,會被帶往後台管理介面,這樣就沒辦法讓他們直接進入 Staff Portal / 員工入口了。
而且登出也會直接停留在登入畫面,不會自動回到首頁。

進入 Redirections 設定 Login URL 和 Logout URL

將 Login URL 設為 /?page_id=288,Logout URL 設為 /

/?page_id=288 僅為 Staff Portal 的頁面連結,不使用絕對路徑是避免更換 Domain 連帶影響。