Example #1
0
/**
 * Update field with new value. The old value will be deleted.
 *
 * @param  int    $id
 * @param  string $slug
 * @param  mixed  $value
 * @param  string $type
 *
 * @return bool
 */
function papi_update_field($id = null, $slug = null, $value = null, $type = 'post')
{
    if (!is_numeric($id) && is_string($id)) {
        $type = empty($value) ? $value : $type;
        $value = $slug;
        $slug = $id;
        $id = null;
    }
    if (!is_string($slug) || empty($slug)) {
        return false;
    }
    if (papi_is_empty($value)) {
        return papi_delete_field($id, $slug, $type);
    }
    $id = papi_get_meta_id($type, $id);
    $store = papi_get_meta_store($id, $type);
    if (is_null($store)) {
        return false;
    }
    $property = $store->get_property($slug);
    if (!papi_is_property($property)) {
        return false;
    }
    papi_delete_field($id, $slug, $type);
    $value = $property->update_value($value, $slug, $id);
    $value = papi_filter_update_value($property->get_option('type'), $value, $slug, $id, $type);
    return papi_update_property_meta_value(['type' => $type, 'id' => $id, 'slug' => $slug, 'value' => $value]);
}
Example #2
0
/**
 * Get entry type id.
 *
 * @param  int $id
 * @param  string $type
 *
 * @return string
 */
function papi_get_entry_type_id($id = 0, $type = null)
{
    $type = papi_get_meta_type($type);
    $id = papi_get_meta_id($type, $id);
    if ($id > 0) {
        if ($meta_value = get_metadata($type, $id, papi_get_page_type_key(), true)) {
            return $meta_value;
        }
    }
    $entry_type_id = papi_get_qs('entry_type');
    /**
     * Change entry type id.
     *
     * @param  string $entry_type_id
     * @param  string $type
     *
     * @return string
     */
    return apply_filters('papi/entry_type_id', $entry_type_id, $type);
}
 /**
  * Get property value.
  *
  * @param  Papi_Core_Conditional_Rule $rule
  *
  * @return mixed
  */
 private function get_value(Papi_Core_Conditional_Rule $rule)
 {
     if (papi_doing_ajax()) {
         $source = $rule->get_source();
         $meta_id = papi_get_meta_id();
         $entry_type = papi_get_entry_type_by_meta_id($meta_id);
         if (!papi_is_empty($source) && $entry_type instanceof Papi_Entry_Type !== false) {
             if (papi_is_property($entry_type->get_property($rule->slug))) {
                 return $this->get_deep_value($rule->slug, $source);
             }
         }
     }
     if (!papi_is_empty($rule->get_source())) {
         return $this->get_deep_value($rule->slug, $rule->get_source());
     }
     $slug = $rule->get_field_slug();
     $type = papi_get_meta_type();
     $value = papi_get_field($slug, null, $type);
     return $this->get_deep_value($slug, $value);
 }