| 1 |
<?php |
| 2 |
|
| 3 |
namespace GeminiLabs\SiteReviews\Database; |
| 4 |
|
| 5 |
use GeminiLabs\SiteReviews\Helpers\Cast; |
| 6 |
use GeminiLabs\SiteReviews\Helpers\Str; |
| 7 |
|
| 8 |
class PostMeta |
| 9 |
{ |
| 10 |
public function delete(int $postId, string $key): bool |
| 11 |
{ |
| 12 |
$metaKey = Str::prefix($key, '_'); |
| 13 |
return delete_metadata('post', $postId, $metaKey); |
| 14 |
} |
| 15 |
|
| 16 |
public function exists(int $postId, string $key): bool |
| 17 |
{ |
| 18 |
$metaKey = Str::prefix($key, '_'); |
| 19 |
return metadata_exists('post', $postId, $metaKey); |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* @return mixed |
| 24 |
*/ |
| 25 |
public function get(int $postId, string $key, string $cast = '') |
| 26 |
{ |
| 27 |
$metaKey = Str::prefix($key, '_'); |
| 28 |
$metaValue = get_metadata('post', $postId, $metaKey, true); |
| 29 |
return Cast::to($cast, $metaValue); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @param mixed $value |
| 34 |
*/ |
| 35 |
public function set(int $postId, string $key, $value): bool |
| 36 |
{ |
| 37 |
$metaKey = Str::prefix($key, '_'); |
| 38 |
return false !== update_metadata('post', $postId, $metaKey, $value); |
| 39 |
} |
| 40 |
} |
| 41 |
|