function zoo_update_user_classifieds($user_id, $new_classifieds) { $classified_premium_user_role = get_option('classified_premium_user_role'); $free_user_classified_count = get_option('free_user_classified_number'); $premium_user_classified_count = get_option('premium_user_classified_number'); $user_data = get_userdata($user_id); if (!in_array('administrator', $user_data->roles)) { if (in_array($classified_premium_user_role, $user_data->roles)) { $new_classifieds = array_slice($new_classifieds, 0, $premium_user_classified_count); } else { $new_classifieds = array_slice($new_classifieds, 0, $free_user_classified_count); } } // existing classified linking from option table $classified_linking = get_option('user_classified_linking'); if ($classified_linking && is_array($classified_linking) && sizeof($classified_linking) > 0) { foreach ($classified_linking as $classified_post_id => $assigned_user_id) { if ($assigned_user_id == $user_id) { // remove post meta zoo_update_classified_owner($assigned_user_id, $classified_post_id, true); // unlink this classified user linking unset($classified_linking[$classified_post_id]); } } } foreach ($new_classifieds as $classified_post_id) { // update post meta zoo_update_classified_owner($user_id, $classified_post_id); // push into existing array $classified_linking[$classified_post_id] = $user_id; } // update option table update_option('user_classified_linking', $classified_linking); }
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; } }