Created
January 11, 2013 15:52
-
-
Save bueltge/4511711 to your computer and use it in GitHub Desktop.
Wordpress plugin for allow iframe in the visual Editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: iFrame for TinyMCE | |
* Description: Allow iframe in the visual Editor | |
* Version: 0.0.1 | |
* Author: Frank Bültge | |
* Author URI: http://bueltge.de/ | |
*/ | |
! defined( 'ABSPATH' ) and exit; | |
add_filter( 'tiny_mce_before_init', 'fb_change_mce_options' ); | |
function fb_change_mce_options( $args ) { | |
// Comma separated string od extendes tags | |
// Command separated string of extended elements | |
$ext = 'iframe[align|longdesc|name|width|height|frameborder|scrolling|marginheight|marginwidth|src]'; | |
if ( isset( $args['extended_valid_elements'] ) ) { | |
$args['extended_valid_elements'] .= ',' . $ext; | |
} else { | |
$args['extended_valid_elements'] = $ext; | |
} | |
// maybe; set tiny paramter verify_html | |
//$args['verify_html'] = false; | |
return $args; | |
} |
Then, to remove the iframes you don't want:
function sanitize_iframes($content) {
$patternIframes = '/<iframe.*src=\\\\"(.*)\\\\".*><\\/iframe>/isU';
$patternSrc = '/^(http:|https:)?\/{2}(www.)?(domain1.com|domain2.com|domain3.com)/'; //whitelist
$iframesCount = preg_match_all($patternIframes, $content["post_content"], $iframesMatches);
if($iframesCount > 0){
$i = 0;
foreach ($iframesMatches[1] as $iframeMatch){
$srcCount = preg_match($patternSrc, $iframeMatch, $obj);
if($srcCount == 0){
$removeBackslashes = str_replace("\\\\", '\\', $iframesMatches[0][$i]);
$content["post_content"] = str_replace($removeBackslashes, "", $content["post_content"]);
}
++$i;
}
}
return $content;
}
add_filter('wp_insert_post_data', 'sanitize_iframes');
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This not work... i'm searching one solutions and i find this:
This work in Wordpress >= 3.9.x.