I have a Wordpress multisite network. I've found that if you're not a Network Admin, Site Admins cannot publish <iframe>s
or <script>
tags.
What I've tried:
- Added the
unfiltered_html
capability to the Admin role - Added
iframe
to the global$allowedtags
- Added
iframe
to theextended_valid_elements
using thetiny_mce_before_init
filter
I've read around a lot, and I know there's an Iframe plugin, but It would really be best to allow my users to copy and paste Iframes from YouTube, etc.
Any insight is much appreciated!
EDIT: full code below
function add_theme_caps() {
$role = get_role('administrator');
$role->add_cap('unfiltered_html');
}
add_action('admin_init', 'add_theme_caps');
public function add_tags()
{
global $allowedtags;
$allowedtags['iframe'] = [
'src' => [],
'width' => [],
'height' => [],
'frameborder' => [],
'style' => [],
'allowfullscreen' => []
];
}
add_action('init', 'add_tags');
public function add_mce_tags($options) {
// Comma separated string of extended tags
$ext = 'iframe[align|longdesc|name|width|height|frameborder|scrolling|marginheight|marginwidth|src]';
if (isset($options['extended_valid_elements'])) {
$options['extended_valid_elements'] .= ',' . $ext;
} else {
$options['extended_valid_elements'] = $ext;
}
// maybe; set tiny paramter verify_html
// $options['verify_html'] = false;
return $options;
}
add_filter('tiny_mce_before_init', 'add_mce_tags');
You can solve this issue using shortcode. If you not found needed solution.
Something like that
admin
isn't a valid default role, I believe you're looking foradministrator
. It's also considered a good practice to make sure your$role
object is actually defined (though in this case it shouldn't be an issue), this should get you up and running: