Skip to content

Instantly share code, notes, and snippets.

@deepak-rajpal
Created November 20, 2015 14:22
Show Gist options
  • Save deepak-rajpal/66d94baf31ee8aeb1811 to your computer and use it in GitHub Desktop.
Save deepak-rajpal/66d94baf31ee8aeb1811 to your computer and use it in GitHub Desktop.
Unfiltered HTML plugin selected code to allow admin/editor js/script etc code in WPMU
<?php
/* To allow unfiltered html for admin and editor */
function um_unfilter_roles() {
// Makes sure $wp_roles is initialized
get_role( 'administrator' );
global $wp_roles;
// Dont use get_role() wrapper, it doesn't work as a one off.
// (get_role does not properly return as reference)
$wp_roles->role_objects['administrator']->add_cap( 'unfiltered_html' );
$wp_roles->role_objects['editor']->add_cap( 'unfiltered_html' );
}
add_action( 'admin_init', 'um_unfilter_roles');
// Add the unfiltered_html capability back in to WordPress 3.0 multisite.
function um_unfilter_multisite( $caps, $cap, $user_id, $args ) {
if ( $cap == 'unfiltered_html' ) {
unset( $caps );
$caps[] = $cap;
}
return $caps;
}
add_filter( 'map_meta_cap', 'um_unfilter_multisite', 10, 4 );
/* To allow unfiltered html for admin and editor - ends */
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment