431 | | if ( $post instanceof WP_Post ) { |
432 | | $_post = $post; |
433 | | } elseif ( is_object( $post ) ) { |
434 | | if ( empty( $post->filter ) ) { |
435 | | $_post = sanitize_post( $post, 'raw' ); |
436 | | $_post = new WP_Post( $_post ); |
437 | | } elseif ( 'raw' == $post->filter ) { |
438 | | $_post = new WP_Post( $post ); |
439 | | } else { |
440 | | $_post = WP_Post::get_instance( $post->ID ); |
441 | | } |
442 | | } else { |
443 | | $_post = WP_Post::get_instance( $post ); |
444 | | } |
| 433 | /** |
| 434 | * Filter that allows a custom object to be provided for post when appropriate. |
| 435 | * |
| 436 | * Allows a developer to substitute an object that contains a WP_Post or that simulates a WP_Post. |
| 437 | * |
| 438 | * @since 4.4.0 |
| 439 | * |
| 440 | * @param null null Default value for filter to return. If null, filter is effectively ignored. |
| 441 | * @param WP_Post $post Post object |
| 442 | * @param string $output Format of data to return, potentially 'OBJECT', 'ARRAY_A' or 'ARRAY_N'. |
| 443 | * @param string $filter Type of filter to apply, potentially 'raw', 'edit', 'db' or 'display'. |
| 444 | * @return null|WP_Post|object |
| 445 | */ |
| 446 | $_post = apply_filters( 'do_get_post', null, $post, $output, $filter ); |
| 447 | |
| 448 | if ( is_null( $_post ) ) { |
| 449 | |
| 450 | if ( $post instanceof WP_Post ) { |
| 451 | $_post = $post; |
| 452 | } elseif ( is_object( $post ) ) { |
| 453 | if ( empty( $post->filter ) ) { |
| 454 | $_post = sanitize_post( $post, 'raw' ); |
| 455 | $_post = new WP_Post( $_post ); |
| 456 | } elseif ( 'raw' == $post->filter ) { |
| 457 | $_post = new WP_Post( $post ); |
| 458 | } else { |
| 459 | $_post = WP_Post::get_instance( $post->ID ); |
| 460 | } |
| 461 | } else { |
| 462 | $_post = WP_Post::get_instance( $post ); |
| 463 | } |