| 279 | } |
| 280 | foreach( get_all_post_type_supports( $this->post_type ) as $supports ) { |
| 281 | if ( ! $instance = apply_filters( 'wp_post_supports_instance', false, $supports, $this ) ) { |
| 282 | continue; |
| 283 | } |
| 284 | /** |
| 285 | * Allow plugins to add contained instances they |
| 286 | * can delegate to in the `wp_post__*` hooks. |
| 287 | */ |
| 288 | $this->supports[ $supports ] = $instance; |
| 289 | }; |
| 290 | do_action( 'wp_post__construct', $this, $post ); |
285 | | if ( 'post_category' == $key ) |
286 | | return true; |
| 310 | if ( preg_match( '#^(ancestors|page_template|post_category|tags_input)$#', $key ) ) { |
| 311 | break; |
| 312 | } |
| 313 | |
| 314 | $isset = metadata_exists( 'post', $this->ID, $key ); |
| 315 | |
| 316 | } while ( false ); |
| 317 | |
| 318 | return apply_filters( 'wp_post__isset', $isset, $key, $this ); |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Caller. |
| 323 | * |
| 324 | * @param string $method Method to call |
| 325 | * @param array $args Parameters |
| 326 | * @return mixed |
| 327 | */ |
| 328 | public function __call( $method, $args = array() ) { |
| 329 | return apply_filters( 'wp_post__call', $method, $args, $this ); |
| 330 | } |
303 | | if ( 'page_template' == $key && $this->__isset( $key ) ) { |
304 | | return get_post_meta( $this->ID, '_wp_page_template', true ); |
305 | | } |
306 | | |
307 | | if ( 'post_category' == $key ) { |
308 | | if ( is_object_in_taxonomy( $this->post_type, 'category' ) ) |
309 | | $terms = get_the_terms( $this, 'category' ); |
310 | | |
311 | | if ( empty( $terms ) ) |
312 | | return array(); |
313 | | |
314 | | return wp_list_pluck( $terms, 'term_id' ); |
315 | | } |
316 | | |
317 | | if ( 'tags_input' == $key ) { |
318 | | if ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) ) |
319 | | $terms = get_the_terms( $this, 'post_tag' ); |
320 | | |
321 | | if ( empty( $terms ) ) |
322 | | return array(); |
323 | | |
324 | | return wp_list_pluck( $terms, 'name' ); |
325 | | } |
| 352 | do { |
327 | | // Rest of the values need filtering. |
328 | | if ( 'ancestors' == $key ) |
329 | | $value = get_post_ancestors( $this ); |
330 | | else |
331 | | $value = get_post_meta( $this->ID, $key, true ); |
| 354 | if ( ! is_null( $value = apply_filters( 'pre_wp_post__get', null, $key, $this ) ) ) { |
| 355 | break; |
| 356 | } |
| 357 | |
| 358 | if ( 'page_template' == $key && $this->__isset( $key ) ) { |
| 359 | $value = get_post_meta( $this->ID, '_wp_page_template', true ); |
| 360 | break; |
| 361 | } |
| 362 | |
| 363 | if ( 'post_category' == $key ) { |
| 364 | if ( is_object_in_taxonomy( $this->post_type, 'category' ) ) { |
| 365 | $terms = get_the_terms( $this, 'category' ); |
| 366 | } |
| 367 | |
| 368 | if ( empty( $terms ) ) { |
| 369 | $value = array(); |
| 370 | break; |
| 371 | } |
| 372 | |
| 373 | $value = wp_list_pluck( $terms, 'term_id' ); |
| 374 | break; |
| 375 | } |
| 376 | |
| 377 | if ( 'tags_input' == $key ) { |
| 378 | if ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) ) { |
| 379 | $terms = get_the_terms( $this, 'post_tag' ); |
| 380 | } |
| 381 | |
| 382 | if ( empty( $terms ) ) { |
| 383 | $value = array(); |
| 384 | break; |
| 385 | } |
| 386 | |
| 387 | $value = wp_list_pluck( $terms, 'name' ); |
| 388 | break; |
| 389 | } |
| 390 | |
| 391 | // Rest of the values need filtering. |
| 392 | if ( 'ancestors' == $key ) { |
| 393 | $value = get_post_ancestors( $this ); |
| 394 | } else { |
| 395 | $value = get_post_meta( $this->ID, $key, true ); |
| 396 | } |
| 397 | |
| 398 | if ( $this->filter ) { |
| 399 | $value = sanitize_post_field( $key, $value, $this->ID, $this->filter ); |
| 400 | } |