Skip to content

Instantly share code, notes, and snippets.

@jazzsequence
Last active March 19, 2024 01:25
Show Gist options
  • Save jazzsequence/4f16932fdc5980c0af43dbdc9bf9aac4 to your computer and use it in GitHub Desktop.
Save jazzsequence/4f16932fdc5980c0af43dbdc9bf9aac4 to your computer and use it in GitHub Desktop.
Add `unfiltered_html` capability to editors on multisite.
<?php
/**
* Add `unfiltered_html` capability to editors (or other user roles).
* On WordPress multisite, `unfiltered_html` is blocked for everyone but super admins. This gives that cap back to editors
* and above.
*
* @author Justin Tadlock
* @link http://themehybrid.com/board/topics/add-unfiltered_html-capability-to-editor-role#post-4629
* @param array $caps An array of capabilities.
* @param string $cap The capability being requested.
* @param int $user_id The current user's ID.
*/
function my_map_meta_cap( $caps, $cap, $user_id ) {
if ( 'unfiltered_html' === $cap && user_can( $user_id, 'editor' ) )
$caps = array( 'unfiltered_html' );
return $caps;
}
add_filter( 'map_meta_cap', 'my_map_meta_cap', 1, 3 );
@donini
Copy link

donini commented Mar 19, 2024

It worked for me, @jazzsequence. I tried various approaches and none of them have worked till I stop by your gist. Thank you so much for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment