即使明确允许,Wordpress也会剥离属性

时间:2018-03-05 13:39:45

标签: wordpress

我查看了关于允许HTML标记和属性到Wordpress帖子的每个指南,但它仍然从iframe剥离allow属性。在回显allowedposttags全局时,看起来iframe[allow]设置为true。 TinyMCE的设置显示extended_valid_elements设置为允许所有*[*]。不会剥离Wordpress更新端点的POST数据。我非常感谢您在确定问题时提供帮助。这是我根据一些指南放在一起的插件:

<?php
/**
 * Plugin Name:Allow Tags
 * Description: Allows one to add "invalid" and custom HTML elements to the Wordpress editor.
 * Version: 0.1
 * Author: Sam Hill
 * with help from http://www.engfers.com/2008/10/16/how-to-allow-stripped-element-attributes-in-wordpress-tinymce-editor/ and many other sources
 */

class AllowTags {

  public static $instance = null;

  public static function get_instance() {
      if ( null == self::$instance ) {
          self::$instance = new self;
      }

      return self::$instance;
  }

  private function __construct() {
    add_filter('wp_kses_allowed_html', 'custom_wpkses_post_tags', 10, 2 );

    add_filter('tiny_mce_before_init', 'tinymce_allow_iframe');

    add_action('init', 'allow_iframe_attributes', 10, 2);
  }
}


AllowTags::get_instance();

function tinymce_allow_iframe($init) {
  $options = '*[*]';
  $init['valid_elements'] = $options;
  $init['extended_valid_elements'] = $options;
  $init['verify_html'] = false;
  return $init;
}

function custom_wpkses_post_tags($allowed, $context){
  if (is_array($context)) {
      return $allowed;
  }

  if ($context === 'post') {
      $allowed['iframe'] = array(
        'src'             => true,
        'height'          => true,
        'width'           => true,
        'frameborder'     => true,
        'allowfullscreen' => true,
        'allow'         => true
      );
  }
  return $allowed;
}

function allow_iframe_attributes( $string ) {

    global $allowedposttags;
    $allowedposttags['iframe'] = array(
        'allow'       => true,
        'align'       => true,
        'frameborder' => true,
        'height'      => true,
        'width'       => true,
        'sandbox'     => true,
        'seamless'    => true,
        'scrolling'   => true,
        'srcdoc'      => true,
        'src'         => true,
        'class'       => true,
        'id'          => true,
        'style'       => true,
        'border'      => true,
    );

    return $string;
}
}

0 个答案:

没有答案