/** * @param $object_type * @param null $_null * @param int $object_id * @param string $meta_key * @param string $meta_value * @param bool $delete_all * * @return null */ public function delete_meta($object_type, $_null = null, $object_id = 0, $meta_key = '', $meta_value = '', $delete_all = false) { if (pods_tableless()) { return $_null; } $object = $this->get_object($object_type, $object_id); if (empty($object_id) || empty($object) || !isset($object['fields'][$meta_key])) { return $_null; } // @todo handle $delete_all (delete the field values from all pod items) if (!empty($meta_value) && in_array($object['fields'][$meta_key]['type'], PodsForm::tableless_field_types())) { if (!is_object(self::$current_field_pod) || self::$current_field_pod->pod != $object['name']) { self::$current_field_pod = pods($object['name'], $object_id); } elseif (self::$current_field_pod->id() != $object_id) { self::$current_field_pod->fetch($object_id); } $pod = self::$current_field_pod; $pod->remove_from($meta_key, $meta_value); } else { if (!is_object(self::$current_field_pod) || self::$current_field_pod->pod != $object['name']) { self::$current_field_pod = pods($object['name']); } $pod = self::$current_field_pod; $pod->save(array($meta_key => null), null, $object_id); } return $_null; }
/** * @param $post_id * @param $post * * @return mixed */ public function save_post($post_id, $post) { $is_new_item = false; if ('new' == self::$old_post_status) { $is_new_item = true; } // Reset to avoid manual new post issues self::$old_post_status = ''; $blacklisted_types = array('revision', '_pods_pod', '_pods_field'); $blacklisted_types = apply_filters('pods_meta_save_post_blacklist_types', $blacklisted_types, $post_id, $post); if (empty($_POST) || 1 != pods_var('pods_metasave', 'post')) { return $post_id; } // @todo Figure out how to hook into autosave for saving meta // Block Autosave and Revisions if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || in_array($post->post_type, $blacklisted_types)) { return $post_id; } // Block Quick Edits / Bulk Edits if ('edit.php' == pods_var('pagenow', 'global') && ('inline-save' == pods_var('action', 'post') || null != pods_var('bulk_edit', 'get') || is_array(pods_var('post', 'get')))) { return $post_id; } // Block Trash if (in_array(pods_var('action', 'get'), array('untrash', 'trash'))) { return $post_id; } // Block Auto-drafting and Trash (not via Admin action) $blacklisted_status = array('auto-draft', 'trash'); $blacklisted_status = apply_filters('pods_meta_save_post_blacklist_status', $blacklisted_status, $post_id, $post); if (in_array($post->post_status, $blacklisted_status)) { return $post_id; } $groups = $this->groups_get('post_type', $post->post_type); if (empty($groups)) { return $post_id; } $data = array(); $id = $post_id; $pod = null; foreach ($groups as $group) { if (empty($group['fields'])) { continue; } if (null === $pod) { $pod = pods($group['pod']['name'], $id, true); } foreach ($group['fields'] as $field) { if (false === PodsForm::permission($field['type'], $field['name'], $field, $group['fields'], $pod, $id)) { if (!pods_var('hidden', $field['options'], false, null, true)) { continue; } } $data[$field['name']] = ''; if (isset($_POST['pods_meta_' . $field['name']])) { $data[$field['name']] = $_POST['pods_meta_' . $field['name']]; } } } if ($is_new_item) { do_action('pods_meta_create_pre_post', $data, $pod, $id, $groups, $post, $post->post_type); do_action("pods_meta_create_pre_post_{$post->post_type}", $data, $pod, $id, $groups, $post); } do_action('pods_meta_save_pre_post', $data, $pod, $id, $groups, $post, $post->post_type); do_action("pods_meta_save_pre_post_{$post->post_type}", $data, $pod, $id, $groups, $post); pods_no_conflict_on('post'); if (!empty($pod)) { // Fix for Pods doing it's own sanitization $data = stripslashes_deep($data); $pod->save($data, null, null, array('is_new_item' => $is_new_item)); } elseif (!empty($id)) { foreach ($data as $field => $value) { update_post_meta($id, $field, $value); } } pods_no_conflict_off('post'); if ($is_new_item) { do_action('pods_meta_create_post', $data, $pod, $id, $groups, $post, $post->post_type); do_action("pods_meta_create_post_{$post->post_type}", $data, $pod, $id, $groups, $post); } do_action('pods_meta_save_post', $data, $pod, $id, $groups, $post, $post->post_type); do_action("pods_meta_save_post_{$post->post_type}", $data, $pod, $id, $groups, $post); return $post_id; }
/** * Include and Init the PodsMeta class * * @see PodsMeta * * @return PodsMeta * * @since 2.0 */ function pods_meta() { require_once PODS_DIR . 'classes/PodsMeta.php'; return PodsMeta::init(); }