Created
April 8, 2020 00:32
-
-
Save anthonyboutinov/3fe56de68acedf9be7c162b8730f09a9 to your computer and use it in GitHub Desktop.
Allow editors in Wordpress to edit Privacy Policy page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: https://wordpress.stackexchange.com/questions/318666/how-to-allow-editor-to-edit-privacy-page-settings-only | |
// Allow users with the role editor or administrator to edit and delete the privacy policy page (which is not possible per default in multisite instances): | |
add_action('map_meta_cap', 'custom_manage_privacy_options', 1, 4); | |
function custom_manage_privacy_options($caps, $cap, $user_id, $args) | |
{ | |
$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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$user_meta
can be false, so you need to check that, otherwise you will get a fatal error for some requests. You should add a guard clause:Some refactoring to make it more readable: