tags:

views:

138

answers:

2

Do I actually have to return $postID in each case, in the code below?

This is code required for capturing the values of custom fields I've added to the WP post and page editor. Got the idea from here: http://apartmentonesix.com/2009/03/creating-user-friendly-custom-fields-by-modifying-the-post-page/

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');
    }
}
        return $postID; //IS THIS EVEN NECESSARY?
}

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);
}
}
A: 

As far as I can see, the code you're being inspired by does not return $postID -- and I can't see anything in the Codex about it being necessary. So, no?

vicvicvic
+1  A: 

Actions never expect a return value. They are called by do_action('name'); in wp-includes/plugin.php which doesn’t return anything. So, no, you don’t have to return the $postID.

toscho