PluginProbe
UpStream: a Project Management Plugin for WordPress / 2.1.0
UpStream: a Project Management Plugin for WordPress v2.1.0
trunk 1.39.0 1.39.1 1.39.2 1.39.3 2.0.7 2.1.0
upstream / includes / class-upstream-client.php

class-upstream-client.php in UpStream: a Project Management Plugin for WordPress 2.1.0, at includes/class-upstream-client.php

286 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * UpStream_Client Class
4 *
5 * @package UpStream
6 */
7
8 // Exit if accessed directly.
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * UpStream_Client Class
15 *
16 * @since 1.0
17 */
18 class UpStream_Client {
19
20 /**
21 * The client ID
22 *
23 * @var int $ID Client ID.
24 * @since 1.0
25 */
26 public $ID = 0;
27
28 /**
29 * The meta prefix
30 *
31 * @var string $meta_prefix Meta prefix.
32 * @since 1.0
33 */
34 public $meta_prefix = '_upstream_client_';
35
36 /**
37 * The meta keys
38 *
39 * @var array $meta Meta keys.
40 * @since 1.0
41 */
42 public $meta = array(
43 'logo',
44 'logo_id',
45 'address',
46 'phone',
47 'website',
48 'users',
49 );
50
51 /**
52 * Declare the default properties in WP_Post as we can't extend it
53 * Anything we've declared above has been removed.
54 */
55
56 /**
57 * The post author
58 *
59 * @var int Post author.
60 */
61 public $post_author = 0;
62
63 /**
64 * The post date
65 *
66 * @var string Post date.
67 */
68 public $post_date = '0000-00-00 00:00:00';
69
70 /**
71 * The post date in GMT
72 *
73 * @var string Post date in GMT.
74 */
75 public $post_date_gmt = '0000-00-00 00:00:00';
76
77 /**
78 * The post content
79 *
80 * @var string Post content.
81 */
82 public $post_content = '';
83
84 /**
85 * The post title
86 *
87 * @var string Post title.
88 */
89 public $post_title = '';
90
91 /**
92 * The post excerpt
93 *
94 * @var string Post excerpt.
95 */
96 public $post_excerpt = '';
97
98 /**
99 * The post status
100 *
101 * @var string Post status.
102 */
103 public $post_status = 'publish';
104
105 /**
106 * The comment status
107 *
108 * @var string Comment status.
109 */
110 public $comment_status = 'open';
111
112 /**
113 * The ping status
114 *
115 * @var string Ping status.
116 */
117 public $ping_status = 'open';
118
119 /**
120 * The post password
121 *
122 * @var string Post password.
123 */
124 public $post_password = '';
125
126 /**
127 * The post name
128 *
129 * @var string Post name.
130 */
131 public $post_name = '';
132
133 /**
134 * To ping
135 *
136 * @var string To ping.
137 */
138 public $to_ping = '';
139
140 /**
141 * Pinged
142 *
143 * @var string Pinged.
144 */
145 public $pinged = '';
146
147 /**
148 * Post modified date
149 *
150 * @var string Post modified date.
151 */
152 public $post_modified = '0000-00-00 00:00:00';
153
154 /**
155 * Post modified date GMT
156 *
157 * @var string Post modified date GMT.
158 */
159 public $post_modified_gmt = '0000-00-00 00:00:00';
160
161 /**
162 * Post content filtered
163 *
164 * @var string Post content filtered.
165 */
166 public $post_content_filtered = '';
167
168 /**
169 * Post parent
170 *
171 * @var string Post parent.
172 */
173 public $post_parent = 0;
174
175 /**
176 * Post GUID
177 *
178 * @var string Post GUID.
179 */
180 public $guid = '';
181
182 /**
183 * Menu order
184 *
185 * @var string Menu order.
186 */
187 public $menu_order = 0;
188
189 /**
190 * Post mime type
191 *
192 * @var string Post mime type.
193 */
194 public $post_mime_type = '';
195
196 /**
197 * Comment count
198 *
199 * @var int Comment count.
200 */
201 public $comment_count = 0;
202
203 /**
204 * Filter
205 *
206 * @var int Filter.
207 */
208 public $filter;
209
210 /**
211 * Get things going
212 *
213 * @param mixed $_id Client ID or false.
214 * @param array $_args Query argument.
215 * @since 1.0
216 */
217 public function __construct( $_id = false, $_args = array() ) {
218 // if no id is sent, then go through the varous ways of getting the id
219 // may need to check the order more closely to ensure we get it right.
220 if ( ! $_id ) {
221 $user_id = upstream_current_user_id();
222 $_id = upstream_get_users_client_id( $user_id );
223 }
224
225 if ( ! $_id ) {
226 $_id = upstream_project_client_id();
227 }
228
229 $client = WP_Post::get_instance( $_id );
230
231 return $this->setup_client( $client );
232 }
233
234 /**
235 * Given the client data, let's set the variables
236 *
237 * @since 2.3.6
238 *
239 * @param object $client The Client Object.
240 *
241 * @return bool If the setup was successful or not
242 */
243 private function setup_client( $client ) {
244 if ( ! is_object( $client ) ) {
245 return false;
246 }
247
248 if ( ! is_a( $client, 'WP_Post' ) ) {
249 return false;
250 }
251
252 if ( 'client' !== $client->post_type ) {
253 return false;
254 }
255
256 // sets the value of each key.
257 foreach ( $client as $key => $value ) {
258 switch ( $key ) {
259 default:
260 $this->$key = $value;
261 break;
262 }
263 }
264
265 return true;
266 }
267
268 /**
269 * Get a meta value
270 *
271 * @since 1.0.0
272 *
273 * @param string $meta the meta field (without prefix).
274 *
275 * @return mixed
276 */
277 public function get_meta( $meta ) {
278 $result = get_post_meta( $this->ID, $this->meta_prefix . $meta, true );
279 if ( ! $result ) {
280 $result = null;
281 }
282
283 return $result;
284 }
285 }
286