1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
<?php
class Papi_Post_Store extends Papi_Core_Meta_Store {
private $post;
protected $type = 'post';
public function __construct( $id = 0 ) {
$this->id = papi_get_post_id( $id );
$this->post = get_post( $this->id );
$id = papi_get_page_type_id( $this->id );
$this->type_class = papi_get_entry_type_by_id( $id );
}
public function get_permalink() {
return get_permalink( $this->id );
}
public function get_post() {
return $this->post;
}
public function get_status() {
return get_post_status( $this->id );
}
public function get_property( $slug, $child_slug = '' ) {
$page_type_id = papi_get_page_type_id( $this->id );
$page_type = papi_get_entry_type_by_id( $page_type_id );
if ( $page_type instanceof Papi_Page_Type === false ) {
return;
}
if ( $property = $page_type->get_property( $slug, $child_slug ) ) {
return $this->prepare_property( $property );
}
}
protected function prepare_load_value( Papi_Core_Property $property, $value ) {
if ( $property->overwrite ) {
clean_post_cache( $this->id );
$slug = $property->get_slug( true );
$context = is_admin() ? 'edit' : 'display';
$value = get_post_field( $slug, $this->id, $context );
}
return $value;
}
public function valid() {
return ! is_null( $this->post );
}
}