PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.64
Timetics – Appointment Booking Calendar & Scheduling v1.0.64
1.0.64 1.0.62 1.0.63 1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 All 65 releases
timetics / vendor / themewinter / email-notification-sdk / src / Base / post.php

post.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.64, at vendor/themewinter/email-notification-sdk/src/Base/post.php

163 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Ens\Base;
4
5 /**
6 * Main post class
7 *
8 * @since 1.0.0
9 *
10 * @package ENS
11 */
12 class Post {
13
14 /**
15 * Store post object
16 *
17 * @since 1.0.0
18 *
19 * @var Object
20 */
21 private $post;
22
23 /**
24 * Post class constructor
25 *
26 * @since 1.0.0
27 *
28 * @return void
29 */
30 public function __construct( PostModel $post ) {
31 $this->post = $post;
32 }
33
34 /**
35 * Create post
36 *
37 * @since 1.0.0
38 *
39 * @param array $args
40 *
41 * @return PostModel
42 */
43 public function create( $args = [] ) {
44 $defaults = [
45 'post_title' => '',
46 'post_type' => $this->post->post_type,
47 'post_status' => 'publish',
48 'post_author' => 1,
49 ];
50
51 $args = wp_parse_args( $args, $defaults );
52 $post_id = wp_insert_post( $args );
53
54 $this->load( $this->post, $post_id );
55 $this->save_meta( $args );
56
57 return $this->post;
58 }
59
60 /**
61 * Update post
62 *
63 * @since 1.0.0
64 *
65 * @param array $args
66 *
67 * @return PostModel
68 */
69 public function update( $post_id, $args = [] ) {
70 $defaults = [
71 'post_title' => '',
72 'post_type' => $this->post->post_type,
73 'post_status' => 'publish',
74 'ID' => $post_id,
75 'post_author' => 1,
76 ];
77
78 $args = wp_parse_args( $args, $defaults );
79
80 $post_id = wp_update_post( $args );
81
82 $this->load( $this->post, $post_id );
83 $this->save_meta( $args );
84
85 return $this->post;
86 }
87
88 /**
89 * Delete post
90 *
91 * @since 1.0.0
92 *
93 * @return boolean
94 */
95 public function delete( $post_id = 0 ) {
96 return wp_delete_post( $post_id, true );
97 }
98
99 /**
100 * Update post meta data
101 *
102 * @since 1.0.0
103 *
104 * @param array $props
105 *
106 * @return void
107 */
108 public function save_meta( $props = [] ) {
109 foreach ( $props as $key => $value ) {
110 $meta_key = $this->post->prefix . $key;
111
112 // If a meta key exists on that post then update the post meta.
113 if ( array_key_exists( $key, $this->post->data ) ) {
114 update_post_meta( $this->post->id, $meta_key, $value );
115 }
116 }
117 }
118
119 /**
120 * Load all properties every model
121 *
122 * @since 1.0.0
123 *
124 * @param PostModel $object Post model object
125 * @param Object $post WordPress post object
126 *
127 * @return void
128 */
129 public function load( $object, $post ) {
130
131 if ( is_int( $post ) ) {
132 $post = get_post( $post );
133 }
134
135 $data = $object->data;
136 $object->id = $post->ID;
137 unset( $data['id'] );
138
139 foreach ( $data as $key => $value ) {
140 $prop = $object->get_prop( $key );
141 $object->$key = '' === $prop ? $value : $prop;
142 }
143 }
144
145 /**
146 * Get post a single post
147 *
148 * @since 1.0.0
149 *
150 * @param integer $post_id
151 *
152 * @return PostModel
153 */
154 public function find( $post_id ) {
155 $post = get_post( $post_id );
156
157 if ( $post ) {
158 $this->load( $this->post, $post );
159 }
160
161 return $this->post;
162 }
163 }