Example #1
0
/**
 * Delete property value in the database.
 *
 * @param  int    $term_id
 * @param  string $slug
 *
 * @return bool
 */
function papi_delete_term_field($term_id, $slug = '')
{
    if (!is_numeric($term_id) && is_string($term_id)) {
        $slug = $term_id;
        $term_id = null;
    }
    if (!is_string($slug) || empty($slug)) {
        return false;
    }
    return papi_delete_field(papi_get_term_id($term_id), $slug, 'term');
}
Example #2
0
/**
 * Update field with new value. The old value will be deleted.
 *
 * @param  int    $post_id
 * @param  string $slug
 * @param  mixed  $value
 * @param  string $type
 *
 * @return bool
 */
function papi_update_field($post_id = null, $slug = null, $value = null, $type = 'page')
{
    if (!is_numeric($post_id) && is_string($post_id)) {
        $value = $slug;
        $slug = $post_id;
        $post_id = null;
    }
    if (!is_string($slug) || empty($slug)) {
        return false;
    }
    if (papi_is_empty($value)) {
        return papi_delete_field($post_id, $slug, $type);
    }
    $post_id = papi_get_post_id($post_id);
    if ($post_id === 0 && $type === Papi_Post_Page::TYPE) {
        return false;
    }
    $page = papi_get_page($post_id, $type);
    if (is_null($page)) {
        return false;
    }
    $property = $page->get_property($slug);
    if (!papi_is_property($property)) {
        return false;
    }
    papi_delete_field($post_id, $slug, $type);
    $value = $property->update_value($value, $slug, $post_id);
    $value = papi_filter_update_value($property->get_option('type'), $value, $slug, $post_id);
    return papi_update_property_meta_value(['type' => $type, 'post_id' => $post_id, 'slug' => $slug, 'value' => $value]);
}
Example #3
0
/**
 * Delete value in the database.
 *
 * @param  string $slug
 *
 * @return bool
 */
function papi_delete_option($slug)
{
    return papi_delete_field(0, $slug, 'option');
}
 /**
  * Restore to post revision.
  *
  * @param int $post_id
  * @param int $revision_id
  */
 public function restore_post_revision($post_id, $revision_id)
 {
     $slugs = papi_get_slugs($revision_id, true);
     foreach ($slugs as $slug) {
         $value = papi_get_field($revision_id, $slug);
         if (papi_is_empty($value)) {
             papi_delete_field($post_id, $slug);
         } else {
             papi_update_field($post_id, $slug, $value);
         }
     }
 }
Example #5
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 #6
0
/**
 * Delete value in the database.
 *
 * @param  string $slug
 *
 * @return bool
 */
function papi_delete_option($slug)
{
    return papi_delete_field(0, $slug, Papi_Core_Page::TYPE_OPTION);
}
Example #7
0
/**
 * Delete value in the database.
 *
 * @param  string $slug
 *
 * @return bool
 */
function papi_delete_option($slug)
{
    return papi_delete_field(0, $slug, Papi_Option_Page::TYPE);
}