编辑隐私策略页面仅限于manage_privacy_options
正如WordPress核心文件中的注释所指出的wp-includes/capabilities.php
:
/*
* Setting the privacy policy page requires `manage_privacy_options`,
* so editing it should require that too.
*/
if ( (int) get_option( \'wp_page_for_privacy_policy\' ) === $post->ID ) {
$caps = array_merge( $caps, map_meta_cap( \'manage_privacy_options\', $user_id ) );
}
允许用户使用角色
editor
和
administrator
谁可以编辑页面(在单个和多站点实例中)要编辑和删除隐私策略页面,必须覆盖
$caps
阵列:
add_action(\'map_meta_cap\', \'custom_manage_privacy_options\', 1, 4);
function custom_manage_privacy_options($caps, $cap, $user_id, $args)
{
if (!is_user_logged_in()) return $caps;
if (\'manage_privacy_options\' === $cap) {
$manage_name = is_multisite() ? \'manage_network\' : \'manage_options\';
$caps = array_diff($caps, [ $manage_name ]);
}
return $caps;
}
更新:允许具有该角色的用户
editor
或
administrator
要编辑和删除隐私策略页面(在多站点实例中,默认情况下无法执行此操作):
add_action(\'map_meta_cap\', \'custom_manage_privacy_options\', 1, 4);
function custom_manage_privacy_options($caps, $cap, $user_id, $args)
{
if (!is_user_logged_in()) return $caps;
$user_meta = get_userdata($user_id);
if (array_intersect([\'editor\', \'administrator\'], $user_meta->roles)) {
if (\'manage_privacy_options\' === $cap) {
$manage_name = is_multisite() ? \'manage_network\' : \'manage_options\';
$caps = array_diff($caps, [ $manage_name ]);
}
}
return $caps;
}