WordPress wp_editor removes html tags - how to stop it?


field

Why does wp_editor remove all my html tags?

Here is my code:

/**
 * Outputs the content of the meta box.
 */
function prfx_meta_callback( $post ) {
    // echo 'This is a meta box';
    wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' );
    $prfx_stored_meta = get_post_meta( $post->ID );

    $field_value = get_post_meta( $post->ID, 'meta-textarea', false );

    // Settings that we'll pass to wp_editor
    $args = array (
        'textarea_rows' => 4,
        'teeny'         => true,
        // 'media_buttons' => false,
    );
    ?>

    <p>
        <label for="meta-text" class="prfx-row-title"><?php _e( 'Example Text Input', 'prfx-textdomain' )?></label>
        <input type="text" name="meta-text" id="meta-text" value="<?php if ( isset ( $prfx_stored_meta['meta-text'] ) ) echo $prfx_stored_meta['meta-text'][0]; ?>" />
    </p>

    <label for="meta-textarea" class="prfx-row-title"><?php _e( 'Example Textarea Input', 'prfx-textdomain' )?></label>
    <?php wp_editor( $field_value[0], 'meta-textarea', $args);?>

    <?php
}

/**
 * Saves the custom meta input.
 */
function prfx_meta_save( $post_id ) {
    // Checks save status
    $is_autosave = wp_is_post_autosave( $post_id );
    $is_revision = wp_is_post_revision( $post_id );
    $is_valid_nonce = ( isset( $_POST[ 'prfx_nonce' ] ) && wp_verify_nonce( $_POST[ 'prfx_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';

    // Exits script depending on save status
    if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
        return;
    }

    // Checks for input and sanitizes/saves if needed
    if( isset( $_POST[ 'meta-text' ] ) ) {
        update_post_meta( $post_id, 'meta-text', sanitize_text_field( $_POST[ 'meta-text' ] ) );
    }

    // Checks for input and sanitizes/saves if needed
    if( isset( $_POST[ 'meta-textarea' ] ) ) {
        update_post_meta( $post_id, 'meta-textarea', sanitize_text_field( $_POST[ 'meta-textarea' ] ) );
    }

}
add_action( 'save_post', 'prfx_meta_save' );

How to stop it from removing html tags?

For example, I enter the following:

<img src="http://xxxx.jpg" alt="10168088_719806568132380_3368979362641476670_n" width="300" height="214" class="alignnone size-medium wp-image-96" />

it removes it.

However, if I enter plain text without html tags,

abcde.

keep.

Any ideas?

Shravan Sharma

sanitize_text_field()Clean up your input.

so replace

 update_post_meta( $post_id, 'meta-textarea', sanitize_text_field( $_POST[ 'meta-textarea' ] ) );

and

 update_post_meta( $post_id, 'meta-textarea', stripslashes( $_POST[ 'meta-textarea' ] ) );

may solve your problem.

Related


WordPress wp_editor removes html tags - how to stop it?

field Why does wp_editor remove all my html tags? Here is my code: /** * Outputs the content of the meta box. */ function prfx_meta_callback( $post ) { // echo 'This is a meta box'; wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' ); $prfx_stor

WordPress wp_editor removes html tags - how to stop it?

field Why does wp_editor remove all my html tags? Here is my code: /** * Outputs the content of the meta box. */ function prfx_meta_callback( $post ) { // echo 'This is a meta box'; wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' ); $prfx_stor

WordPress wp_editor removes html tags - how to stop it?

field Why does wp_editor remove all my html tags? Here is my code: /** * Outputs the content of the meta box. */ function prfx_meta_callback( $post ) { // echo 'This is a meta box'; wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' ); $prfx_stor

WordPress wp_editor removes html tags - how to stop it?

field Why does wp_editor remove all my html tags? Here is my code: /** * Outputs the content of the meta box. */ function prfx_meta_callback( $post ) { // echo 'This is a meta box'; wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' ); $prfx_stor

WordPress wp_editor removes html tags - how to stop it?

field Why does wp_editor remove all my html tags? Here is my code: /** * Outputs the content of the meta box. */ function prfx_meta_callback( $post ) { // echo 'This is a meta box'; wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' ); $prfx_stor

WordPress wp_editor removes html tags - how to stop it?

field Why does wp_editor remove all my html tags? Here is my code: /** * Outputs the content of the meta box. */ function prfx_meta_callback( $post ) { // echo 'This is a meta box'; wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' ); $prfx_stor

WordPress wp_editor removes html tags - how to stop it?

field Why does wp_editor remove all my html tags? Here is my code: /** * Outputs the content of the meta box. */ function prfx_meta_callback( $post ) { // echo 'This is a meta box'; wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' ); $prfx_stor

WordPress wp_editor removes html tags - how to stop it?

field Why does wp_editor remove all my html tags? Here is my code: /** * Outputs the content of the meta box. */ function prfx_meta_callback( $post ) { // echo 'This is a meta box'; wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' ); $prfx_stor

WordPress wp_editor removes html tags - how to stop it?

field Why does wp_editor remove all my html tags? Here is my code: /** * Outputs the content of the meta box. */ function prfx_meta_callback( $post ) { // echo 'This is a meta box'; wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' ); $prfx_stor

wordpress how to add wp_editor in array

Said Mohammad Aladdin I have a small problem with my wordpress code, I need to display a wordpress wp_editor in a page which has an array of values. These values are defined as follows $fields[] = array( 'name' => __('Class', 'my-theme'), '

wordpress how to add wp_editor in array

Said Mohammad Aladdin I have a small problem with my wordpress code, I need to display a wordpress wp_editor in a page which has an array of values. These values are defined as follows $fields[] = array( 'name' => __('Class', 'my-theme'), '

wordpress how to add wp_editor in array

Said Mohammad Aladdin I have a small problem with my wordpress code, I need to display a wordpress wp_editor in a page which has an array of values. These values are defined as follows $fields[] = array( 'name' => __('Class', 'my-theme'), '

wordpress how to add wp_editor in array

Said Mohammad Aladdin I have a small problem with my wordpress code, I need to display a wordpress wp_editor in a page which has an array of values. These values are defined as follows $fields[] = array( 'name' => __('Class', 'my-theme'), '

How to add custom attribute to Wordpress wp_editor text area?

Kapil yadav How to add custom attribute to Wordpress wp_editor textarea field? In the official documentation, there is no way to do this. I need to add a client-side validation attribute (data-bvalidator="required") to a text area generated by WordPress ' wp_e

How to add custom attribute to Wordpress wp_editor text area?

Kapil yadav How to add custom attribute to Wordpress wp_editor textarea field? In the official documentation, there is no way to do this. I need to add a client-side validation attribute (data-bvalidator="required") to a text area generated by WordPress ' wp_e

How to add custom attribute to Wordpress wp_editor text area?

Kapil yadav How to add custom attribute to Wordpress wp_editor textarea field? In the official documentation, there is no way to do this. I need to add a client-side validation attribute (data-bvalidator="required") to a text area generated by WordPress ' wp_e

How to add custom attribute to Wordpress wp_editor text area?

Kapil yadav How to add custom attribute to Wordpress wp_editor textarea field? In the official documentation, there is no way to do this. I need to add a client-side validation attribute (data-bvalidator="required") to a text area generated by WordPress ' wp_e

How to add custom attribute to Wordpress wp_editor text area?

Kapil yadav How to add custom attribute to Wordpress wp_editor textarea field? In the official documentation, there is no way to do this. I need to add a client-side validation attribute (data-bvalidator="required") to a text area generated by WordPress ' wp_e

wp_editor: How to load wp_editor on demand with jQuery?

username I am trying to load wp_editor on demand using jquery/javascript. I have somehow successfully used the following code, but it is not saving the changed data in the element. tinyMCE.execCommand('mceAddEditor', false, textarea_id); I will be very gratef

Include TinyMCE plugin in Wordpress wp_editor?

Mathias Svensson Carlson Plugins are currently being written for WordPress, including the TinyMCE plugin for WordPress' built-in editor. However, when I print the TinyMCE editor on the custom admin page with: wp_editor( $content, $editor_id, $settings ); The

load wordpress wp_editor dynamically (ajax)

Zac This is an answer/solution rather than a question, still there maybe some bugs, even I tried on my dev env. I recently try to use wp_editor in widget/menu, after some search, I did not find a complete solution as I want. I would share my solution in below

Dynamically load wordpress wp_editor (ajax)

Zach This is an answer/solution, not a question, even if I try to use my development environment, there may still be some bugs. I recently tried to use wp_editor in a widget/menu and after some searching I didn't find the complete solution I was looking for. A

How to detect changes in wp_editor?

username How to detect in JavaScript if the content wp_editorof tinyMCE instance has changed in WordPress 4.2.2 ? I have tried tinyMCE.editors["content"].isDirty()but the result is always wrong. Yibao if (tinyMCE.activeEditor.isDirty()) alert("You must sav

CKEditor removes <html> and <body> tags

B. Azizan I use CKEditor and if I click the Source button and paste the HTML code like this: <html> <head> <meta http-equiv="Content-Type" content="text/html" /> </head> <body> <p>test</p> </body> </html> Then click "Source" again, and submit the form, the "

Jsoup removes only html tags

rougher What is the correct way to remove only html tags (keeping all custom/unknown tags) with JSOUP (without using regex)? Expected input: <html> <customTag> <div> dsgfdgdgf </div> </customTag> <123456789/> <123> <html123/> </html> Expected ou

Jsoup removes only html tags

rougher What is the correct way to remove only html tags (keeping all custom/unknown tags) with JSOUP (without using regex)? Expected input: <html> <customTag> <div> dsgfdgdgf </div> </customTag> <123456789/> <123> <html123/> </html> Expected ou

Jsoup removes only html tags

rougher What is the correct way to remove only html tags (keeping all custom/unknown tags) with JSOUP (without using regex)? Expected input: <html> <customTag> <div> dsgfdgdgf </div> </customTag> <123456789/> <123> <html123/> </html> Expected ou