Skip to main content
corrected code formatting
Source Link
s_ha_dum
  • 65.5k
  • 13
  • 84
  • 174

I'm using a custom form field on a Custom Taxonomy to hold various data. All working well except in one particular case where I'm trying to save an iframe embed code (from Bandcamp) which is to be echoed in a template later. Wordpress is inserting \ before any " in the output. I've

I've tried using htmlspecialchars on my output, I've also added that to the value of my edit form field action. I guess I'm missing part of the process somewhere, perhaps on save?

Save function is:

function save_taxonomy_custom_meta_bandcamp_embed_music( $term_id ) { if ( isset( $_POST['term_meta'] ) ) { $t_id = $term_id; $term_meta = get_option( "taxonomy_$t_id" ); $cat_keys = array_keys( $_POST['term_meta'] ); foreach ( $cat_keys as $key ) { if ( isset ( $_POST['term_meta'][$key] ) ) { $term_meta[$key] = $_POST['term_meta'][$key]; } } // Save the option array. update_option( "taxonomy_$t_id", $term_meta ); } } add_action( 'edited_hhie_artists', 'save_taxonomy_custom_meta_bandcamp_embed_music', 10, 2 ); add_action( 'create_hhie_artists', 'save_taxonomy_custom_meta_bandcamp_embed_music', 10, 2 );

function save_taxonomy_custom_meta_bandcamp_embed_music( $term_id ) {
    if ( isset( $_POST['term_meta'] ) ) {
        $t_id = $term_id;
        $term_meta = get_option( "taxonomy_$t_id" );
        $cat_keys = array_keys( $_POST['term_meta'] );
        foreach ( $cat_keys as $key ) {
            if ( isset ( $_POST['term_meta'][$key] ) ) {
                $term_meta[$key] = $_POST['term_meta'][$key];
            }
        }
        // Save the option array.
        update_option( "taxonomy_$t_id", $term_meta );
    }
}  
add_action( 'edited_hhie_artists', 'save_taxonomy_custom_meta_bandcamp_embed_music', 10, 2 );  
add_action( 'create_hhie_artists', 'save_taxonomy_custom_meta_bandcamp_embed_music', 10, 2 );

I'm using a custom form field on a Custom Taxonomy to hold various data. All working well except in one particular case where I'm trying to save an iframe embed code (from Bandcamp) which is to be echoed in a template later. Wordpress is inserting \ before any " in the output. I've tried using htmlspecialchars on my output, I've also added that to the value of my edit form field action. I guess I'm missing part of the process somewhere, perhaps on save?

Save function is:

function save_taxonomy_custom_meta_bandcamp_embed_music( $term_id ) { if ( isset( $_POST['term_meta'] ) ) { $t_id = $term_id; $term_meta = get_option( "taxonomy_$t_id" ); $cat_keys = array_keys( $_POST['term_meta'] ); foreach ( $cat_keys as $key ) { if ( isset ( $_POST['term_meta'][$key] ) ) { $term_meta[$key] = $_POST['term_meta'][$key]; } } // Save the option array. update_option( "taxonomy_$t_id", $term_meta ); } } add_action( 'edited_hhie_artists', 'save_taxonomy_custom_meta_bandcamp_embed_music', 10, 2 ); add_action( 'create_hhie_artists', 'save_taxonomy_custom_meta_bandcamp_embed_music', 10, 2 );

I'm using a custom form field on a Custom Taxonomy to hold various data. All working well except in one particular case where I'm trying to save an iframe embed code (from Bandcamp) which is to be echoed in a template later. Wordpress is inserting \ before any " in the output.

I've tried using htmlspecialchars on my output, I've also added that to the value of my edit form field action. I guess I'm missing part of the process somewhere, perhaps on save?

Save function is:

function save_taxonomy_custom_meta_bandcamp_embed_music( $term_id ) {
    if ( isset( $_POST['term_meta'] ) ) {
        $t_id = $term_id;
        $term_meta = get_option( "taxonomy_$t_id" );
        $cat_keys = array_keys( $_POST['term_meta'] );
        foreach ( $cat_keys as $key ) {
            if ( isset ( $_POST['term_meta'][$key] ) ) {
                $term_meta[$key] = $_POST['term_meta'][$key];
            }
        }
        // Save the option array.
        update_option( "taxonomy_$t_id", $term_meta );
    }
}  
add_action( 'edited_hhie_artists', 'save_taxonomy_custom_meta_bandcamp_embed_music', 10, 2 );  
add_action( 'create_hhie_artists', 'save_taxonomy_custom_meta_bandcamp_embed_music', 10, 2 );
Source Link
JMB
  • 628
  • 7
  • 16

Avoiding stripping of HTML in Custom Taxonomy Meta Field

I'm using a custom form field on a Custom Taxonomy to hold various data. All working well except in one particular case where I'm trying to save an iframe embed code (from Bandcamp) which is to be echoed in a template later. Wordpress is inserting \ before any " in the output. I've tried using htmlspecialchars on my output, I've also added that to the value of my edit form field action. I guess I'm missing part of the process somewhere, perhaps on save?

Save function is:

function save_taxonomy_custom_meta_bandcamp_embed_music( $term_id ) { if ( isset( $_POST['term_meta'] ) ) { $t_id = $term_id; $term_meta = get_option( "taxonomy_$t_id" ); $cat_keys = array_keys( $_POST['term_meta'] ); foreach ( $cat_keys as $key ) { if ( isset ( $_POST['term_meta'][$key] ) ) { $term_meta[$key] = $_POST['term_meta'][$key]; } } // Save the option array. update_option( "taxonomy_$t_id", $term_meta ); } } add_action( 'edited_hhie_artists', 'save_taxonomy_custom_meta_bandcamp_embed_music', 10, 2 ); add_action( 'create_hhie_artists', 'save_taxonomy_custom_meta_bandcamp_embed_music', 10, 2 );