WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am managing a Wordpress network and would like to add the unfiltered_html user capability to the already predefined user role of Admin. In a standard installation of Wordpress the Admin account would already have this capability but in an MU installation only Super Admins are afforded this capability. Wordpress Roles and Capabilities.

How can I augment the Admin role from within a theme or plugin?

share|improve this question
wordpress.org/extend/plugins/unfiltered-mu looks like it may help. But it works for admins and editors. If that's not desired maybe the code can be tweaked a little? – Rev. Voodoo Mar 29 '11 at 19:30
see this A: wordpress.stackexchange.com/questions/13025/… – kaiser Mar 30 '11 at 1:46
@Rev. Voodoo Thanks for the suggestion. This helped shed some light on the subject as adding the capability of unfiltered_html is not enough to allow a role other than Admin or Super admin the ability to post embeds, etc. The key was un filtering/hooking Wordpress’ KSES: kses_remove_filters() – Jonnybojangles Apr 5 '11 at 23:44
Glad I could help a little! – Rev. Voodoo Apr 6 '11 at 11:10
A detail blog:goo.gl/xNuafH – Suresh Kamrushi Jan 14 at 9:19
up vote 7 down vote accepted

You can use WP_Role class,

// get the the role object
$role_object = get_role( $role_name );

// add $cap capability to this role object
$role_object->add_cap( $capability_name );

// remove $cap capability from this role object
$role_object->remove_cap( $capability_name );

or you can run this once in your functions:

/* Roles & Capabilities */
add_role('professional', 'Professional User', array(
    'read' => true, // True allows that capability, False specifically removes it.
    'edit_posts' => true,
    'delete_posts' => true,
    //'edit_published_posts' => true,
    //'publish_posts' => true,
    //'edit_files' => true,
    'upload_files' => true //last in array needs no comma!
share|improve this answer
Thanks Philip. In regards to the WP_Role class when should execute the code? I am guessing this affects the global role object? I am glad that you brought up the second block of code mentioning that I could run this once in my functions file. I have found similar solutions on some of the Wordpress support forums but I find it odd to have run once code in a theme or plugin in. Especially without a check if the change already exists. Perhaps the role write is actually negligible. To check for the capability vs just write the capability to the role as your first example shows. – Jonnybojangles Mar 30 '11 at 16:01
I'm also interested in how you would execute the WP_Role class if you get a moment free to tell us. Thanks – Osu Mar 30 '11 at 18:49
@Jonnybojagles & @Osu, check this out: Ultimate Guide to Roles & Capabilities garyc40.com/2010/04/ultimate-guide-to-roles-and-capabilities – Philip Mar 31 '11 at 5:39
I have already read that article in my pursuit, but I did take the opportunity to run through it all again, thank you! Eventually, after dissecting the unfiltered-mu (mentioned above by Rev. Voodoo) plugin I eventually found out that changing roles by adding capabilities is not enough. I needed to unfilter Wordpress’ KSES filters. – Jonnybojangles Apr 5 '11 at 23:52

In order to allow another role other than Super Admin or Admin (depending if the Wordpress installation is a network/MU instance or not) to add unfiltered html to a post or comment Wordpress’ KSES filter must be removed.

Check if a user has a particular capability.

if ( current_user_can( 'unfiltered_html' ) ) { … }

If so than remove KSES


This functionality is already wrapped up in unfiltered-mu, allowing admins and editors to add unfiltered html.

share|improve this answer
The functionality is also wrapped in a plugin register and deregister so that the logic does not need to be preformed on each WP instance. – Jonnybojangles Apr 12 '11 at 18:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.