Wordpress Site Admin can't publish s on multsite network
Wordpress Site Admin can't publish <iframe>s on multsite network
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.
<iframe>s
<script>
What I've tried:
unfiltered_html
iframe
$allowedtags
iframe
extended_valid_elements
tiny_mce_before_init
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) width
add_filter('tiny_mce_before_init', 'add_mce_tags');
unfiltered_html
@Xhynk Added full code block.
– jon_childs
Sep 4 '18 at 20:09
2 Answers
2
You can solve this issue using shortcode. If you not found needed solution.
Something like that
add_shortcode('book', array('iframe_shortcode', 'shortcode')); class iframe_shortcode
function shortcode($atts, $content=null)
extract(shortcode_atts(array(
'url' => '',
'scrolling' => 'yes',
'width' => '680',
'height' => '850',
'frameborder' => '0',
'marginheight' => '0',
), $atts));
if (empty($url)) return '<!-- Iframe: You did not enter a valid URL -->';
return '<iframe src="'.$url.'" title="" width="'.$width.'" height="'.$height.'" scrolling="'.$scrolling.'" frameborder="'.$frameborder.'" marginheight="'.$marginheight.'"><a href="'.$url.'" target="_blank">'.$url.'</a></iframe>';
Thanks for your contribution, especially since it provides an alternative (and viable) solution to the question. As a note, I'd double check your code (it's a bit easier in an IDE if you aren't using one) - as the shortcode you've posted would require OP to use
[book url="https://example.com/"]
instead of something more semantic like [iframe url="https://example.com/"]
- and be sure to check your formatting and indenting once you submit your answer, to make sure it's easy to parse through and read. Cheers!– Xhynk
Sep 4 '18 at 20:42
[book url="https://example.com/"]
[iframe url="https://example.com/"]
Thank you for your comment. Code was just an example and for sure should be changed or customized to specific needs.
– Andrey Svyrydov
Sep 4 '18 at 20:45
admin
isn't a valid default role, I believe you're looking for administrator
. 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:
admin
administrator
$role
function add_theme_caps()
if( $role = get_role( 'administrator' ) )
$role->add_cap('unfiltered_html');
add_action( 'admin_init', 'add_theme_caps' );
Good catch. I actually was using a plugin to do it before, still with no luck.
– jon_childs
Sep 4 '18 at 20:56
unfiltered_html
seems to be deprecated anyways.– jon_childs
Sep 4 '18 at 21:28
unfiltered_html
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Can you post the code you used to give
unfiltered_html
back to admins?– Xhynk
Sep 4 '18 at 19:47