Custom add_action('save_post') causes html markup to disappear!

Posted by Scott B on Stack Overflow See other posts from Stack Overflow or by Scott B
Published on 2010-04-03T12:37:09Z Indexed on 2010/04/03 12:43 UTC
Read the original article Hit count: 188

Filed under:
|

I've added a custom "save_post" action to my theme (code is below). However, when I place images or video code in the post, its stripped away. The only way I can get it to stay is to comment out the add_action line. What do I need to do in order to keep all the post info intact?

add_action('save_post', 'custom_add_save');

function custom_add_save($postID){
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $postID;
    }
    else
    {
        // called after a post or page is saved
        if($parent_id = wp_is_post_revision($postID))
        {
        $postID = $parent_id;
        }

        if ($_POST['my_customHeader']) 
        {
            update_custom_meta($postID, $_POST['my_customHeader'], 'my_customHeader');
        }
        else
        {
            update_custom_meta($postID, '', 'my_customHeader');
        }
        if ($_POST['my_customTitle']) 
        {
            update_custom_meta($postID, $_POST['my_customTitle'], 'my_customTitle');
        }
        else
        {
            update_custom_meta($postID, '', 'my_customTitle');
        }
    }
}

function update_custom_meta($postID, $newvalue, $field_name) {
    // To create new meta
    if(!get_post_meta($postID, $field_name)){
    add_post_meta($postID, $field_name, $newvalue);
    }else{
    // or to update existing meta
    update_post_meta($postID, $field_name, $newvalue);
    }
}

© Stack Overflow or respective owner

Related posts about php

Related posts about Wordpress