Skip to content

Instantly share code, notes, and snippets.

@mihdan
Forked from kagg-design/fix-authors-bug-5.7.php
Created March 22, 2021 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mihdan/dff233cc48469bde8a22cc894d286d25 to your computer and use it in GitHub Desktop.
Save mihdan/dff233cc48469bde8a22cc894d286d25 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