Example #1
0
/**
 * Delete value in the database.
 *
 * @param  int    $post_id
 * @param  string $slug
 * @param  string $type
 *
 * @return bool
 */
function papi_delete_field($post_id = null, $slug = null, $type = 'page')
{
    if (!is_numeric($post_id) && is_string($post_id)) {
        $slug = $post_id;
        $post_id = null;
    }
    if (!is_string($slug) || empty($slug)) {
        return false;
    }
    $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_cache_delete($slug, $post_id);
    papi_action_delete_value($type, $slug, $post_id);
    return $property->delete_value($slug, $post_id, $type);
}
Example #2
0
/**
 * Delete value in the database.
 *
 * @param  int    $id
 * @param  string $slug
 * @param  string $type
 *
 * @return bool
 */
function papi_delete_field($id = null, $slug = null, $type = 'post')
{
    if (!is_numeric($id) && is_string($id)) {
        $type = empty($slug) ? $type : $slug;
        $slug = $id;
        $id = null;
    }
    if (!is_string($slug) || empty($slug)) {
        return false;
    }
    $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_cache_delete($slug, $id, $type);
    papi_action_delete_value($type, $slug, $id);
    return $property->delete_value($slug, $id, $type);
}