Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-inclu...
File: post.php
* from 'draft' – or some other status – to 'publish'. However, if a post is already
[5500] Fix | Delete
* published and is simply being updated, the "old" and "new" statuses may both be 'publish'
[5501] Fix | Delete
* before and after the transition.
[5502] Fix | Delete
*
[5503] Fix | Delete
* @since 2.3.0
[5504] Fix | Delete
*
[5505] Fix | Delete
* @param string $new_status Transition to this post status.
[5506] Fix | Delete
* @param string $old_status Previous post status.
[5507] Fix | Delete
* @param WP_Post $post Post data.
[5508] Fix | Delete
*/
[5509] Fix | Delete
function wp_transition_post_status( $new_status, $old_status, $post ) {
[5510] Fix | Delete
/**
[5511] Fix | Delete
* Fires when a post is transitioned from one status to another.
[5512] Fix | Delete
*
[5513] Fix | Delete
* @since 2.3.0
[5514] Fix | Delete
*
[5515] Fix | Delete
* @param string $new_status New post status.
[5516] Fix | Delete
* @param string $old_status Old post status.
[5517] Fix | Delete
* @param WP_Post $post Post object.
[5518] Fix | Delete
*/
[5519] Fix | Delete
do_action( 'transition_post_status', $new_status, $old_status, $post );
[5520] Fix | Delete
[5521] Fix | Delete
/**
[5522] Fix | Delete
* Fires when a post is transitioned from one status to another.
[5523] Fix | Delete
*
[5524] Fix | Delete
* The dynamic portions of the hook name, `$new_status` and `$old_status`,
[5525] Fix | Delete
* refer to the old and new post statuses, respectively.
[5526] Fix | Delete
*
[5527] Fix | Delete
* Possible hook names include:
[5528] Fix | Delete
*
[5529] Fix | Delete
* - `draft_to_publish`
[5530] Fix | Delete
* - `publish_to_trash`
[5531] Fix | Delete
* - `pending_to_draft`
[5532] Fix | Delete
*
[5533] Fix | Delete
* @since 2.3.0
[5534] Fix | Delete
*
[5535] Fix | Delete
* @param WP_Post $post Post object.
[5536] Fix | Delete
*/
[5537] Fix | Delete
do_action( "{$old_status}_to_{$new_status}", $post );
[5538] Fix | Delete
[5539] Fix | Delete
/**
[5540] Fix | Delete
* Fires when a post is transitioned from one status to another.
[5541] Fix | Delete
*
[5542] Fix | Delete
* The dynamic portions of the hook name, `$new_status` and `$post->post_type`,
[5543] Fix | Delete
* refer to the new post status and post type, respectively.
[5544] Fix | Delete
*
[5545] Fix | Delete
* Possible hook names include:
[5546] Fix | Delete
*
[5547] Fix | Delete
* - `draft_post`
[5548] Fix | Delete
* - `future_post`
[5549] Fix | Delete
* - `pending_post`
[5550] Fix | Delete
* - `private_post`
[5551] Fix | Delete
* - `publish_post`
[5552] Fix | Delete
* - `trash_post`
[5553] Fix | Delete
* - `draft_page`
[5554] Fix | Delete
* - `future_page`
[5555] Fix | Delete
* - `pending_page`
[5556] Fix | Delete
* - `private_page`
[5557] Fix | Delete
* - `publish_page`
[5558] Fix | Delete
* - `trash_page`
[5559] Fix | Delete
* - `publish_attachment`
[5560] Fix | Delete
* - `trash_attachment`
[5561] Fix | Delete
*
[5562] Fix | Delete
* Please note: When this action is hooked using a particular post status (like
[5563] Fix | Delete
* 'publish', as `publish_{$post->post_type}`), it will fire both when a post is
[5564] Fix | Delete
* first transitioned to that status from something else, as well as upon
[5565] Fix | Delete
* subsequent post updates (old and new status are both the same).
[5566] Fix | Delete
*
[5567] Fix | Delete
* Therefore, if you are looking to only fire a callback when a post is first
[5568] Fix | Delete
* transitioned to a status, use the {@see 'transition_post_status'} hook instead.
[5569] Fix | Delete
*
[5570] Fix | Delete
* @since 2.3.0
[5571] Fix | Delete
* @since 5.9.0 Added `$old_status` parameter.
[5572] Fix | Delete
*
[5573] Fix | Delete
* @param int $post_id Post ID.
[5574] Fix | Delete
* @param WP_Post $post Post object.
[5575] Fix | Delete
* @param string $old_status Old post status.
[5576] Fix | Delete
*/
[5577] Fix | Delete
do_action( "{$new_status}_{$post->post_type}", $post->ID, $post, $old_status );
[5578] Fix | Delete
}
[5579] Fix | Delete
[5580] Fix | Delete
/**
[5581] Fix | Delete
* Fires actions after a post, its terms and meta data has been saved.
[5582] Fix | Delete
*
[5583] Fix | Delete
* @since 5.6.0
[5584] Fix | Delete
*
[5585] Fix | Delete
* @param int|WP_Post $post The post ID or object that has been saved.
[5586] Fix | Delete
* @param bool $update Whether this is an existing post being updated.
[5587] Fix | Delete
* @param null|WP_Post $post_before Null for new posts, the WP_Post object prior
[5588] Fix | Delete
* to the update for updated posts.
[5589] Fix | Delete
*/
[5590] Fix | Delete
function wp_after_insert_post( $post, $update, $post_before ) {
[5591] Fix | Delete
$post = get_post( $post );
[5592] Fix | Delete
[5593] Fix | Delete
if ( ! $post ) {
[5594] Fix | Delete
return;
[5595] Fix | Delete
}
[5596] Fix | Delete
[5597] Fix | Delete
$post_id = $post->ID;
[5598] Fix | Delete
[5599] Fix | Delete
/**
[5600] Fix | Delete
* Fires once a post, its terms and meta data has been saved.
[5601] Fix | Delete
*
[5602] Fix | Delete
* @since 5.6.0
[5603] Fix | Delete
*
[5604] Fix | Delete
* @param int $post_id Post ID.
[5605] Fix | Delete
* @param WP_Post $post Post object.
[5606] Fix | Delete
* @param bool $update Whether this is an existing post being updated.
[5607] Fix | Delete
* @param null|WP_Post $post_before Null for new posts, the WP_Post object prior
[5608] Fix | Delete
* to the update for updated posts.
[5609] Fix | Delete
*/
[5610] Fix | Delete
do_action( 'wp_after_insert_post', $post_id, $post, $update, $post_before );
[5611] Fix | Delete
}
[5612] Fix | Delete
[5613] Fix | Delete
//
[5614] Fix | Delete
// Comment, trackback, and pingback functions.
[5615] Fix | Delete
//
[5616] Fix | Delete
[5617] Fix | Delete
/**
[5618] Fix | Delete
* Adds a URL to those already pinged.
[5619] Fix | Delete
*
[5620] Fix | Delete
* @since 1.5.0
[5621] Fix | Delete
* @since 4.7.0 `$post` can be a WP_Post object.
[5622] Fix | Delete
* @since 4.7.0 `$uri` can be an array of URIs.
[5623] Fix | Delete
*
[5624] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[5625] Fix | Delete
*
[5626] Fix | Delete
* @param int|WP_Post $post Post ID or post object.
[5627] Fix | Delete
* @param string|array $uri Ping URI or array of URIs.
[5628] Fix | Delete
* @return int|false How many rows were updated.
[5629] Fix | Delete
*/
[5630] Fix | Delete
function add_ping( $post, $uri ) {
[5631] Fix | Delete
global $wpdb;
[5632] Fix | Delete
[5633] Fix | Delete
$post = get_post( $post );
[5634] Fix | Delete
[5635] Fix | Delete
if ( ! $post ) {
[5636] Fix | Delete
return false;
[5637] Fix | Delete
}
[5638] Fix | Delete
[5639] Fix | Delete
$pung = trim( $post->pinged );
[5640] Fix | Delete
$pung = preg_split( '/\s/', $pung );
[5641] Fix | Delete
[5642] Fix | Delete
if ( is_array( $uri ) ) {
[5643] Fix | Delete
$pung = array_merge( $pung, $uri );
[5644] Fix | Delete
} else {
[5645] Fix | Delete
$pung[] = $uri;
[5646] Fix | Delete
}
[5647] Fix | Delete
$new = implode( "\n", $pung );
[5648] Fix | Delete
[5649] Fix | Delete
/**
[5650] Fix | Delete
* Filters the new ping URL to add for the given post.
[5651] Fix | Delete
*
[5652] Fix | Delete
* @since 2.0.0
[5653] Fix | Delete
*
[5654] Fix | Delete
* @param string $new New ping URL to add.
[5655] Fix | Delete
*/
[5656] Fix | Delete
$new = apply_filters( 'add_ping', $new );
[5657] Fix | Delete
[5658] Fix | Delete
$return = $wpdb->update( $wpdb->posts, array( 'pinged' => $new ), array( 'ID' => $post->ID ) );
[5659] Fix | Delete
clean_post_cache( $post->ID );
[5660] Fix | Delete
return $return;
[5661] Fix | Delete
}
[5662] Fix | Delete
[5663] Fix | Delete
/**
[5664] Fix | Delete
* Retrieves enclosures already enclosed for a post.
[5665] Fix | Delete
*
[5666] Fix | Delete
* @since 1.5.0
[5667] Fix | Delete
*
[5668] Fix | Delete
* @param int $post_id Post ID.
[5669] Fix | Delete
* @return string[] Array of enclosures for the given post.
[5670] Fix | Delete
*/
[5671] Fix | Delete
function get_enclosed( $post_id ) {
[5672] Fix | Delete
$custom_fields = get_post_custom( $post_id );
[5673] Fix | Delete
$pung = array();
[5674] Fix | Delete
if ( ! is_array( $custom_fields ) ) {
[5675] Fix | Delete
return $pung;
[5676] Fix | Delete
}
[5677] Fix | Delete
[5678] Fix | Delete
foreach ( $custom_fields as $key => $val ) {
[5679] Fix | Delete
if ( 'enclosure' !== $key || ! is_array( $val ) ) {
[5680] Fix | Delete
continue;
[5681] Fix | Delete
}
[5682] Fix | Delete
foreach ( $val as $enc ) {
[5683] Fix | Delete
$enclosure = explode( "\n", $enc );
[5684] Fix | Delete
$pung[] = trim( $enclosure[0] );
[5685] Fix | Delete
}
[5686] Fix | Delete
}
[5687] Fix | Delete
[5688] Fix | Delete
/**
[5689] Fix | Delete
* Filters the list of enclosures already enclosed for the given post.
[5690] Fix | Delete
*
[5691] Fix | Delete
* @since 2.0.0
[5692] Fix | Delete
*
[5693] Fix | Delete
* @param string[] $pung Array of enclosures for the given post.
[5694] Fix | Delete
* @param int $post_id Post ID.
[5695] Fix | Delete
*/
[5696] Fix | Delete
return apply_filters( 'get_enclosed', $pung, $post_id );
[5697] Fix | Delete
}
[5698] Fix | Delete
[5699] Fix | Delete
/**
[5700] Fix | Delete
* Retrieves URLs already pinged for a post.
[5701] Fix | Delete
*
[5702] Fix | Delete
* @since 1.5.0
[5703] Fix | Delete
*
[5704] Fix | Delete
* @since 4.7.0 `$post` can be a WP_Post object.
[5705] Fix | Delete
*
[5706] Fix | Delete
* @param int|WP_Post $post Post ID or object.
[5707] Fix | Delete
* @return string[]|false Array of URLs already pinged for the given post, false if the post is not found.
[5708] Fix | Delete
*/
[5709] Fix | Delete
function get_pung( $post ) {
[5710] Fix | Delete
$post = get_post( $post );
[5711] Fix | Delete
[5712] Fix | Delete
if ( ! $post ) {
[5713] Fix | Delete
return false;
[5714] Fix | Delete
}
[5715] Fix | Delete
[5716] Fix | Delete
$pung = trim( $post->pinged );
[5717] Fix | Delete
$pung = preg_split( '/\s/', $pung );
[5718] Fix | Delete
[5719] Fix | Delete
/**
[5720] Fix | Delete
* Filters the list of already-pinged URLs for the given post.
[5721] Fix | Delete
*
[5722] Fix | Delete
* @since 2.0.0
[5723] Fix | Delete
*
[5724] Fix | Delete
* @param string[] $pung Array of URLs already pinged for the given post.
[5725] Fix | Delete
*/
[5726] Fix | Delete
return apply_filters( 'get_pung', $pung );
[5727] Fix | Delete
}
[5728] Fix | Delete
[5729] Fix | Delete
/**
[5730] Fix | Delete
* Retrieves URLs that need to be pinged.
[5731] Fix | Delete
*
[5732] Fix | Delete
* @since 1.5.0
[5733] Fix | Delete
* @since 4.7.0 `$post` can be a WP_Post object.
[5734] Fix | Delete
*
[5735] Fix | Delete
* @param int|WP_Post $post Post ID or post object.
[5736] Fix | Delete
* @return string[]|false List of URLs yet to ping.
[5737] Fix | Delete
*/
[5738] Fix | Delete
function get_to_ping( $post ) {
[5739] Fix | Delete
$post = get_post( $post );
[5740] Fix | Delete
[5741] Fix | Delete
if ( ! $post ) {
[5742] Fix | Delete
return false;
[5743] Fix | Delete
}
[5744] Fix | Delete
[5745] Fix | Delete
$to_ping = sanitize_trackback_urls( $post->to_ping );
[5746] Fix | Delete
$to_ping = preg_split( '/\s/', $to_ping, -1, PREG_SPLIT_NO_EMPTY );
[5747] Fix | Delete
[5748] Fix | Delete
/**
[5749] Fix | Delete
* Filters the list of URLs yet to ping for the given post.
[5750] Fix | Delete
*
[5751] Fix | Delete
* @since 2.0.0
[5752] Fix | Delete
*
[5753] Fix | Delete
* @param string[] $to_ping List of URLs yet to ping.
[5754] Fix | Delete
*/
[5755] Fix | Delete
return apply_filters( 'get_to_ping', $to_ping );
[5756] Fix | Delete
}
[5757] Fix | Delete
[5758] Fix | Delete
/**
[5759] Fix | Delete
* Does trackbacks for a list of URLs.
[5760] Fix | Delete
*
[5761] Fix | Delete
* @since 1.0.0
[5762] Fix | Delete
*
[5763] Fix | Delete
* @param string $tb_list Comma separated list of URLs.
[5764] Fix | Delete
* @param int $post_id Post ID.
[5765] Fix | Delete
*/
[5766] Fix | Delete
function trackback_url_list( $tb_list, $post_id ) {
[5767] Fix | Delete
if ( ! empty( $tb_list ) ) {
[5768] Fix | Delete
// Get post data.
[5769] Fix | Delete
$postdata = get_post( $post_id, ARRAY_A );
[5770] Fix | Delete
[5771] Fix | Delete
// Form an excerpt.
[5772] Fix | Delete
$excerpt = strip_tags( $postdata['post_excerpt'] ? $postdata['post_excerpt'] : $postdata['post_content'] );
[5773] Fix | Delete
[5774] Fix | Delete
if ( strlen( $excerpt ) > 255 ) {
[5775] Fix | Delete
$excerpt = substr( $excerpt, 0, 252 ) . '…';
[5776] Fix | Delete
}
[5777] Fix | Delete
[5778] Fix | Delete
$trackback_urls = explode( ',', $tb_list );
[5779] Fix | Delete
foreach ( (array) $trackback_urls as $tb_url ) {
[5780] Fix | Delete
$tb_url = trim( $tb_url );
[5781] Fix | Delete
trackback( $tb_url, wp_unslash( $postdata['post_title'] ), $excerpt, $post_id );
[5782] Fix | Delete
}
[5783] Fix | Delete
}
[5784] Fix | Delete
}
[5785] Fix | Delete
[5786] Fix | Delete
//
[5787] Fix | Delete
// Page functions.
[5788] Fix | Delete
//
[5789] Fix | Delete
[5790] Fix | Delete
/**
[5791] Fix | Delete
* Gets a list of page IDs.
[5792] Fix | Delete
*
[5793] Fix | Delete
* @since 2.0.0
[5794] Fix | Delete
*
[5795] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[5796] Fix | Delete
*
[5797] Fix | Delete
* @return string[] List of page IDs as strings.
[5798] Fix | Delete
*/
[5799] Fix | Delete
function get_all_page_ids() {
[5800] Fix | Delete
global $wpdb;
[5801] Fix | Delete
[5802] Fix | Delete
$page_ids = wp_cache_get( 'all_page_ids', 'posts' );
[5803] Fix | Delete
if ( ! is_array( $page_ids ) ) {
[5804] Fix | Delete
$page_ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'page'" );
[5805] Fix | Delete
wp_cache_add( 'all_page_ids', $page_ids, 'posts' );
[5806] Fix | Delete
}
[5807] Fix | Delete
[5808] Fix | Delete
return $page_ids;
[5809] Fix | Delete
}
[5810] Fix | Delete
[5811] Fix | Delete
/**
[5812] Fix | Delete
* Retrieves page data given a page ID or page object.
[5813] Fix | Delete
*
[5814] Fix | Delete
* Use get_post() instead of get_page().
[5815] Fix | Delete
*
[5816] Fix | Delete
* @since 1.5.1
[5817] Fix | Delete
* @deprecated 3.5.0 Use get_post()
[5818] Fix | Delete
*
[5819] Fix | Delete
* @param int|WP_Post $page Page object or page ID. Passed by reference.
[5820] Fix | Delete
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which
[5821] Fix | Delete
* correspond to a WP_Post object, an associative array, or a numeric array,
[5822] Fix | Delete
* respectively. Default OBJECT.
[5823] Fix | Delete
* @param string $filter Optional. How the return value should be filtered. Accepts 'raw',
[5824] Fix | Delete
* 'edit', 'db', 'display'. Default 'raw'.
[5825] Fix | Delete
* @return WP_Post|array|null WP_Post or array on success, null on failure.
[5826] Fix | Delete
*/
[5827] Fix | Delete
function get_page( $page, $output = OBJECT, $filter = 'raw' ) {
[5828] Fix | Delete
return get_post( $page, $output, $filter );
[5829] Fix | Delete
}
[5830] Fix | Delete
[5831] Fix | Delete
/**
[5832] Fix | Delete
* Retrieves a page given its path.
[5833] Fix | Delete
*
[5834] Fix | Delete
* @since 2.1.0
[5835] Fix | Delete
*
[5836] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[5837] Fix | Delete
*
[5838] Fix | Delete
* @param string $page_path Page path.
[5839] Fix | Delete
* @param string $output Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which
[5840] Fix | Delete
* correspond to a WP_Post object, an associative array, or a numeric array,
[5841] Fix | Delete
* respectively. Default OBJECT.
[5842] Fix | Delete
* @param string|array $post_type Optional. Post type or array of post types. Default 'page'.
[5843] Fix | Delete
* @return WP_Post|array|null WP_Post (or array) on success, or null on failure.
[5844] Fix | Delete
*/
[5845] Fix | Delete
function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) {
[5846] Fix | Delete
global $wpdb;
[5847] Fix | Delete
[5848] Fix | Delete
$last_changed = wp_cache_get_last_changed( 'posts' );
[5849] Fix | Delete
[5850] Fix | Delete
$hash = md5( $page_path . serialize( $post_type ) );
[5851] Fix | Delete
$cache_key = "get_page_by_path:$hash:$last_changed";
[5852] Fix | Delete
$cached = wp_cache_get( $cache_key, 'post-queries' );
[5853] Fix | Delete
if ( false !== $cached ) {
[5854] Fix | Delete
// Special case: '0' is a bad `$page_path`.
[5855] Fix | Delete
if ( '0' === $cached || 0 === $cached ) {
[5856] Fix | Delete
return;
[5857] Fix | Delete
} else {
[5858] Fix | Delete
return get_post( $cached, $output );
[5859] Fix | Delete
}
[5860] Fix | Delete
}
[5861] Fix | Delete
[5862] Fix | Delete
$page_path = rawurlencode( urldecode( $page_path ) );
[5863] Fix | Delete
$page_path = str_replace( '%2F', '/', $page_path );
[5864] Fix | Delete
$page_path = str_replace( '%20', ' ', $page_path );
[5865] Fix | Delete
$parts = explode( '/', trim( $page_path, '/' ) );
[5866] Fix | Delete
$parts = array_map( 'sanitize_title_for_query', $parts );
[5867] Fix | Delete
$escaped_parts = esc_sql( $parts );
[5868] Fix | Delete
[5869] Fix | Delete
$in_string = "'" . implode( "','", $escaped_parts ) . "'";
[5870] Fix | Delete
[5871] Fix | Delete
if ( is_array( $post_type ) ) {
[5872] Fix | Delete
$post_types = $post_type;
[5873] Fix | Delete
} else {
[5874] Fix | Delete
$post_types = array( $post_type, 'attachment' );
[5875] Fix | Delete
}
[5876] Fix | Delete
[5877] Fix | Delete
$post_types = esc_sql( $post_types );
[5878] Fix | Delete
$post_type_in_string = "'" . implode( "','", $post_types ) . "'";
[5879] Fix | Delete
$sql = "
[5880] Fix | Delete
SELECT ID, post_name, post_parent, post_type
[5881] Fix | Delete
FROM $wpdb->posts
[5882] Fix | Delete
WHERE post_name IN ($in_string)
[5883] Fix | Delete
AND post_type IN ($post_type_in_string)
[5884] Fix | Delete
";
[5885] Fix | Delete
[5886] Fix | Delete
$pages = $wpdb->get_results( $sql, OBJECT_K );
[5887] Fix | Delete
[5888] Fix | Delete
$revparts = array_reverse( $parts );
[5889] Fix | Delete
[5890] Fix | Delete
$foundid = 0;
[5891] Fix | Delete
foreach ( (array) $pages as $page ) {
[5892] Fix | Delete
if ( $page->post_name == $revparts[0] ) {
[5893] Fix | Delete
$count = 0;
[5894] Fix | Delete
$p = $page;
[5895] Fix | Delete
[5896] Fix | Delete
/*
[5897] Fix | Delete
* Loop through the given path parts from right to left,
[5898] Fix | Delete
* ensuring each matches the post ancestry.
[5899] Fix | Delete
*/
[5900] Fix | Delete
while ( 0 != $p->post_parent && isset( $pages[ $p->post_parent ] ) ) {
[5901] Fix | Delete
++$count;
[5902] Fix | Delete
$parent = $pages[ $p->post_parent ];
[5903] Fix | Delete
if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] ) {
[5904] Fix | Delete
break;
[5905] Fix | Delete
}
[5906] Fix | Delete
$p = $parent;
[5907] Fix | Delete
}
[5908] Fix | Delete
[5909] Fix | Delete
if ( 0 == $p->post_parent && count( $revparts ) === $count + 1 && $p->post_name == $revparts[ $count ] ) {
[5910] Fix | Delete
$foundid = $page->ID;
[5911] Fix | Delete
if ( $page->post_type == $post_type ) {
[5912] Fix | Delete
break;
[5913] Fix | Delete
}
[5914] Fix | Delete
}
[5915] Fix | Delete
}
[5916] Fix | Delete
}
[5917] Fix | Delete
[5918] Fix | Delete
// We cache misses as well as hits.
[5919] Fix | Delete
wp_cache_set( $cache_key, $foundid, 'post-queries' );
[5920] Fix | Delete
[5921] Fix | Delete
if ( $foundid ) {
[5922] Fix | Delete
return get_post( $foundid, $output );
[5923] Fix | Delete
}
[5924] Fix | Delete
[5925] Fix | Delete
return null;
[5926] Fix | Delete
}
[5927] Fix | Delete
[5928] Fix | Delete
/**
[5929] Fix | Delete
* Identifies descendants of a given page ID in a list of page objects.
[5930] Fix | Delete
*
[5931] Fix | Delete
* Descendants are identified from the `$pages` array passed to the function. No database queries are performed.
[5932] Fix | Delete
*
[5933] Fix | Delete
* @since 1.5.1
[5934] Fix | Delete
*
[5935] Fix | Delete
* @param int $page_id Page ID.
[5936] Fix | Delete
* @param WP_Post[] $pages List of page objects from which descendants should be identified.
[5937] Fix | Delete
* @return WP_Post[] List of page children.
[5938] Fix | Delete
*/
[5939] Fix | Delete
function get_page_children( $page_id, $pages ) {
[5940] Fix | Delete
// Build a hash of ID -> children.
[5941] Fix | Delete
$children = array();
[5942] Fix | Delete
foreach ( (array) $pages as $page ) {
[5943] Fix | Delete
$children[ (int) $page->post_parent ][] = $page;
[5944] Fix | Delete
}
[5945] Fix | Delete
[5946] Fix | Delete
$page_list = array();
[5947] Fix | Delete
[5948] Fix | Delete
// Start the search by looking at immediate children.
[5949] Fix | Delete
if ( isset( $children[ $page_id ] ) ) {
[5950] Fix | Delete
// Always start at the end of the stack in order to preserve original `$pages` order.
[5951] Fix | Delete
$to_look = array_reverse( $children[ $page_id ] );
[5952] Fix | Delete
[5953] Fix | Delete
while ( $to_look ) {
[5954] Fix | Delete
$p = array_pop( $to_look );
[5955] Fix | Delete
$page_list[] = $p;
[5956] Fix | Delete
if ( isset( $children[ $p->ID ] ) ) {
[5957] Fix | Delete
foreach ( array_reverse( $children[ $p->ID ] ) as $child ) {
[5958] Fix | Delete
// Append to the `$to_look` stack to descend the tree.
[5959] Fix | Delete
$to_look[] = $child;
[5960] Fix | Delete
}
[5961] Fix | Delete
}
[5962] Fix | Delete
}
[5963] Fix | Delete
}
[5964] Fix | Delete
[5965] Fix | Delete
return $page_list;
[5966] Fix | Delete
}
[5967] Fix | Delete
[5968] Fix | Delete
/**
[5969] Fix | Delete
* Orders the pages with children under parents in a flat list.
[5970] Fix | Delete
*
[5971] Fix | Delete
* It uses auxiliary structure to hold parent-children relationships and
[5972] Fix | Delete
* runs in O(N) complexity
[5973] Fix | Delete
*
[5974] Fix | Delete
* @since 2.0.0
[5975] Fix | Delete
*
[5976] Fix | Delete
* @param WP_Post[] $pages Posts array (passed by reference).
[5977] Fix | Delete
* @param int $page_id Optional. Parent page ID. Default 0.
[5978] Fix | Delete
* @return string[] Array of post names keyed by ID and arranged by hierarchy. Children immediately follow their parents.
[5979] Fix | Delete
*/
[5980] Fix | Delete
function get_page_hierarchy( &$pages, $page_id = 0 ) {
[5981] Fix | Delete
if ( empty( $pages ) ) {
[5982] Fix | Delete
return array();
[5983] Fix | Delete
}
[5984] Fix | Delete
[5985] Fix | Delete
$children = array();
[5986] Fix | Delete
foreach ( (array) $pages as $p ) {
[5987] Fix | Delete
$parent_id = (int) $p->post_parent;
[5988] Fix | Delete
$children[ $parent_id ][] = $p;
[5989] Fix | Delete
}
[5990] Fix | Delete
[5991] Fix | Delete
$result = array();
[5992] Fix | Delete
_page_traverse_name( $page_id, $children, $result );
[5993] Fix | Delete
[5994] Fix | Delete
return $result;
[5995] Fix | Delete
}
[5996] Fix | Delete
[5997] Fix | Delete
/**
[5998] Fix | Delete
* Traverses and return all the nested children post names of a root page.
[5999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function