Wordpress网站管理员无法发布 在多站点网络上

问题描述 投票:0回答:2

我有一个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');
wordpress iframe embed multisite
2个回答
1
投票

您可以使用短代码解决此问题。如果你没找到需要的解决方案。

这样的事情

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>';
    } }

0
投票

admin不是一个有效的默认角色,我相信你正在寻找administrator。确保你的$role对象实际定义是一种很好的做法(尽管在这种情况下它不应该是一个问题),这应该可以让你运行起来:

function add_theme_caps() {
    if( $role = get_role( 'administrator' ) ){
        $role->add_cap('unfiltered_html');
    }
}
add_action( 'admin_init', 'add_theme_caps' );
© www.soinside.com 2019 - 2024. All rights reserved.