Changeset 33759 for trunk/src/wp-includes/post-functions.php
- Timestamp:
- 08/26/2015 12:39:07 PM (10 years ago)
- File:
-
- 1 copied
-
trunk/src/wp-includes/post-functions.php (copied) (copied from trunk/src/wp-includes/post.php) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post-functions.php
r33758 r33759 455 455 456 456 return $_post; 457 }458 459 /**460 * WordPress Post class.461 *462 * @since 3.5.0463 *464 * @property string $page_template465 *466 * @property-read array $ancestors467 * @property-read int $post_category468 * @property-read string $tag_input469 *470 */471 final class WP_Post {472 473 /**474 * Post ID.475 *476 * @var int477 */478 public $ID;479 480 /**481 * ID of post author.482 *483 * A numeric string, for compatibility reasons.484 *485 * @var string486 */487 public $post_author = 0;488 489 /**490 * The post's local publication time.491 *492 * @var string493 */494 public $post_date = '0000-00-00 00:00:00';495 496 /**497 * The post's GMT publication time.498 *499 * @var string500 */501 public $post_date_gmt = '0000-00-00 00:00:00';502 503 /**504 * The post's content.505 *506 * @var string507 */508 public $post_content = '';509 510 /**511 * The post's title.512 *513 * @var string514 */515 public $post_title = '';516 517 /**518 * The post's excerpt.519 *520 * @var string521 */522 public $post_excerpt = '';523 524 /**525 * The post's status.526 *527 * @var string528 */529 public $post_status = 'publish';530 531 /**532 * Whether comments are allowed.533 *534 * @var string535 */536 public $comment_status = 'open';537 538 /**539 * Whether pings are allowed.540 *541 * @var string542 */543 public $ping_status = 'open';544 545 /**546 * The post's password in plain text.547 *548 * @var string549 */550 public $post_password = '';551 552 /**553 * The post's slug.554 *555 * @var string556 */557 public $post_name = '';558 559 /**560 * URLs queued to be pinged.561 *562 * @var string563 */564 public $to_ping = '';565 566 /**567 * URLs that have been pinged.568 *569 * @var string570 */571 public $pinged = '';572 573 /**574 * The post's local modified time.575 *576 * @var string577 */578 public $post_modified = '0000-00-00 00:00:00';579 580 /**581 * The post's GMT modified time.582 *583 * @var string584 */585 public $post_modified_gmt = '0000-00-00 00:00:00';586 587 /**588 * A utility DB field for post content.589 *590 *591 * @var string592 */593 public $post_content_filtered = '';594 595 /**596 * ID of a post's parent post.597 *598 * @var int599 */600 public $post_parent = 0;601 602 /**603 * The unique identifier for a post, not necessarily a URL, used as the feed GUID.604 *605 * @var string606 */607 public $guid = '';608 609 /**610 * A field used for ordering posts.611 *612 * @var int613 */614 public $menu_order = 0;615 616 /**617 * The post's type, like post or page.618 *619 * @var string620 */621 public $post_type = 'post';622 623 /**624 * An attachment's mime type.625 *626 * @var string627 */628 public $post_mime_type = '';629 630 /**631 * Cached comment count.632 *633 * A numeric string, for compatibility reasons.634 *635 * @var string636 */637 public $comment_count = 0;638 639 /**640 * Stores the post object's sanitization level.641 *642 * Does not correspond to a DB field.643 *644 * @var string645 */646 public $filter;647 648 /**649 * Retrieve WP_Post instance.650 *651 * @static652 * @access public653 *654 * @global wpdb $wpdb655 *656 * @param int $post_id Post ID.657 * @return WP_Post|false Post object, false otherwise.658 */659 public static function get_instance( $post_id ) {660 global $wpdb;661 662 $post_id = (int) $post_id;663 if ( ! $post_id )664 return false;665 666 $_post = wp_cache_get( $post_id, 'posts' );667 668 if ( ! $_post ) {669 $_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id ) );670 671 if ( ! $_post )672 return false;673 674 $_post = sanitize_post( $_post, 'raw' );675 wp_cache_add( $_post->ID, $_post, 'posts' );676 } elseif ( empty( $_post->filter ) ) {677 $_post = sanitize_post( $_post, 'raw' );678 }679 680 return new WP_Post( $_post );681 }682 683 /**684 * Constructor.685 *686 * @param WP_Post|object $post Post object.687 */688 public function __construct( $post ) {689 foreach ( get_object_vars( $post ) as $key => $value )690 $this->$key = $value;691 }692 693 /**694 * Isset-er.695 *696 * @param string $key Property to check if set.697 * @return bool698 */699 public function __isset( $key ) {700 if ( 'ancestors' == $key )701 return true;702 703 if ( 'page_template' == $key )704 return ( 'page' == $this->post_type );705 706 if ( 'post_category' == $key )707 return true;708 709 if ( 'tags_input' == $key )710 return true;711 712 return metadata_exists( 'post', $this->ID, $key );713 }714 715 /**716 * Getter.717 *718 * @param string $key Key to get.719 * @return mixed720 */721 public function __get( $key ) {722 if ( 'page_template' == $key && $this->__isset( $key ) ) {723 return get_post_meta( $this->ID, '_wp_page_template', true );724 }725 726 if ( 'post_category' == $key ) {727 if ( is_object_in_taxonomy( $this->post_type, 'category' ) )728 $terms = get_the_terms( $this, 'category' );729 730 if ( empty( $terms ) )731 return array();732 733 return wp_list_pluck( $terms, 'term_id' );734 }735 736 if ( 'tags_input' == $key ) {737 if ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) )738 $terms = get_the_terms( $this, 'post_tag' );739 740 if ( empty( $terms ) )741 return array();742 743 return wp_list_pluck( $terms, 'name' );744 }745 746 // Rest of the values need filtering.747 if ( 'ancestors' == $key )748 $value = get_post_ancestors( $this );749 else750 $value = get_post_meta( $this->ID, $key, true );751 752 if ( $this->filter )753 $value = sanitize_post_field( $key, $value, $this->ID, $this->filter );754 755 return $value;756 }757 758 /**759 * {@Missing Summary}760 *761 * @param string $filter Filter.762 * @return self|array|bool|object|WP_Post763 */764 public function filter( $filter ) {765 if ( $this->filter == $filter )766 return $this;767 768 if ( $filter == 'raw' )769 return self::get_instance( $this->ID );770 771 return sanitize_post( $this, $filter );772 }773 774 /**775 * Convert object to array.776 *777 * @return array Object as array.778 */779 public function to_array() {780 $post = get_object_vars( $this );781 782 foreach ( array( 'ancestors', 'page_template', 'post_category', 'tags_input' ) as $key ) {783 if ( $this->__isset( $key ) )784 $post[ $key ] = $this->__get( $key );785 }786 787 return $post;788 }789 457 } 790 458
Note: See TracChangeset
for help on using the changeset viewer.