Edit File by line
/home/barbar84/www/wp-inclu...
File: class-wp-post.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Post API: WP_Post class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Post
[5] Fix | Delete
* @since 4.4.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Core class used to implement the WP_Post object.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 3.5.0
[12] Fix | Delete
*
[13] Fix | Delete
* @property string $page_template
[14] Fix | Delete
*
[15] Fix | Delete
* @property-read int[] $ancestors
[16] Fix | Delete
* @property-read int $post_category
[17] Fix | Delete
* @property-read string $tag_input
[18] Fix | Delete
*/
[19] Fix | Delete
final class WP_Post {
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* Post ID.
[23] Fix | Delete
*
[24] Fix | Delete
* @since 3.5.0
[25] Fix | Delete
* @var int
[26] Fix | Delete
*/
[27] Fix | Delete
public $ID;
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* ID of post author.
[31] Fix | Delete
*
[32] Fix | Delete
* A numeric string, for compatibility reasons.
[33] Fix | Delete
*
[34] Fix | Delete
* @since 3.5.0
[35] Fix | Delete
* @var string
[36] Fix | Delete
*/
[37] Fix | Delete
public $post_author = 0;
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* The post's local publication time.
[41] Fix | Delete
*
[42] Fix | Delete
* @since 3.5.0
[43] Fix | Delete
* @var string
[44] Fix | Delete
*/
[45] Fix | Delete
public $post_date = '0000-00-00 00:00:00';
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* The post's GMT publication time.
[49] Fix | Delete
*
[50] Fix | Delete
* @since 3.5.0
[51] Fix | Delete
* @var string
[52] Fix | Delete
*/
[53] Fix | Delete
public $post_date_gmt = '0000-00-00 00:00:00';
[54] Fix | Delete
[55] Fix | Delete
/**
[56] Fix | Delete
* The post's content.
[57] Fix | Delete
*
[58] Fix | Delete
* @since 3.5.0
[59] Fix | Delete
* @var string
[60] Fix | Delete
*/
[61] Fix | Delete
public $post_content = '';
[62] Fix | Delete
[63] Fix | Delete
/**
[64] Fix | Delete
* The post's title.
[65] Fix | Delete
*
[66] Fix | Delete
* @since 3.5.0
[67] Fix | Delete
* @var string
[68] Fix | Delete
*/
[69] Fix | Delete
public $post_title = '';
[70] Fix | Delete
[71] Fix | Delete
/**
[72] Fix | Delete
* The post's excerpt.
[73] Fix | Delete
*
[74] Fix | Delete
* @since 3.5.0
[75] Fix | Delete
* @var string
[76] Fix | Delete
*/
[77] Fix | Delete
public $post_excerpt = '';
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* The post's status.
[81] Fix | Delete
*
[82] Fix | Delete
* @since 3.5.0
[83] Fix | Delete
* @var string
[84] Fix | Delete
*/
[85] Fix | Delete
public $post_status = 'publish';
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Whether comments are allowed.
[89] Fix | Delete
*
[90] Fix | Delete
* @since 3.5.0
[91] Fix | Delete
* @var string
[92] Fix | Delete
*/
[93] Fix | Delete
public $comment_status = 'open';
[94] Fix | Delete
[95] Fix | Delete
/**
[96] Fix | Delete
* Whether pings are allowed.
[97] Fix | Delete
*
[98] Fix | Delete
* @since 3.5.0
[99] Fix | Delete
* @var string
[100] Fix | Delete
*/
[101] Fix | Delete
public $ping_status = 'open';
[102] Fix | Delete
[103] Fix | Delete
/**
[104] Fix | Delete
* The post's password in plain text.
[105] Fix | Delete
*
[106] Fix | Delete
* @since 3.5.0
[107] Fix | Delete
* @var string
[108] Fix | Delete
*/
[109] Fix | Delete
public $post_password = '';
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* The post's slug.
[113] Fix | Delete
*
[114] Fix | Delete
* @since 3.5.0
[115] Fix | Delete
* @var string
[116] Fix | Delete
*/
[117] Fix | Delete
public $post_name = '';
[118] Fix | Delete
[119] Fix | Delete
/**
[120] Fix | Delete
* URLs queued to be pinged.
[121] Fix | Delete
*
[122] Fix | Delete
* @since 3.5.0
[123] Fix | Delete
* @var string
[124] Fix | Delete
*/
[125] Fix | Delete
public $to_ping = '';
[126] Fix | Delete
[127] Fix | Delete
/**
[128] Fix | Delete
* URLs that have been pinged.
[129] Fix | Delete
*
[130] Fix | Delete
* @since 3.5.0
[131] Fix | Delete
* @var string
[132] Fix | Delete
*/
[133] Fix | Delete
public $pinged = '';
[134] Fix | Delete
[135] Fix | Delete
/**
[136] Fix | Delete
* The post's local modified time.
[137] Fix | Delete
*
[138] Fix | Delete
* @since 3.5.0
[139] Fix | Delete
* @var string
[140] Fix | Delete
*/
[141] Fix | Delete
public $post_modified = '0000-00-00 00:00:00';
[142] Fix | Delete
[143] Fix | Delete
/**
[144] Fix | Delete
* The post's GMT modified time.
[145] Fix | Delete
*
[146] Fix | Delete
* @since 3.5.0
[147] Fix | Delete
* @var string
[148] Fix | Delete
*/
[149] Fix | Delete
public $post_modified_gmt = '0000-00-00 00:00:00';
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* A utility DB field for post content.
[153] Fix | Delete
*
[154] Fix | Delete
* @since 3.5.0
[155] Fix | Delete
* @var string
[156] Fix | Delete
*/
[157] Fix | Delete
public $post_content_filtered = '';
[158] Fix | Delete
[159] Fix | Delete
/**
[160] Fix | Delete
* ID of a post's parent post.
[161] Fix | Delete
*
[162] Fix | Delete
* @since 3.5.0
[163] Fix | Delete
* @var int
[164] Fix | Delete
*/
[165] Fix | Delete
public $post_parent = 0;
[166] Fix | Delete
[167] Fix | Delete
/**
[168] Fix | Delete
* The unique identifier for a post, not necessarily a URL, used as the feed GUID.
[169] Fix | Delete
*
[170] Fix | Delete
* @since 3.5.0
[171] Fix | Delete
* @var string
[172] Fix | Delete
*/
[173] Fix | Delete
public $guid = '';
[174] Fix | Delete
[175] Fix | Delete
/**
[176] Fix | Delete
* A field used for ordering posts.
[177] Fix | Delete
*
[178] Fix | Delete
* @since 3.5.0
[179] Fix | Delete
* @var int
[180] Fix | Delete
*/
[181] Fix | Delete
public $menu_order = 0;
[182] Fix | Delete
[183] Fix | Delete
/**
[184] Fix | Delete
* The post's type, like post or page.
[185] Fix | Delete
*
[186] Fix | Delete
* @since 3.5.0
[187] Fix | Delete
* @var string
[188] Fix | Delete
*/
[189] Fix | Delete
public $post_type = 'post';
[190] Fix | Delete
[191] Fix | Delete
/**
[192] Fix | Delete
* An attachment's mime type.
[193] Fix | Delete
*
[194] Fix | Delete
* @since 3.5.0
[195] Fix | Delete
* @var string
[196] Fix | Delete
*/
[197] Fix | Delete
public $post_mime_type = '';
[198] Fix | Delete
[199] Fix | Delete
/**
[200] Fix | Delete
* Cached comment count.
[201] Fix | Delete
*
[202] Fix | Delete
* A numeric string, for compatibility reasons.
[203] Fix | Delete
*
[204] Fix | Delete
* @since 3.5.0
[205] Fix | Delete
* @var string
[206] Fix | Delete
*/
[207] Fix | Delete
public $comment_count = 0;
[208] Fix | Delete
[209] Fix | Delete
/**
[210] Fix | Delete
* Stores the post object's sanitization level.
[211] Fix | Delete
*
[212] Fix | Delete
* Does not correspond to a DB field.
[213] Fix | Delete
*
[214] Fix | Delete
* @since 3.5.0
[215] Fix | Delete
* @var string
[216] Fix | Delete
*/
[217] Fix | Delete
public $filter;
[218] Fix | Delete
[219] Fix | Delete
/**
[220] Fix | Delete
* Retrieve WP_Post instance.
[221] Fix | Delete
*
[222] Fix | Delete
* @since 3.5.0
[223] Fix | Delete
*
[224] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[225] Fix | Delete
*
[226] Fix | Delete
* @param int $post_id Post ID.
[227] Fix | Delete
* @return WP_Post|false Post object, false otherwise.
[228] Fix | Delete
*/
[229] Fix | Delete
public static function get_instance( $post_id ) {
[230] Fix | Delete
global $wpdb;
[231] Fix | Delete
[232] Fix | Delete
$post_id = (int) $post_id;
[233] Fix | Delete
if ( ! $post_id ) {
[234] Fix | Delete
return false;
[235] Fix | Delete
}
[236] Fix | Delete
[237] Fix | Delete
$_post = wp_cache_get( $post_id, 'posts' );
[238] Fix | Delete
[239] Fix | Delete
if ( ! $_post ) {
[240] Fix | Delete
$_post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id ) );
[241] Fix | Delete
[242] Fix | Delete
if ( ! $_post ) {
[243] Fix | Delete
return false;
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
$_post = sanitize_post( $_post, 'raw' );
[247] Fix | Delete
wp_cache_add( $_post->ID, $_post, 'posts' );
[248] Fix | Delete
} elseif ( empty( $_post->filter ) ) {
[249] Fix | Delete
$_post = sanitize_post( $_post, 'raw' );
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
return new WP_Post( $_post );
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
/**
[256] Fix | Delete
* Constructor.
[257] Fix | Delete
*
[258] Fix | Delete
* @since 3.5.0
[259] Fix | Delete
*
[260] Fix | Delete
* @param WP_Post|object $post Post object.
[261] Fix | Delete
*/
[262] Fix | Delete
public function __construct( $post ) {
[263] Fix | Delete
foreach ( get_object_vars( $post ) as $key => $value ) {
[264] Fix | Delete
$this->$key = $value;
[265] Fix | Delete
}
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
/**
[269] Fix | Delete
* Isset-er.
[270] Fix | Delete
*
[271] Fix | Delete
* @since 3.5.0
[272] Fix | Delete
*
[273] Fix | Delete
* @param string $key Property to check if set.
[274] Fix | Delete
* @return bool
[275] Fix | Delete
*/
[276] Fix | Delete
public function __isset( $key ) {
[277] Fix | Delete
if ( 'ancestors' === $key ) {
[278] Fix | Delete
return true;
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
if ( 'page_template' === $key ) {
[282] Fix | Delete
return true;
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
if ( 'post_category' === $key ) {
[286] Fix | Delete
return true;
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
if ( 'tags_input' === $key ) {
[290] Fix | Delete
return true;
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
return metadata_exists( 'post', $this->ID, $key );
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
/**
[297] Fix | Delete
* Getter.
[298] Fix | Delete
*
[299] Fix | Delete
* @since 3.5.0
[300] Fix | Delete
*
[301] Fix | Delete
* @param string $key Key to get.
[302] Fix | Delete
* @return mixed
[303] Fix | Delete
*/
[304] Fix | Delete
public function __get( $key ) {
[305] Fix | Delete
if ( 'page_template' === $key && $this->__isset( $key ) ) {
[306] Fix | Delete
return get_post_meta( $this->ID, '_wp_page_template', true );
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
if ( 'post_category' === $key ) {
[310] Fix | Delete
if ( is_object_in_taxonomy( $this->post_type, 'category' ) ) {
[311] Fix | Delete
$terms = get_the_terms( $this, 'category' );
[312] Fix | Delete
}
[313] Fix | Delete
[314] Fix | Delete
if ( empty( $terms ) ) {
[315] Fix | Delete
return array();
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
return wp_list_pluck( $terms, 'term_id' );
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
if ( 'tags_input' === $key ) {
[322] Fix | Delete
if ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) ) {
[323] Fix | Delete
$terms = get_the_terms( $this, 'post_tag' );
[324] Fix | Delete
}
[325] Fix | Delete
[326] Fix | Delete
if ( empty( $terms ) ) {
[327] Fix | Delete
return array();
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
return wp_list_pluck( $terms, 'name' );
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
// Rest of the values need filtering.
[334] Fix | Delete
if ( 'ancestors' === $key ) {
[335] Fix | Delete
$value = get_post_ancestors( $this );
[336] Fix | Delete
} else {
[337] Fix | Delete
$value = get_post_meta( $this->ID, $key, true );
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
if ( $this->filter ) {
[341] Fix | Delete
$value = sanitize_post_field( $key, $value, $this->ID, $this->filter );
[342] Fix | Delete
}
[343] Fix | Delete
[344] Fix | Delete
return $value;
[345] Fix | Delete
}
[346] Fix | Delete
[347] Fix | Delete
/**
[348] Fix | Delete
* {@Missing Summary}
[349] Fix | Delete
*
[350] Fix | Delete
* @since 3.5.0
[351] Fix | Delete
*
[352] Fix | Delete
* @param string $filter Filter.
[353] Fix | Delete
* @return WP_Post
[354] Fix | Delete
*/
[355] Fix | Delete
public function filter( $filter ) {
[356] Fix | Delete
if ( $this->filter === $filter ) {
[357] Fix | Delete
return $this;
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
if ( 'raw' === $filter ) {
[361] Fix | Delete
return self::get_instance( $this->ID );
[362] Fix | Delete
}
[363] Fix | Delete
[364] Fix | Delete
return sanitize_post( $this, $filter );
[365] Fix | Delete
}
[366] Fix | Delete
[367] Fix | Delete
/**
[368] Fix | Delete
* Convert object to array.
[369] Fix | Delete
*
[370] Fix | Delete
* @since 3.5.0
[371] Fix | Delete
*
[372] Fix | Delete
* @return array Object as array.
[373] Fix | Delete
*/
[374] Fix | Delete
public function to_array() {
[375] Fix | Delete
$post = get_object_vars( $this );
[376] Fix | Delete
[377] Fix | Delete
foreach ( array( 'ancestors', 'page_template', 'post_category', 'tags_input' ) as $key ) {
[378] Fix | Delete
if ( $this->__isset( $key ) ) {
[379] Fix | Delete
$post[ $key ] = $this->__get( $key );
[380] Fix | Delete
}
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
return $post;
[384] Fix | Delete
}
[385] Fix | Delete
}
[386] Fix | Delete
[387] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function