PluginProbe
Site Reviews / trunk
Site Reviews vtrunk
8.3.1 8.3.0 8.2.2 8.2.1 8.2.0 8.1.0 8.0.13 8.0.12 8.0.11 trunk 1.2.2 2.17.1 3.5.4 4.7.0 5.25.1 6.11.8 7.0.10 7.0.11 7.0.12 7.0.13 7.0.14 7.0.15 7.0.16 7.0.17 7.0.18 All 54 releases
site-reviews / plugin / Database / PostMeta.php

PostMeta.php in Site Reviews trunk, at plugin/Database/PostMeta.php

41 lines 1013 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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