WordPress.org

Ready to get started?Download WordPress

Forums

user_can_richedit filter and HTML (5 posts)

  1. Wil
    Member
    Posted 1 year ago #

    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.

  2. 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' );

  3. Wil
    Member
    Posted 1 year ago #

    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.

  4. Wil
    Member
    Posted 1 year ago #

    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;
    }
  5. Wil
    Member
    Posted 1 year ago #

    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";') );

Topic Closed

This topic has been closed to new replies.

About this Topic