Tag: paste

  • WordPress TinyMCE paste as plain text

    <?php
    /**
     * Replaces plugin for pasting as plain text on TinyMCE.
     *
     * Adapted form http://wordpress.org/plugins/paste-as-plain-text/
     */
     
     add_action( 'admin_init', 'BRR2025_paste_plain_init' );
     
     function BRR2025_paste_plain_init() {
       
    	add_filter( 'tiny_mce_before_init', 'BRR2025_force_paste_as_plain_text' );
    	add_filter( 'teeny_mce_before_init', 'BRR2025_force_paste_as_plain_text' );
    	add_filter( 'teeny_mce_plugins', 'BRR2025_load_paste_in_teeny' );
    	add_filter( 'mce_buttons_2', 'BRR2025_remove_paste_plain_text_button' );
      
     }  
      
    	function BRR2025_force_paste_as_plain_text( $mceInit ) {
    
    		global $tinymce_version;
    
    		if ( $tinymce_version[0] < 4 ) {
    			$mceInit[ 'paste_text_sticky' ] = true;
    			$mceInit[ 'paste_text_sticky_default' ] = true;
    		} else {
    			$mceInit[ 'paste_as_text' ] = true;
    		}
    
    		return $mceInit;
    	}
    
    	function BRR2025_load_paste_in_teeny( $plugins ) {
    
    		return array_merge( $plugins, (array) 'paste' );
    
    	}
    
    	function BRR2025_remove_paste_plain_text_button( $buttons ) {
    
    		if( ( $key = array_search( 'pastetext', $buttons ) ) !== false ) {
    			unset( $buttons[ $key ] );
    		}
    
    		return $buttons;
    
    	}