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 know there are a ton of post out there about how to allow html in profiles. Most of these warn about the security risk of doing so. My thinking is there has to be a way to only allow users to use html for certain users. I tried this but It doesn't work. I think it's because you can't remove a filter from inside a filter. Any help would be awesome.

add_action('edit user profile update', 'nifty_strip_html');

 function nifty_strip_html($user_id) {
     if ($user_id == 2){
        //if user id is 2 then allow html
        remove_filter('pre_user_description', 'wp_filter_kses');

            return; //keep the filtered html
share|improve this question
You could try this for all users: wordpress.stackexchange.com/questions/21326/… – birgire Mar 20 '13 at 10:35
@birgire Yeah I know, but I'd rather just be on the safe side – BandonRandon Mar 20 '13 at 18:14
up vote 3 down vote accepted

You can hook on an early action and apply the filter for your use case:

add_action( 'load-profile.php', 'allow_profile_html_wpse_91564' );

function allow_profile_html_wpse_91564()
    global $current_user;
    if( '2' == $current_user->ID )
        remove_filter('pre_user_description', 'wp_filter_kses');

The hook load-$pagenow runs in all default admin pages (i.e., not added by a third party), and it's declared in the file /wp-admin/admin.php.

$pagenow is the PHP page running at a given moment. So, to target the page /wp-admin/user-edit.php?user_id=2, another hook is needed and also another conditional checking:

add_action( 'load-user-edit.php', 'callback_function' );

function allow_user_html_wpse_91564()
    if( isset( $_REQUEST['user_id'] ) && '2' == $_REQUEST['user_id'] )
        remove_filter( 'pre_user_description', 'wp_filter_kses' );    
share|improve this answer
That didn't seem to work. What page is load-profile.php? I'm trying to edit the user inside of the admin so i tried to change the hook to edit-user.php but still didn't work. – BandonRandon Mar 24 '13 at 1:02
Updated the answer, my first example was only for the profile page. And, for editing an user, another conditional is needed. – brasofilo Mar 24 '13 at 11:11

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.