4

I'm trying to allow "author" users to embed in posts. I (the administrator) can iframe, embed, etc...., but authors can not.

Can someone show me to give authors 'just' the ability to embed and iframe in posts?

1
  • I have a similar issue where administrators code is stripped like iframe code for youtube or google maps, however Super Admin is not. I don't see any plugins doing this and it is not what I see as normal behaviour. There is no code in functions either..
    – landed
    Apr 11, 2017 at 13:17

2 Answers 2

6

The capability you are after is called unfiltered_html. Some options:

  1. Modify author capabilities in your theme functions.php. This is saved in the DB, so you can access a page, make sure it works then remove it from your functions.php file. A better option would be to run it on theme activation. See this page on WP Codex for options:

    function add_theme_caps() {
        // gets the author role
        $role = get_role( 'author' );
    
        // This only works, because it accesses the class instance.
        // would allow the author to edit others' posts for current theme only
        $role->add_cap( 'unfiltered_html' ); 
    }
    add_action( 'admin_init', 'add_theme_caps');
    
  2. Use a plugin that allows you to modify it using a UI, like User Role Editor.

3
  • Thank you @oliver! FYI for anyone else. Add 'Unfiltered html' in user role editor to give rights to add embed and iFrame to posts.
    – Mr. B
    Apr 7, 2015 at 19:52
  • I'm not sure this gives authors just the "ability to embed and iframe in posts" as requested. I am pretty sure it gives authors a lot more power than that, including the ability to edit posts written by other authors (which seems like a bad idea).
    – s_ha_dum
    Apr 7, 2015 at 21:43
  • @s_ha_dum you're right, I make a mistake while copy pasting code and I've edited my post with the proper capability (unfiltered_html).
    – Olivier
    Apr 8, 2015 at 5:35
2

This is a bad idea and you might as well just give those users "higher" roles as with the "unfiltered_html" permission it is not very hard to duplicate the admin authorization cookies and take control of the site.

What you should do is to teach them to use the built-in functionality of oEmbed, which should be enough to embed content from many sites in a simple way, by just putting the url of the content on a line of its own, but if that is not good enough, then you need to write shortcodes that will do the actual embed into the content.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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