Skip to content

Instantly share code, notes, and snippets.

@kagg-design
Created March 22, 2021 08:28
Show Gist options
  • Save kagg-design/2cefd1770242d43999cf5ff5459841f2 to your computer and use it in GitHub Desktop.
Save kagg-design/2cefd1770242d43999cf5ff5459841f2 to your computer and use it in GitHub Desktop.
MU-Plugin to temporary fix the problem with the list of authors on post edit page with Block Editor.
<?php
/**
* MU-Plugin to temporary fix the problem with the list of authors on post edit page with Block Editor.
* With WP 5.7, user with the Editor role is unable to search across long list of authors in Author combobox.
*
* @package kagg-design
*/
/**
* Fixes bug in WP 5.7 with author selection on post edit in admin.
*
* @param bool $jsonp_enabled Whether JSONP is enabled. Default true. We do not modify it.
*
* @return bool
*/
function vp_rest_jsonp_enabled_filter( $jsonp_enabled ) {
// phpcs:disable WordPress.Security.NonceVerification.Recommended
if (
isset( $_GET['who'] ) && 'authors' === $_GET['who'] &&
isset( $_GET['context'] ) && 'edit' === $_GET['context'] &&
current_user_can( 'moderate_comments' ) // Editor role.
) {
// Unset parameter which causes the permission problem.
unset( $_GET['context'] );
}
// phpcs:enable WordPress.Security.NonceVerification.Recommended
return $jsonp_enabled;
}
add_filter( 'rest_jsonp_enabled', 'vp_rest_jsonp_enabled_filter' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment