0

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

2 Answers 2

0

you can use esc_attr

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] = esc_attr( $_POST['term_meta'][$key] ); // encoded text with HTML entities
            }
        }
        // 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 );
1
  • Thanks a lot for that. As simple as escaping attributes on save. What I figured, but wasn't sure. Returning the correct iframe code, now just to figure out how to get it to embed rather than echo the iframe code.
    – JMB
    Commented Dec 8, 2013 at 20:17
0

wordpress always slashes all parameters of $_GET and $_POST. You should unslash them when updating your option in your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.