• Hi,

    When saving meta data with a custom metabox add_post_meta() is stripping out double quotes and the closing ‘/’ for the closing tag.

    I need to be able to save this:
    <meta name="fb:whatever" content="somecontent"/>

    How do I protect the string so add_post_meta() won’t strip it?
    I tried addslashes() but that ends up causing an error somewhere and stoping it from writing anything to the database at all.

    here is my save code excluding the admin check part.

    $current_data = esc_textarea(get_post_meta($post_id, '_my_meta_facebook', TRUE)); 
    
        $new_data = $_POST['_my_meta_facebook'];
    
        //$new_data = addslashes($new_data);
        //my_meta_facebook_clean($new_data);
    
        if ($current_data)
        {
            if (is_null($new_data)) delete_post_meta($post_id,'_my_meta_facebook');
            else update_post_meta($post_id,'_my_meta_facebook',addslashes($new_data));
        }
        elseif (!is_null($new_data))
        {
            add_post_meta($post_id,'_my_meta_facebook', addslashes($new_data), TRUE);
        }
    
        return $post_id;

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • I don’t know php but in javascript you would have to write something like this \/ to add a /

    Thread Starter iansane

    (@iansane)

    It would be the same with php. the \ is supposed to escape the next character. But there’s more than that going on here. It strips out the < and > and converts the double quotes to single quotes. Actually when I try to escape a character with the \ it ends up blank so maybe it is interpreting the \ as escape everything else after it.

    For a work around and probably more secure way, I made an input for each meta tag and then in the header have a function that gets those values and builds out the meta tags but I’d like to know how to do it the other way so if I wanted to just have a text area where the user can just type in a block of meta tags and have them added to the header all in one chunk.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘need to save html in a metabox, problem with add_post_meta’ is closed to new replies.