• Wil

    (@limecanvas)


    When I apply a filter to disable rich editing using user_can_richedit filter, when the post is saved, and if it contains a textarea HTML tag, the closing textarea is not preserved.

    The formatting is preserved if I don’t disable rich editing using the filter and use the normal WordPress “Text” tab.

    Why is calling the user_can_richedit filter and setting it to false, screwing up the HTML code?

    e.g.

    add_action( 'admin_head', 'my_handler' );
    
    function my_handler(){
    add_filter('user_can_richedit',create_function(null,'return false;'));}

    Then try to edit and save a page with a simple textarea HTML box in it.

    <h1>this is a test</h1>
    <textarea cols="40" name="myname" rows="5">Now we are inside the area - which is nice.</textarea>

    The result chops off the closing textarea tag and for larger HTML pages.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You don’t need to attach your function to admin_head. Also you can simply pass in the __return_false function to your filter. Just put this somewhere before the page loads like in functions.php

    add_filter( 'user_can_richedit', '__return_false' );

    Thread Starter Wil

    (@limecanvas)

    Thanks Chris.

    It’s bundled as part of a plugin so I need to add the filter to something that runs when being edited in the Admin dashboard.

    I’m also reading a meta_value from the current post, so I also need a hook that will give the the current page ID.

    Thread Starter Wil

    (@limecanvas)

    Doesn’t seem to matter which filter I use, the results are always that the textarea closing tag is removed.

    add_filter( 'parse_query', 'filter_post_edit_screen' );
    function filter_post_edit_screen($query) {
    	global $pagenow, $post;
    
    	if (is_admin() && ( $pagenow=='post.php' && $_GET['action']=='edit' ) ){
    		add_filter('user_can_richedit','__return_false');
    	}
    	return $query;
    }
    Thread Starter Wil

    (@limecanvas)

    Seeing as there seems to be an issue with the user_can_richedit filter and perserving the textarea HTML tag, I am using the following filter which seems to give the same result.

    // Set the editor to HTML ("Text")
    add_filter( 'wp_default_editor', create_function(null,'return "html";') );
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘user_can_richedit filter and HTML’ is closed to new replies.