Example #1
0
 function zoo_save_custom_meta_for_user($user_id)
 {
     // update user classifieds
     $new_classifieds = !empty($_POST['user_classifieds']) ? $_POST['user_classifieds'] : array();
     zoo_update_user_classifieds($user_id, $new_classifieds);
 }
function manage_wp_posts_be_qe_save_post($post_id, $post)
{
    // pointless if $_POST is empty (this happens on bulk edit)
    if (empty($_POST)) {
        return $post_id;
    }
    // verify quick edit nonce
    if (isset($_POST['_inline_edit']) && !wp_verify_nonce($_POST['_inline_edit'], 'inlineeditnonce')) {
        return $post_id;
    }
    // don't save for autosave
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return $post_id;
    }
    // dont save for revisions
    if (isset($post->post_type) && $post->post_type == 'revision') {
        return $post_id;
    }
    switch ($post->post_type) {
        case 'classified-ad':
            /**
             * Because this action is run in several places, checking for the array key
             * keeps WordPress from editing data that wasn't in the form, i.e. if you had
             * this post meta on your "Quick Edit" but didn't have it on the "Edit Post" screen.
             */
            $custom_fields = array('_zoo_classified_status', '_zoo_classified_expired_at', '_zoo_classified_featured', '_zoo_classified_owner');
            foreach ($custom_fields as $field) {
                if (array_key_exists($field, $_POST) && !empty($_POST[$field])) {
                    if ($field == '_zoo_classified_owner') {
                        if ($_POST[$field] == '-1') {
                            $current_owner = get_post_meta($post_id, '_zoo_classified_owner', true);
                            if ($current_owner) {
                                $prev_classifieds = get_the_author_meta('user_classifieds', $current_owner);
                                if (($key = array_search($post_id, $prev_classifieds)) !== false) {
                                    unset($prev_classifieds[$key]);
                                }
                                update_user_meta($current_owner, 'user_classifieds', $prev_classifieds);
                                zoo_update_classified_owner($_POST[$field], $post_id, true);
                            }
                        } else {
                            zoo_update_user_classifieds($_POST[$field], $post_id);
                        }
                    } else {
                        update_post_meta($post_id, $field, $_POST[$field]);
                    }
                }
            }
            break;
    }
}