我有一个Wordpress多站点网络。我发现,如果您不是网络管理员,网站管理员无法发布<iframe>s
或<script>
标签。
我尝试过的:
unfiltered_html
功能添加到Admin角色iframe
添加到全球$allowedtags
iframe
过滤器将extended_valid_elements
添加到tiny_mce_before_init
我已经阅读了很多内容,我知道有一个Iframe插件,但最好允许我的用户从YouTube等复制和粘贴iframe。
任何见解都非常感谢!
编辑:下面的完整代码
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');
您可以使用短代码解决此问题。如果你没找到需要的解决方案。
这样的事情
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>';
} }
admin
不是一个有效的默认角色,我相信你正在寻找administrator
。确保你的$role
对象实际定义是一种很好的做法(尽管在这种情况下它不应该是一个问题),这应该可以让你运行起来:
function add_theme_caps() {
if( $role = get_role( 'administrator' ) ){
$role->add_cap('unfiltered_html');
}
}
add_action( 'admin_init', 'add_theme_caps' );