Advertisement
Guest User

Add script tag in WordPress

a guest
Apr 16th, 2014
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.92 KB | None | 0 0
  1.         add_filter('tiny_mce_before_init', 'esw_tiny_mce_before_init');
  2.         function esw_tiny_mce_before_init($o) {
  3.             # http://forum.semiologic.com/discussion/4807/iframe-code-disappears-switching-visualhtml/
  4.             # http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/valid_elements#Full_XHTML_rule_set
  5.             # assume the stuff below is properly set if they exist already
  6.            
  7.             if ( current_user_can('publish_posts') ){
  8.                
  9.                 if ( !isset($o['extended_valid_elements']) ){
  10.                     $elts = array();
  11.                    
  12.                     $elts[] = "iframe[align<bottom?left?middle?right?top|class|frameborder|height|id"
  13.                         . "|longdesc|marginheight|marginwidth|name|scrolling<auto?no?yes|src|style"
  14.                         . "|title|width]";
  15.        
  16.                     $elts = implode(',', $elts);
  17.        
  18.                     $o['extended_valid_elements'] = $elts;
  19.                    
  20.                 }
  21.             }
  22.             else{
  23.                 if ( !isset($o['invalid_elements']) ){
  24.                     $elts = array();
  25.        
  26.                     $elts[] = "iframe";
  27.                     $elts[] = "script";
  28.        
  29.                     $elts = implode(',', $elts);
  30.        
  31.                     $o['invalid_elements'] = $elts;
  32.                 }
  33.             }
  34.            
  35.             return $o;
  36.         }
  37.        
  38.         //add_filter( 'user_has_cap', 'esw_author_cap_filter', 10, 3 );
  39.         add_filter( 'wp_kses_allowed_html', 'esw_author_cap_filter_tags',1,1 );
  40.         function esw_author_cap_filter_tags( $allowedposttags ) {
  41.            
  42.        
  43.             if ( !current_user_can( 'publish_posts' ) )
  44.                 return $allowedposttags;
  45.        
  46.             $allowedposttags['iframe']=array(
  47.                 'align' => true,
  48.                 'width' => true,
  49.                 'height' => true,
  50.                 'frameborder' => true,
  51.                 'name' => true,
  52.                 'src' => true,
  53.                 'id' => true,
  54.                 'class' => true,
  55.                 'style' => true,
  56.                 'scrolling' => true,
  57.                 'marginwidth' => true,
  58.                 'marginheight' => true,
  59.                 );
  60.             $allowedposttags['code']=array();
  61.             return $allowedposttags;       
  62.         }
  63.        
  64.         add_filter( 'safe_style_css', 'esw_author_cap_filter_css',1,1 );
  65.         function esw_author_cap_filter_css( $allowedpostcss ) {
  66.             $allowedpostcss[]='display';
  67.             return $allowedpostcss;
  68.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement