save_pod_item() public method

$params['pod'] string The Pod name (pod or pod_id is required) $params['pod_id'] string The Pod ID (pod or pod_id is required) $params['id'] int The item ID $params['data'] array (optional) Associative array of field names + values $params['bypass_helpers'] bool Set to true to bypass running pre-save and post-save helpers $params['track_changed_fields'] bool Set to true to enable tracking of saved fields via PodsAPI::get_changed_fields()
Since: 1.7.9
public save_pod_item ( array | object $params ) : integer
$params array | object An associative array of parameters
return integer The item ID
Beispiel #1
0
 /**
  * Save an item by giving an array of field data or set a specific field to a specific value.
  *
  * Though this function has the capacity to add new items, best practice should direct you
  * to use add() for that instead.
  *
  * @see PodsAPI::save_pod_item
  *
  * @param array|string $data Either an associative array of field information or a field name
  * @param mixed $value (optional) Value of the field, if $data is a field name
  * @param int $id (optional) ID of the pod item to update
  * @param array $params (optional) Additional params to send to save_pod_item
  *
  * @return int The item ID
  *
  * @since 2.0
  * @link http://pods.io/docs/save/
  */
 public function save($data = null, $value = null, $id = null, $params = null)
 {
     if (null !== $value) {
         $data = array($data => $value);
     }
     $fetch = false;
     if (null === $id) {
         $fetch = true;
         $id = $this->id();
     }
     $data = (array) $this->do_hook('save', $data, $id);
     if (empty($data)) {
         return $id;
     }
     $default = array();
     if (!empty($params) && is_array($params)) {
         $default = $params;
     }
     $params = array('pod' => $this->pod, 'id' => $id, 'data' => $data, 'allow_custom_fields' => true);
     if (!empty($default)) {
         $params = array_merge($params, $default);
     }
     $id = $this->api->save_pod_item($params);
     if (0 < $id && $fetch) {
         $this->fetch($id, false);
     }
     return $id;
 }
Beispiel #2
0
 /**
  * Save an item by giving an array of field data or set a specific field to a specific value.
  *
  * Though this function has the capacity to add new items, best practice should direct you
  * to use add() for that instead.
  *
  * @see PodsAPI::save_pod_item
  *
  * @param array|string $data Either an associative array of field information or a field name
  * @param mixed $value (optional) Value of the field, if $data is a field name
  * @param int $id (optional) ID of the pod item to update
  * @param array $params (optional) Additional params to send to save_pod_item
  *
  * @return int The item ID
  *
  * @since 2.0
  * @link http://pods.io/docs/save/
  */
 public function save($data = null, $value = null, $id = null, $params = null)
 {
     if (null !== $value) {
         $data = array($data => $value);
     }
     $fetch = false;
     if (null === $id || $this->row && $id == $this->id()) {
         $fetch = true;
         if (null === $id) {
             $id = $this->id();
         }
     }
     $data = (array) $this->do_hook('save', $data, $id);
     if (empty($data)) {
         return $id;
     }
     $default = array();
     if (!empty($params) && is_array($params)) {
         $default = $params;
     }
     $params = array('pod' => $this->pod, 'id' => $id, 'data' => $data, 'allow_custom_fields' => true, 'clear_slug_cache' => false);
     if (!empty($default)) {
         $params = array_merge($params, $default);
     }
     $id = $this->api->save_pod_item($params);
     if (0 < $id && $fetch) {
         $this->fetch($id, false);
     }
     if (!empty($this->pod_data['field_slug'])) {
         if (0 < $id && $fetch) {
             $slug = $this->field($this->pod_data['field_slug']);
         } else {
             $slug = pods($this->pod, $id)->field($this->pod_data['field_slug']);
         }
         if (0 < strlen($slug)) {
             pods_cache_clear($slug, 'pods_items_' . $this->pod);
         }
     }
     return $id;
 }