241 $_post = wp_cache_get( $post_id, 'posts' ); |
239 $_post = wp_cache_get( $post_id, 'posts' ); |
242 |
240 |
243 if ( ! $_post ) { |
241 if ( ! $_post ) { |
244 $_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id ) ); |
242 $_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id ) ); |
245 |
243 |
246 if ( ! $_post ) |
244 if ( ! $_post ) { |
247 return false; |
245 return false; |
|
246 } |
248 |
247 |
249 $_post = sanitize_post( $_post, 'raw' ); |
248 $_post = sanitize_post( $_post, 'raw' ); |
250 wp_cache_add( $_post->ID, $_post, 'posts' ); |
249 wp_cache_add( $_post->ID, $_post, 'posts' ); |
251 } elseif ( empty( $_post->filter ) ) { |
250 } elseif ( empty( $_post->filter ) ) { |
252 $_post = sanitize_post( $_post, 'raw' ); |
251 $_post = sanitize_post( $_post, 'raw' ); |
274 * |
274 * |
275 * @param string $key Property to check if set. |
275 * @param string $key Property to check if set. |
276 * @return bool |
276 * @return bool |
277 */ |
277 */ |
278 public function __isset( $key ) { |
278 public function __isset( $key ) { |
279 if ( 'ancestors' == $key ) |
279 if ( 'ancestors' === $key ) { |
280 return true; |
280 return true; |
281 |
281 } |
282 if ( 'page_template' == $key ) |
282 |
|
283 if ( 'page_template' === $key ) { |
283 return true; |
284 return true; |
284 |
285 } |
285 if ( 'post_category' == $key ) |
286 |
286 return true; |
287 if ( 'post_category' === $key ) { |
287 |
288 return true; |
288 if ( 'tags_input' == $key ) |
289 } |
289 return true; |
290 |
|
291 if ( 'tags_input' === $key ) { |
|
292 return true; |
|
293 } |
290 |
294 |
291 return metadata_exists( 'post', $this->ID, $key ); |
295 return metadata_exists( 'post', $this->ID, $key ); |
292 } |
296 } |
293 |
297 |
294 /** |
298 /** |
298 * |
302 * |
299 * @param string $key Key to get. |
303 * @param string $key Key to get. |
300 * @return mixed |
304 * @return mixed |
301 */ |
305 */ |
302 public function __get( $key ) { |
306 public function __get( $key ) { |
303 if ( 'page_template' == $key && $this->__isset( $key ) ) { |
307 if ( 'page_template' === $key && $this->__isset( $key ) ) { |
304 return get_post_meta( $this->ID, '_wp_page_template', true ); |
308 return get_post_meta( $this->ID, '_wp_page_template', true ); |
305 } |
309 } |
306 |
310 |
307 if ( 'post_category' == $key ) { |
311 if ( 'post_category' === $key ) { |
308 if ( is_object_in_taxonomy( $this->post_type, 'category' ) ) |
312 if ( is_object_in_taxonomy( $this->post_type, 'category' ) ) { |
309 $terms = get_the_terms( $this, 'category' ); |
313 $terms = get_the_terms( $this, 'category' ); |
310 |
314 } |
311 if ( empty( $terms ) ) |
315 |
|
316 if ( empty( $terms ) ) { |
312 return array(); |
317 return array(); |
|
318 } |
313 |
319 |
314 return wp_list_pluck( $terms, 'term_id' ); |
320 return wp_list_pluck( $terms, 'term_id' ); |
315 } |
321 } |
316 |
322 |
317 if ( 'tags_input' == $key ) { |
323 if ( 'tags_input' === $key ) { |
318 if ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) ) |
324 if ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) ) { |
319 $terms = get_the_terms( $this, 'post_tag' ); |
325 $terms = get_the_terms( $this, 'post_tag' ); |
320 |
326 } |
321 if ( empty( $terms ) ) |
327 |
|
328 if ( empty( $terms ) ) { |
322 return array(); |
329 return array(); |
|
330 } |
323 |
331 |
324 return wp_list_pluck( $terms, 'name' ); |
332 return wp_list_pluck( $terms, 'name' ); |
325 } |
333 } |
326 |
334 |
327 // Rest of the values need filtering. |
335 // Rest of the values need filtering. |
328 if ( 'ancestors' == $key ) |
336 if ( 'ancestors' === $key ) { |
329 $value = get_post_ancestors( $this ); |
337 $value = get_post_ancestors( $this ); |
330 else |
338 } else { |
331 $value = get_post_meta( $this->ID, $key, true ); |
339 $value = get_post_meta( $this->ID, $key, true ); |
332 |
340 } |
333 if ( $this->filter ) |
341 |
|
342 if ( $this->filter ) { |
334 $value = sanitize_post_field( $key, $value, $this->ID, $this->filter ); |
343 $value = sanitize_post_field( $key, $value, $this->ID, $this->filter ); |
|
344 } |
335 |
345 |
336 return $value; |
346 return $value; |
337 } |
347 } |
338 |
348 |
339 /** |
349 /** |
340 * {@Missing Summary} |
350 * {@Missing Summary} |
341 * |
351 * |
342 * @since 3.5.0 |
352 * @since 3.5.0 |
343 * |
353 * |
344 * @param string $filter Filter. |
354 * @param string $filter Filter. |
345 * @return self|array|bool|object|WP_Post |
355 * @return array|bool|object|WP_Post |
346 */ |
356 */ |
347 public function filter( $filter ) { |
357 public function filter( $filter ) { |
348 if ( $this->filter == $filter ) |
358 if ( $this->filter === $filter ) { |
349 return $this; |
359 return $this; |
350 |
360 } |
351 if ( $filter == 'raw' ) |
361 |
|
362 if ( 'raw' === $filter ) { |
352 return self::get_instance( $this->ID ); |
363 return self::get_instance( $this->ID ); |
|
364 } |
353 |
365 |
354 return sanitize_post( $this, $filter ); |
366 return sanitize_post( $this, $filter ); |
355 } |
367 } |
356 |
368 |
357 /** |
369 /** |