PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.1.0
Kirki – Freeform Page Builder, Website Builder & Customizer v6.1.0
6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / app / Models / PostMeta.php
kirki / app / Models Last commit date
Collaboration.php 3 weeks ago CollaborationComment.php 3 weeks ago CollaborationCommentSeen.php 3 weeks ago CollaborationConnected.php 3 weeks ago CollaborationSent.php 3 weeks ago Collection.php 3 weeks ago CollectionItem.php 3 weeks ago Media.php 3 weeks ago Page.php 3 weeks ago Post.php 3 weeks ago PostMeta.php 3 days ago Reference.php 3 weeks ago Term.php 3 weeks ago TermMeta.php 3 weeks ago TermTaxonomy.php 3 weeks ago User.php 3 weeks ago UserMeta.php 3 weeks ago
PostMeta.php
58 lines
1 <?php
2
3 namespace Kirki\App\Models;
4
5 defined('ABSPATH') || exit;
6
7 use Kirki\App\Casts\AsSerialize;
8 use Kirki\Framework\Database\Query\Model;
9
10 class PostMeta extends Model
11 {
12 protected $table = 'postmeta';
13
14 protected $primary_key = 'meta_id';
15 protected $timestamps = false;
16
17 protected $fillable = [
18 'post_id',
19 'meta_key',
20 'meta_value',
21 ];
22
23 protected $casts = [
24 'post_id' => 'integer',
25 'meta_value' => AsSerialize::class,
26 ];
27
28 /**
29 * @param int $post_id
30 * @param string $meta_key
31 * @param mixed $default
32 *
33 * @return mixed
34 */
35 public static function get_meta_value(int $post_id, string $meta_key, $default = null)
36 {
37 $meta = static::where('post_id', $post_id)->where('meta_key', $meta_key)->first();
38 return $meta && $meta->meta_value !== null && $meta->meta_value !== '' ? $meta->meta_value : $default;
39 }
40
41 /**
42 * @param int $post_id
43 * @param string $meta_key
44 * @param mixed $meta_value
45 *
46 * @return static
47 */
48 public static function update_meta_value(int $post_id, string $meta_key, $meta_value)
49 {
50 return static::update_or_create(['post_id' => $post_id, 'meta_key' => $meta_key], ['meta_value' => $meta_value]);
51 }
52
53 public function post()
54 {
55 return $this->belongs_to(Post::class, 'post_id', 'ID');
56 }
57 }
58