Error while saving posts on subsite
-
We run a multisite setup and installed Powered Cache yesterday. Users on subsite got the following error message when trying to make a new post. This was on a custom post type but I did not test if it also happens on a normal post.
The update failed. Unfortunately, you are not authorized to edit the custom field powered_cache_disable_cache.If I look into the network tab I get the following answer:
{"code":"rest_cannot_update","message":"Du bist leider nicht berechtigt, das individuelle Feld powered_cache_disable_cache zu bearbeiten.","data":{"key":"powered_cache_disable_lazyload","status":403},"additional_data":[{"key":"powered_cache_disable_cache","status":403}],"additional_errors":[{"code":"rest_cannot_update","message":"Du bist leider nicht berechtigt, das individuelle Feld powered_cache_disable_lazyload zu bearbeiten.","data":{"key":"powered_cache_disable_lazyload","status":403},"additional_data":[{"key":"powered_cache_disable_cache","status":403}]}]}With ChatGPT I managed to get it running with the following code but thats surley not ideal:
add_filter('user_has_cap', function($allcaps, $caps, $args, $user) {
if (defined('REST_REQUEST') && REST_REQUEST) {
if (!empty($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/wp/v2/posts') !== false) {
if (isset($allcaps['edit_posts']) && $allcaps['edit_posts']) {
$allcaps['manage_options'] = true;
}
}
}
return $allcaps;
}, 999, 4);
You must be logged in to reply to this topic.