Accueil Logiciels libres Wordpress How to finally allow iframes in WordPress (or any other tag)

How to finally allow iframes in WordPress (or any other tag)

I've spend a lot of time trying to allow iframes for administrators in a multi-site WordPress 3.8
I first tried the Unfiltered MU plugin, with no effect...

I've tried to add the (deprecated ?) "unfiltered_html" capability width User Role Editor, without more effects.

I've added some code found on the web to allow iframe in TinyMCE, but after saving the post, all iframe tags where stripped.

 

Finnaly, after many hours, I decided to get into the trac, browse the code, and find the solution by myself.

Here it is :

 

wp-includes/kses.php has a library used to defined wich tags are allowed or not, and functions uses filters hooks. So the following code worked for me :

 

add_filter( 'wp_kses_allowed_html', 'esw_author_cap_filter',1,1 );

function esw_author_cap_filter( $allowedposttags ) {

//Here put your conditions, depending your context

if ( !current_user_can( 'publish_posts' ) )
return $allowedposttags;

// Here add tags and attributes you want to allow

$allowedposttags['iframe']=array(

'align' => true,
'width' => true,
'height' => true,
'frameborder' => true,
'name' => true,
'src' => true,
'id' => true,
'class' => true,
'style' => true,
'scrolling' => true,
'marginwidth' => true,
'marginheight' => true,

);
return $allowedposttags;

}

 

Hope it helps !

Laisser un commentaire

Dark Web Design Saves Energy