Edit File by line
/home/barbar84/www/wp-inclu...
File: post.php
* @param string $old_status Previous post status.
[5000] Fix | Delete
* @param WP_Post $post Post data.
[5001] Fix | Delete
*/
[5002] Fix | Delete
function wp_transition_post_status( $new_status, $old_status, $post ) {
[5003] Fix | Delete
/**
[5004] Fix | Delete
* Fires when a post is transitioned from one status to another.
[5005] Fix | Delete
*
[5006] Fix | Delete
* @since 2.3.0
[5007] Fix | Delete
*
[5008] Fix | Delete
* @param string $new_status New post status.
[5009] Fix | Delete
* @param string $old_status Old post status.
[5010] Fix | Delete
* @param WP_Post $post Post object.
[5011] Fix | Delete
*/
[5012] Fix | Delete
do_action( 'transition_post_status', $new_status, $old_status, $post );
[5013] Fix | Delete
[5014] Fix | Delete
/**
[5015] Fix | Delete
* Fires when a post is transitioned from one status to another.
[5016] Fix | Delete
*
[5017] Fix | Delete
* The dynamic portions of the hook name, `$new_status` and `$old_status`,
[5018] Fix | Delete
* refer to the old and new post statuses, respectively.
[5019] Fix | Delete
*
[5020] Fix | Delete
* @since 2.3.0
[5021] Fix | Delete
*
[5022] Fix | Delete
* @param WP_Post $post Post object.
[5023] Fix | Delete
*/
[5024] Fix | Delete
do_action( "{$old_status}_to_{$new_status}", $post );
[5025] Fix | Delete
[5026] Fix | Delete
/**
[5027] Fix | Delete
* Fires when a post is transitioned from one status to another.
[5028] Fix | Delete
*
[5029] Fix | Delete
* The dynamic portions of the hook name, `$new_status` and `$post->post_type`,
[5030] Fix | Delete
* refer to the new post status and post type, respectively.
[5031] Fix | Delete
*
[5032] Fix | Delete
* Please note: When this action is hooked using a particular post status (like
[5033] Fix | Delete
* 'publish', as `publish_{$post->post_type}`), it will fire both when a post is
[5034] Fix | Delete
* first transitioned to that status from something else, as well as upon
[5035] Fix | Delete
* subsequent post updates (old and new status are both the same).
[5036] Fix | Delete
*
[5037] Fix | Delete
* Therefore, if you are looking to only fire a callback when a post is first
[5038] Fix | Delete
* transitioned to a status, use the {@see 'transition_post_status'} hook instead.
[5039] Fix | Delete
*
[5040] Fix | Delete
* @since 2.3.0
[5041] Fix | Delete
*
[5042] Fix | Delete
* @param int $post_id Post ID.
[5043] Fix | Delete
* @param WP_Post $post Post object.
[5044] Fix | Delete
*/
[5045] Fix | Delete
do_action( "{$new_status}_{$post->post_type}", $post->ID, $post );
[5046] Fix | Delete
}
[5047] Fix | Delete
[5048] Fix | Delete
/**
[5049] Fix | Delete
* Fires actions after a post, its terms and meta data has been saved.
[5050] Fix | Delete
*
[5051] Fix | Delete
* @since 5.6.0
[5052] Fix | Delete
*
[5053] Fix | Delete
* @param int|WP_Post $post The post ID or object that has been saved.
[5054] Fix | Delete
* @param bool $update Whether this is an existing post being updated.
[5055] Fix | Delete
* @param null|WP_Post $post_before Null for new posts, the WP_Post object prior
[5056] Fix | Delete
* to the update for updated posts.
[5057] Fix | Delete
*/
[5058] Fix | Delete
function wp_after_insert_post( $post, $update, $post_before ) {
[5059] Fix | Delete
$post = get_post( $post );
[5060] Fix | Delete
if ( ! $post ) {
[5061] Fix | Delete
return;
[5062] Fix | Delete
}
[5063] Fix | Delete
[5064] Fix | Delete
$post_id = $post->ID;
[5065] Fix | Delete
[5066] Fix | Delete
/**
[5067] Fix | Delete
* Fires once a post, its terms and meta data has been saved.
[5068] Fix | Delete
*
[5069] Fix | Delete
* @since 5.6.0
[5070] Fix | Delete
*
[5071] Fix | Delete
* @param int $post_id Post ID.
[5072] Fix | Delete
* @param WP_Post $post Post object.
[5073] Fix | Delete
* @param bool $update Whether this is an existing post being updated.
[5074] Fix | Delete
* @param null|WP_Post $post_before Null for new posts, the WP_Post object prior
[5075] Fix | Delete
* to the update for updated posts.
[5076] Fix | Delete
*/
[5077] Fix | Delete
do_action( 'wp_after_insert_post', $post_id, $post, $update, $post_before );
[5078] Fix | Delete
}
[5079] Fix | Delete
[5080] Fix | Delete
//
[5081] Fix | Delete
// Comment, trackback, and pingback functions.
[5082] Fix | Delete
//
[5083] Fix | Delete
[5084] Fix | Delete
/**
[5085] Fix | Delete
* Add a URL to those already pinged.
[5086] Fix | Delete
*
[5087] Fix | Delete
* @since 1.5.0
[5088] Fix | Delete
* @since 4.7.0 `$post_id` can be a WP_Post object.
[5089] Fix | Delete
* @since 4.7.0 `$uri` can be an array of URIs.
[5090] Fix | Delete
*
[5091] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[5092] Fix | Delete
*
[5093] Fix | Delete
* @param int|WP_Post $post_id Post object or ID.
[5094] Fix | Delete
* @param string|array $uri Ping URI or array of URIs.
[5095] Fix | Delete
* @return int|false How many rows were updated.
[5096] Fix | Delete
*/
[5097] Fix | Delete
function add_ping( $post_id, $uri ) {
[5098] Fix | Delete
global $wpdb;
[5099] Fix | Delete
[5100] Fix | Delete
$post = get_post( $post_id );
[5101] Fix | Delete
[5102] Fix | Delete
if ( ! $post ) {
[5103] Fix | Delete
return false;
[5104] Fix | Delete
}
[5105] Fix | Delete
[5106] Fix | Delete
$pung = trim( $post->pinged );
[5107] Fix | Delete
$pung = preg_split( '/\s/', $pung );
[5108] Fix | Delete
[5109] Fix | Delete
if ( is_array( $uri ) ) {
[5110] Fix | Delete
$pung = array_merge( $pung, $uri );
[5111] Fix | Delete
} else {
[5112] Fix | Delete
$pung[] = $uri;
[5113] Fix | Delete
}
[5114] Fix | Delete
$new = implode( "\n", $pung );
[5115] Fix | Delete
[5116] Fix | Delete
/**
[5117] Fix | Delete
* Filters the new ping URL to add for the given post.
[5118] Fix | Delete
*
[5119] Fix | Delete
* @since 2.0.0
[5120] Fix | Delete
*
[5121] Fix | Delete
* @param string $new New ping URL to add.
[5122] Fix | Delete
*/
[5123] Fix | Delete
$new = apply_filters( 'add_ping', $new );
[5124] Fix | Delete
[5125] Fix | Delete
$return = $wpdb->update( $wpdb->posts, array( 'pinged' => $new ), array( 'ID' => $post->ID ) );
[5126] Fix | Delete
clean_post_cache( $post->ID );
[5127] Fix | Delete
return $return;
[5128] Fix | Delete
}
[5129] Fix | Delete
[5130] Fix | Delete
/**
[5131] Fix | Delete
* Retrieve enclosures already enclosed for a post.
[5132] Fix | Delete
*
[5133] Fix | Delete
* @since 1.5.0
[5134] Fix | Delete
*
[5135] Fix | Delete
* @param int $post_id Post ID.
[5136] Fix | Delete
* @return string[] Array of enclosures for the given post.
[5137] Fix | Delete
*/
[5138] Fix | Delete
function get_enclosed( $post_id ) {
[5139] Fix | Delete
$custom_fields = get_post_custom( $post_id );
[5140] Fix | Delete
$pung = array();
[5141] Fix | Delete
if ( ! is_array( $custom_fields ) ) {
[5142] Fix | Delete
return $pung;
[5143] Fix | Delete
}
[5144] Fix | Delete
[5145] Fix | Delete
foreach ( $custom_fields as $key => $val ) {
[5146] Fix | Delete
if ( 'enclosure' !== $key || ! is_array( $val ) ) {
[5147] Fix | Delete
continue;
[5148] Fix | Delete
}
[5149] Fix | Delete
foreach ( $val as $enc ) {
[5150] Fix | Delete
$enclosure = explode( "\n", $enc );
[5151] Fix | Delete
$pung[] = trim( $enclosure[0] );
[5152] Fix | Delete
}
[5153] Fix | Delete
}
[5154] Fix | Delete
[5155] Fix | Delete
/**
[5156] Fix | Delete
* Filters the list of enclosures already enclosed for the given post.
[5157] Fix | Delete
*
[5158] Fix | Delete
* @since 2.0.0
[5159] Fix | Delete
*
[5160] Fix | Delete
* @param string[] $pung Array of enclosures for the given post.
[5161] Fix | Delete
* @param int $post_id Post ID.
[5162] Fix | Delete
*/
[5163] Fix | Delete
return apply_filters( 'get_enclosed', $pung, $post_id );
[5164] Fix | Delete
}
[5165] Fix | Delete
[5166] Fix | Delete
/**
[5167] Fix | Delete
* Retrieve URLs already pinged for a post.
[5168] Fix | Delete
*
[5169] Fix | Delete
* @since 1.5.0
[5170] Fix | Delete
*
[5171] Fix | Delete
* @since 4.7.0 `$post_id` can be a WP_Post object.
[5172] Fix | Delete
*
[5173] Fix | Delete
* @param int|WP_Post $post_id Post ID or object.
[5174] Fix | Delete
* @return string[]|false Array of URLs already pinged for the given post, false if the post is not found.
[5175] Fix | Delete
*/
[5176] Fix | Delete
function get_pung( $post_id ) {
[5177] Fix | Delete
$post = get_post( $post_id );
[5178] Fix | Delete
[5179] Fix | Delete
if ( ! $post ) {
[5180] Fix | Delete
return false;
[5181] Fix | Delete
}
[5182] Fix | Delete
[5183] Fix | Delete
$pung = trim( $post->pinged );
[5184] Fix | Delete
$pung = preg_split( '/\s/', $pung );
[5185] Fix | Delete
[5186] Fix | Delete
/**
[5187] Fix | Delete
* Filters the list of already-pinged URLs for the given post.
[5188] Fix | Delete
*
[5189] Fix | Delete
* @since 2.0.0
[5190] Fix | Delete
*
[5191] Fix | Delete
* @param string[] $pung Array of URLs already pinged for the given post.
[5192] Fix | Delete
*/
[5193] Fix | Delete
return apply_filters( 'get_pung', $pung );
[5194] Fix | Delete
}
[5195] Fix | Delete
[5196] Fix | Delete
/**
[5197] Fix | Delete
* Retrieve URLs that need to be pinged.
[5198] Fix | Delete
*
[5199] Fix | Delete
* @since 1.5.0
[5200] Fix | Delete
* @since 4.7.0 `$post_id` can be a WP_Post object.
[5201] Fix | Delete
*
[5202] Fix | Delete
* @param int|WP_Post $post_id Post Object or ID
[5203] Fix | Delete
* @return string[]|false List of URLs yet to ping.
[5204] Fix | Delete
*/
[5205] Fix | Delete
function get_to_ping( $post_id ) {
[5206] Fix | Delete
$post = get_post( $post_id );
[5207] Fix | Delete
[5208] Fix | Delete
if ( ! $post ) {
[5209] Fix | Delete
return false;
[5210] Fix | Delete
}
[5211] Fix | Delete
[5212] Fix | Delete
$to_ping = sanitize_trackback_urls( $post->to_ping );
[5213] Fix | Delete
$to_ping = preg_split( '/\s/', $to_ping, -1, PREG_SPLIT_NO_EMPTY );
[5214] Fix | Delete
[5215] Fix | Delete
/**
[5216] Fix | Delete
* Filters the list of URLs yet to ping for the given post.
[5217] Fix | Delete
*
[5218] Fix | Delete
* @since 2.0.0
[5219] Fix | Delete
*
[5220] Fix | Delete
* @param string[] $to_ping List of URLs yet to ping.
[5221] Fix | Delete
*/
[5222] Fix | Delete
return apply_filters( 'get_to_ping', $to_ping );
[5223] Fix | Delete
}
[5224] Fix | Delete
[5225] Fix | Delete
/**
[5226] Fix | Delete
* Do trackbacks for a list of URLs.
[5227] Fix | Delete
*
[5228] Fix | Delete
* @since 1.0.0
[5229] Fix | Delete
*
[5230] Fix | Delete
* @param string $tb_list Comma separated list of URLs.
[5231] Fix | Delete
* @param int $post_id Post ID.
[5232] Fix | Delete
*/
[5233] Fix | Delete
function trackback_url_list( $tb_list, $post_id ) {
[5234] Fix | Delete
if ( ! empty( $tb_list ) ) {
[5235] Fix | Delete
// Get post data.
[5236] Fix | Delete
$postdata = get_post( $post_id, ARRAY_A );
[5237] Fix | Delete
[5238] Fix | Delete
// Form an excerpt.
[5239] Fix | Delete
$excerpt = strip_tags( $postdata['post_excerpt'] ? $postdata['post_excerpt'] : $postdata['post_content'] );
[5240] Fix | Delete
[5241] Fix | Delete
if ( strlen( $excerpt ) > 255 ) {
[5242] Fix | Delete
$excerpt = substr( $excerpt, 0, 252 ) . '…';
[5243] Fix | Delete
}
[5244] Fix | Delete
[5245] Fix | Delete
$trackback_urls = explode( ',', $tb_list );
[5246] Fix | Delete
foreach ( (array) $trackback_urls as $tb_url ) {
[5247] Fix | Delete
$tb_url = trim( $tb_url );
[5248] Fix | Delete
trackback( $tb_url, wp_unslash( $postdata['post_title'] ), $excerpt, $post_id );
[5249] Fix | Delete
}
[5250] Fix | Delete
}
[5251] Fix | Delete
}
[5252] Fix | Delete
[5253] Fix | Delete
//
[5254] Fix | Delete
// Page functions.
[5255] Fix | Delete
//
[5256] Fix | Delete
[5257] Fix | Delete
/**
[5258] Fix | Delete
* Get a list of page IDs.
[5259] Fix | Delete
*
[5260] Fix | Delete
* @since 2.0.0
[5261] Fix | Delete
*
[5262] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[5263] Fix | Delete
*
[5264] Fix | Delete
* @return string[] List of page IDs as strings.
[5265] Fix | Delete
*/
[5266] Fix | Delete
function get_all_page_ids() {
[5267] Fix | Delete
global $wpdb;
[5268] Fix | Delete
[5269] Fix | Delete
$page_ids = wp_cache_get( 'all_page_ids', 'posts' );
[5270] Fix | Delete
if ( ! is_array( $page_ids ) ) {
[5271] Fix | Delete
$page_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'page'" );
[5272] Fix | Delete
wp_cache_add( 'all_page_ids', $page_ids, 'posts' );
[5273] Fix | Delete
}
[5274] Fix | Delete
[5275] Fix | Delete
return $page_ids;
[5276] Fix | Delete
}
[5277] Fix | Delete
[5278] Fix | Delete
/**
[5279] Fix | Delete
* Retrieves page data given a page ID or page object.
[5280] Fix | Delete
*
[5281] Fix | Delete
* Use get_post() instead of get_page().
[5282] Fix | Delete
*
[5283] Fix | Delete
* @since 1.5.1
[5284] Fix | Delete
* @deprecated 3.5.0 Use get_post()
[5285] Fix | Delete
*
[5286] Fix | Delete
* @param int|WP_Post $page Page object or page ID. Passed by reference.
[5287] Fix | Delete
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which
[5288] Fix | Delete
* correspond to a WP_Post object, an associative array, or a numeric array,
[5289] Fix | Delete
* respectively. Default OBJECT.
[5290] Fix | Delete
* @param string $filter Optional. How the return value should be filtered. Accepts 'raw',
[5291] Fix | Delete
* 'edit', 'db', 'display'. Default 'raw'.
[5292] Fix | Delete
* @return WP_Post|array|null WP_Post or array on success, null on failure.
[5293] Fix | Delete
*/
[5294] Fix | Delete
function get_page( $page, $output = OBJECT, $filter = 'raw' ) {
[5295] Fix | Delete
return get_post( $page, $output, $filter );
[5296] Fix | Delete
}
[5297] Fix | Delete
[5298] Fix | Delete
/**
[5299] Fix | Delete
* Retrieves a page given its path.
[5300] Fix | Delete
*
[5301] Fix | Delete
* @since 2.1.0
[5302] Fix | Delete
*
[5303] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[5304] Fix | Delete
*
[5305] Fix | Delete
* @param string $page_path Page path.
[5306] Fix | Delete
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which
[5307] Fix | Delete
* correspond to a WP_Post object, an associative array, or a numeric array,
[5308] Fix | Delete
* respectively. Default OBJECT.
[5309] Fix | Delete
* @param string|array $post_type Optional. Post type or array of post types. Default 'page'.
[5310] Fix | Delete
* @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
[5311] Fix | Delete
*/
[5312] Fix | Delete
function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) {
[5313] Fix | Delete
global $wpdb;
[5314] Fix | Delete
[5315] Fix | Delete
$last_changed = wp_cache_get_last_changed( 'posts' );
[5316] Fix | Delete
[5317] Fix | Delete
$hash = md5( $page_path . serialize( $post_type ) );
[5318] Fix | Delete
$cache_key = "get_page_by_path:$hash:$last_changed";
[5319] Fix | Delete
$cached = wp_cache_get( $cache_key, 'posts' );
[5320] Fix | Delete
if ( false !== $cached ) {
[5321] Fix | Delete
// Special case: '0' is a bad `$page_path`.
[5322] Fix | Delete
if ( '0' === $cached || 0 === $cached ) {
[5323] Fix | Delete
return;
[5324] Fix | Delete
} else {
[5325] Fix | Delete
return get_post( $cached, $output );
[5326] Fix | Delete
}
[5327] Fix | Delete
}
[5328] Fix | Delete
[5329] Fix | Delete
$page_path = rawurlencode( urldecode( $page_path ) );
[5330] Fix | Delete
$page_path = str_replace( '%2F', '/', $page_path );
[5331] Fix | Delete
$page_path = str_replace( '%20', ' ', $page_path );
[5332] Fix | Delete
$parts = explode( '/', trim( $page_path, '/' ) );
[5333] Fix | Delete
$parts = array_map( 'sanitize_title_for_query', $parts );
[5334] Fix | Delete
$escaped_parts = esc_sql( $parts );
[5335] Fix | Delete
[5336] Fix | Delete
$in_string = "'" . implode( "','", $escaped_parts ) . "'";
[5337] Fix | Delete
[5338] Fix | Delete
if ( is_array( $post_type ) ) {
[5339] Fix | Delete
$post_types = $post_type;
[5340] Fix | Delete
} else {
[5341] Fix | Delete
$post_types = array( $post_type, 'attachment' );
[5342] Fix | Delete
}
[5343] Fix | Delete
[5344] Fix | Delete
$post_types = esc_sql( $post_types );
[5345] Fix | Delete
$post_type_in_string = "'" . implode( "','", $post_types ) . "'";
[5346] Fix | Delete
$sql = "
[5347] Fix | Delete
SELECT ID, post_name, post_parent, post_type
[5348] Fix | Delete
FROM $wpdb->posts
[5349] Fix | Delete
WHERE post_name IN ($in_string)
[5350] Fix | Delete
AND post_type IN ($post_type_in_string)
[5351] Fix | Delete
";
[5352] Fix | Delete
[5353] Fix | Delete
$pages = $wpdb->get_results( $sql, OBJECT_K );
[5354] Fix | Delete
[5355] Fix | Delete
$revparts = array_reverse( $parts );
[5356] Fix | Delete
[5357] Fix | Delete
$foundid = 0;
[5358] Fix | Delete
foreach ( (array) $pages as $page ) {
[5359] Fix | Delete
if ( $page->post_name == $revparts[0] ) {
[5360] Fix | Delete
$count = 0;
[5361] Fix | Delete
$p = $page;
[5362] Fix | Delete
[5363] Fix | Delete
/*
[5364] Fix | Delete
* Loop through the given path parts from right to left,
[5365] Fix | Delete
* ensuring each matches the post ancestry.
[5366] Fix | Delete
*/
[5367] Fix | Delete
while ( 0 != $p->post_parent && isset( $pages[ $p->post_parent ] ) ) {
[5368] Fix | Delete
$count++;
[5369] Fix | Delete
$parent = $pages[ $p->post_parent ];
[5370] Fix | Delete
if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] ) {
[5371] Fix | Delete
break;
[5372] Fix | Delete
}
[5373] Fix | Delete
$p = $parent;
[5374] Fix | Delete
}
[5375] Fix | Delete
[5376] Fix | Delete
if ( 0 == $p->post_parent && count( $revparts ) == $count + 1 && $p->post_name == $revparts[ $count ] ) {
[5377] Fix | Delete
$foundid = $page->ID;
[5378] Fix | Delete
if ( $page->post_type == $post_type ) {
[5379] Fix | Delete
break;
[5380] Fix | Delete
}
[5381] Fix | Delete
}
[5382] Fix | Delete
}
[5383] Fix | Delete
}
[5384] Fix | Delete
[5385] Fix | Delete
// We cache misses as well as hits.
[5386] Fix | Delete
wp_cache_set( $cache_key, $foundid, 'posts' );
[5387] Fix | Delete
[5388] Fix | Delete
if ( $foundid ) {
[5389] Fix | Delete
return get_post( $foundid, $output );
[5390] Fix | Delete
}
[5391] Fix | Delete
}
[5392] Fix | Delete
[5393] Fix | Delete
/**
[5394] Fix | Delete
* Retrieve a page given its title.
[5395] Fix | Delete
*
[5396] Fix | Delete
* If more than one post uses the same title, the post with the smallest ID will be returned.
[5397] Fix | Delete
* Be careful: in case of more than one post having the same title, it will check the oldest
[5398] Fix | Delete
* publication date, not the smallest ID.
[5399] Fix | Delete
*
[5400] Fix | Delete
* Because this function uses the MySQL '=' comparison, $page_title will usually be matched
[5401] Fix | Delete
* as case-insensitive with default collation.
[5402] Fix | Delete
*
[5403] Fix | Delete
* @since 2.1.0
[5404] Fix | Delete
* @since 3.0.0 The `$post_type` parameter was added.
[5405] Fix | Delete
*
[5406] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[5407] Fix | Delete
*
[5408] Fix | Delete
* @param string $page_title Page title.
[5409] Fix | Delete
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which
[5410] Fix | Delete
* correspond to a WP_Post object, an associative array, or a numeric array,
[5411] Fix | Delete
* respectively. Default OBJECT.
[5412] Fix | Delete
* @param string|array $post_type Optional. Post type or array of post types. Default 'page'.
[5413] Fix | Delete
* @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
[5414] Fix | Delete
*/
[5415] Fix | Delete
function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) {
[5416] Fix | Delete
global $wpdb;
[5417] Fix | Delete
[5418] Fix | Delete
if ( is_array( $post_type ) ) {
[5419] Fix | Delete
$post_type = esc_sql( $post_type );
[5420] Fix | Delete
$post_type_in_string = "'" . implode( "','", $post_type ) . "'";
[5421] Fix | Delete
$sql = $wpdb->prepare(
[5422] Fix | Delete
"
[5423] Fix | Delete
SELECT ID
[5424] Fix | Delete
FROM $wpdb->posts
[5425] Fix | Delete
WHERE post_title = %s
[5426] Fix | Delete
AND post_type IN ($post_type_in_string)
[5427] Fix | Delete
",
[5428] Fix | Delete
$page_title
[5429] Fix | Delete
);
[5430] Fix | Delete
} else {
[5431] Fix | Delete
$sql = $wpdb->prepare(
[5432] Fix | Delete
"
[5433] Fix | Delete
SELECT ID
[5434] Fix | Delete
FROM $wpdb->posts
[5435] Fix | Delete
WHERE post_title = %s
[5436] Fix | Delete
AND post_type = %s
[5437] Fix | Delete
",
[5438] Fix | Delete
$page_title,
[5439] Fix | Delete
$post_type
[5440] Fix | Delete
);
[5441] Fix | Delete
}
[5442] Fix | Delete
[5443] Fix | Delete
$page = $wpdb->get_var( $sql );
[5444] Fix | Delete
[5445] Fix | Delete
if ( $page ) {
[5446] Fix | Delete
return get_post( $page, $output );
[5447] Fix | Delete
}
[5448] Fix | Delete
}
[5449] Fix | Delete
[5450] Fix | Delete
/**
[5451] Fix | Delete
* Identify descendants of a given page ID in a list of page objects.
[5452] Fix | Delete
*
[5453] Fix | Delete
* Descendants are identified from the `$pages` array passed to the function. No database queries are performed.
[5454] Fix | Delete
*
[5455] Fix | Delete
* @since 1.5.1
[5456] Fix | Delete
*
[5457] Fix | Delete
* @param int $page_id Page ID.
[5458] Fix | Delete
* @param array $pages List of page objects from which descendants should be identified.
[5459] Fix | Delete
* @return array List of page children.
[5460] Fix | Delete
*/
[5461] Fix | Delete
function get_page_children( $page_id, $pages ) {
[5462] Fix | Delete
// Build a hash of ID -> children.
[5463] Fix | Delete
$children = array();
[5464] Fix | Delete
foreach ( (array) $pages as $page ) {
[5465] Fix | Delete
$children[ (int) $page->post_parent ][] = $page;
[5466] Fix | Delete
}
[5467] Fix | Delete
[5468] Fix | Delete
$page_list = array();
[5469] Fix | Delete
[5470] Fix | Delete
// Start the search by looking at immediate children.
[5471] Fix | Delete
if ( isset( $children[ $page_id ] ) ) {
[5472] Fix | Delete
// Always start at the end of the stack in order to preserve original `$pages` order.
[5473] Fix | Delete
$to_look = array_reverse( $children[ $page_id ] );
[5474] Fix | Delete
[5475] Fix | Delete
while ( $to_look ) {
[5476] Fix | Delete
$p = array_pop( $to_look );
[5477] Fix | Delete
$page_list[] = $p;
[5478] Fix | Delete
if ( isset( $children[ $p->ID ] ) ) {
[5479] Fix | Delete
foreach ( array_reverse( $children[ $p->ID ] ) as $child ) {
[5480] Fix | Delete
// Append to the `$to_look` stack to descend the tree.
[5481] Fix | Delete
$to_look[] = $child;
[5482] Fix | Delete
}
[5483] Fix | Delete
}
[5484] Fix | Delete
}
[5485] Fix | Delete
}
[5486] Fix | Delete
[5487] Fix | Delete
return $page_list;
[5488] Fix | Delete
}
[5489] Fix | Delete
[5490] Fix | Delete
/**
[5491] Fix | Delete
* Order the pages with children under parents in a flat list.
[5492] Fix | Delete
*
[5493] Fix | Delete
* It uses auxiliary structure to hold parent-children relationships and
[5494] Fix | Delete
* runs in O(N) complexity
[5495] Fix | Delete
*
[5496] Fix | Delete
* @since 2.0.0
[5497] Fix | Delete
*
[5498] Fix | Delete
* @param WP_Post[] $pages Posts array (passed by reference).
[5499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function