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
}
[7500] Fix | Delete
[7501] Fix | Delete
/**
[7502] Fix | Delete
* Updates post author user caches for a list of post objects.
[7503] Fix | Delete
*
[7504] Fix | Delete
* @since 6.1.0
[7505] Fix | Delete
*
[7506] Fix | Delete
* @param WP_Post[] $posts Array of post objects.
[7507] Fix | Delete
*/
[7508] Fix | Delete
function update_post_author_caches( $posts ) {
[7509] Fix | Delete
/*
[7510] Fix | Delete
* cache_users() is a pluggable function so is not available prior
[7511] Fix | Delete
* to the `plugins_loaded` hook firing. This is to ensure against
[7512] Fix | Delete
* fatal errors when the function is not available.
[7513] Fix | Delete
*/
[7514] Fix | Delete
if ( ! function_exists( 'cache_users' ) ) {
[7515] Fix | Delete
return;
[7516] Fix | Delete
}
[7517] Fix | Delete
[7518] Fix | Delete
$author_ids = wp_list_pluck( $posts, 'post_author' );
[7519] Fix | Delete
$author_ids = array_map( 'absint', $author_ids );
[7520] Fix | Delete
$author_ids = array_unique( array_filter( $author_ids ) );
[7521] Fix | Delete
[7522] Fix | Delete
cache_users( $author_ids );
[7523] Fix | Delete
}
[7524] Fix | Delete
[7525] Fix | Delete
/**
[7526] Fix | Delete
* Updates parent post caches for a list of post objects.
[7527] Fix | Delete
*
[7528] Fix | Delete
* @since 6.1.0
[7529] Fix | Delete
*
[7530] Fix | Delete
* @param WP_Post[] $posts Array of post objects.
[7531] Fix | Delete
*/
[7532] Fix | Delete
function update_post_parent_caches( $posts ) {
[7533] Fix | Delete
$parent_ids = wp_list_pluck( $posts, 'post_parent' );
[7534] Fix | Delete
$parent_ids = array_map( 'absint', $parent_ids );
[7535] Fix | Delete
$parent_ids = array_unique( array_filter( $parent_ids ) );
[7536] Fix | Delete
[7537] Fix | Delete
if ( ! empty( $parent_ids ) ) {
[7538] Fix | Delete
_prime_post_caches( $parent_ids, false );
[7539] Fix | Delete
}
[7540] Fix | Delete
}
[7541] Fix | Delete
[7542] Fix | Delete
/**
[7543] Fix | Delete
* Updates metadata cache for a list of post IDs.
[7544] Fix | Delete
*
[7545] Fix | Delete
* Performs SQL query to retrieve the metadata for the post IDs and updates the
[7546] Fix | Delete
* metadata cache for the posts. Therefore, the functions, which call this
[7547] Fix | Delete
* function, do not need to perform SQL queries on their own.
[7548] Fix | Delete
*
[7549] Fix | Delete
* @since 2.1.0
[7550] Fix | Delete
*
[7551] Fix | Delete
* @param int[] $post_ids Array of post IDs.
[7552] Fix | Delete
* @return array|false An array of metadata on success, false if there is nothing to update.
[7553] Fix | Delete
*/
[7554] Fix | Delete
function update_postmeta_cache( $post_ids ) {
[7555] Fix | Delete
return update_meta_cache( 'post', $post_ids );
[7556] Fix | Delete
}
[7557] Fix | Delete
[7558] Fix | Delete
/**
[7559] Fix | Delete
* Will clean the attachment in the cache.
[7560] Fix | Delete
*
[7561] Fix | Delete
* Cleaning means delete from the cache. Optionally will clean the term
[7562] Fix | Delete
* object cache associated with the attachment ID.
[7563] Fix | Delete
*
[7564] Fix | Delete
* This function will not run if $_wp_suspend_cache_invalidation is not empty.
[7565] Fix | Delete
*
[7566] Fix | Delete
* @since 3.0.0
[7567] Fix | Delete
*
[7568] Fix | Delete
* @global bool $_wp_suspend_cache_invalidation
[7569] Fix | Delete
*
[7570] Fix | Delete
* @param int $id The attachment ID in the cache to clean.
[7571] Fix | Delete
* @param bool $clean_terms Optional. Whether to clean terms cache. Default false.
[7572] Fix | Delete
*/
[7573] Fix | Delete
function clean_attachment_cache( $id, $clean_terms = false ) {
[7574] Fix | Delete
global $_wp_suspend_cache_invalidation;
[7575] Fix | Delete
[7576] Fix | Delete
if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
[7577] Fix | Delete
return;
[7578] Fix | Delete
}
[7579] Fix | Delete
[7580] Fix | Delete
$id = (int) $id;
[7581] Fix | Delete
[7582] Fix | Delete
wp_cache_delete( $id, 'posts' );
[7583] Fix | Delete
wp_cache_delete( $id, 'post_meta' );
[7584] Fix | Delete
[7585] Fix | Delete
if ( $clean_terms ) {
[7586] Fix | Delete
clean_object_term_cache( $id, 'attachment' );
[7587] Fix | Delete
}
[7588] Fix | Delete
[7589] Fix | Delete
/**
[7590] Fix | Delete
* Fires after the given attachment's cache is cleaned.
[7591] Fix | Delete
*
[7592] Fix | Delete
* @since 3.0.0
[7593] Fix | Delete
*
[7594] Fix | Delete
* @param int $id Attachment ID.
[7595] Fix | Delete
*/
[7596] Fix | Delete
do_action( 'clean_attachment_cache', $id );
[7597] Fix | Delete
}
[7598] Fix | Delete
[7599] Fix | Delete
//
[7600] Fix | Delete
// Hooks.
[7601] Fix | Delete
//
[7602] Fix | Delete
[7603] Fix | Delete
/**
[7604] Fix | Delete
* Hook for managing future post transitions to published.
[7605] Fix | Delete
*
[7606] Fix | Delete
* @since 2.3.0
[7607] Fix | Delete
* @access private
[7608] Fix | Delete
*
[7609] Fix | Delete
* @see wp_clear_scheduled_hook()
[7610] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[7611] Fix | Delete
*
[7612] Fix | Delete
* @param string $new_status New post status.
[7613] Fix | Delete
* @param string $old_status Previous post status.
[7614] Fix | Delete
* @param WP_Post $post Post object.
[7615] Fix | Delete
*/
[7616] Fix | Delete
function _transition_post_status( $new_status, $old_status, $post ) {
[7617] Fix | Delete
global $wpdb;
[7618] Fix | Delete
[7619] Fix | Delete
if ( 'publish' !== $old_status && 'publish' === $new_status ) {
[7620] Fix | Delete
// Reset GUID if transitioning to publish and it is empty.
[7621] Fix | Delete
if ( '' === get_the_guid( $post->ID ) ) {
[7622] Fix | Delete
$wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post->ID ) ), array( 'ID' => $post->ID ) );
[7623] Fix | Delete
}
[7624] Fix | Delete
[7625] Fix | Delete
/**
[7626] Fix | Delete
* Fires when a post's status is transitioned from private to published.
[7627] Fix | Delete
*
[7628] Fix | Delete
* @since 1.5.0
[7629] Fix | Delete
* @deprecated 2.3.0 Use {@see 'private_to_publish'} instead.
[7630] Fix | Delete
*
[7631] Fix | Delete
* @param int $post_id Post ID.
[7632] Fix | Delete
*/
[7633] Fix | Delete
do_action_deprecated( 'private_to_published', array( $post->ID ), '2.3.0', 'private_to_publish' );
[7634] Fix | Delete
}
[7635] Fix | Delete
[7636] Fix | Delete
// If published posts changed clear the lastpostmodified cache.
[7637] Fix | Delete
if ( 'publish' === $new_status || 'publish' === $old_status ) {
[7638] Fix | Delete
foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) {
[7639] Fix | Delete
wp_cache_delete( "lastpostmodified:$timezone", 'timeinfo' );
[7640] Fix | Delete
wp_cache_delete( "lastpostdate:$timezone", 'timeinfo' );
[7641] Fix | Delete
wp_cache_delete( "lastpostdate:$timezone:{$post->post_type}", 'timeinfo' );
[7642] Fix | Delete
}
[7643] Fix | Delete
}
[7644] Fix | Delete
[7645] Fix | Delete
if ( $new_status !== $old_status ) {
[7646] Fix | Delete
wp_cache_delete( _count_posts_cache_key( $post->post_type ), 'counts' );
[7647] Fix | Delete
wp_cache_delete( _count_posts_cache_key( $post->post_type, 'readable' ), 'counts' );
[7648] Fix | Delete
}
[7649] Fix | Delete
[7650] Fix | Delete
// Always clears the hook in case the post status bounced from future to draft.
[7651] Fix | Delete
wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) );
[7652] Fix | Delete
}
[7653] Fix | Delete
[7654] Fix | Delete
/**
[7655] Fix | Delete
* Hook used to schedule publication for a post marked for the future.
[7656] Fix | Delete
*
[7657] Fix | Delete
* The $post properties used and must exist are 'ID' and 'post_date_gmt'.
[7658] Fix | Delete
*
[7659] Fix | Delete
* @since 2.3.0
[7660] Fix | Delete
* @access private
[7661] Fix | Delete
*
[7662] Fix | Delete
* @param int $deprecated Not used. Can be set to null. Never implemented. Not marked
[7663] Fix | Delete
* as deprecated with _deprecated_argument() as it conflicts with
[7664] Fix | Delete
* wp_transition_post_status() and the default filter for _future_post_hook().
[7665] Fix | Delete
* @param WP_Post $post Post object.
[7666] Fix | Delete
*/
[7667] Fix | Delete
function _future_post_hook( $deprecated, $post ) {
[7668] Fix | Delete
wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) );
[7669] Fix | Delete
wp_schedule_single_event( strtotime( get_gmt_from_date( $post->post_date ) . ' GMT' ), 'publish_future_post', array( $post->ID ) );
[7670] Fix | Delete
}
[7671] Fix | Delete
[7672] Fix | Delete
/**
[7673] Fix | Delete
* Hook to schedule pings and enclosures when a post is published.
[7674] Fix | Delete
*
[7675] Fix | Delete
* Uses XMLRPC_REQUEST and WP_IMPORTING constants.
[7676] Fix | Delete
*
[7677] Fix | Delete
* @since 2.3.0
[7678] Fix | Delete
* @access private
[7679] Fix | Delete
*
[7680] Fix | Delete
* @param int $post_id The ID of the post being published.
[7681] Fix | Delete
*/
[7682] Fix | Delete
function _publish_post_hook( $post_id ) {
[7683] Fix | Delete
if ( defined( 'XMLRPC_REQUEST' ) ) {
[7684] Fix | Delete
/**
[7685] Fix | Delete
* Fires when _publish_post_hook() is called during an XML-RPC request.
[7686] Fix | Delete
*
[7687] Fix | Delete
* @since 2.1.0
[7688] Fix | Delete
*
[7689] Fix | Delete
* @param int $post_id Post ID.
[7690] Fix | Delete
*/
[7691] Fix | Delete
do_action( 'xmlrpc_publish_post', $post_id );
[7692] Fix | Delete
}
[7693] Fix | Delete
[7694] Fix | Delete
if ( defined( 'WP_IMPORTING' ) ) {
[7695] Fix | Delete
return;
[7696] Fix | Delete
}
[7697] Fix | Delete
[7698] Fix | Delete
if ( get_option( 'default_pingback_flag' ) ) {
[7699] Fix | Delete
add_post_meta( $post_id, '_pingme', '1', true );
[7700] Fix | Delete
}
[7701] Fix | Delete
add_post_meta( $post_id, '_encloseme', '1', true );
[7702] Fix | Delete
[7703] Fix | Delete
$to_ping = get_to_ping( $post_id );
[7704] Fix | Delete
if ( ! empty( $to_ping ) ) {
[7705] Fix | Delete
add_post_meta( $post_id, '_trackbackme', '1' );
[7706] Fix | Delete
}
[7707] Fix | Delete
[7708] Fix | Delete
if ( ! wp_next_scheduled( 'do_pings' ) ) {
[7709] Fix | Delete
wp_schedule_single_event( time(), 'do_pings' );
[7710] Fix | Delete
}
[7711] Fix | Delete
}
[7712] Fix | Delete
[7713] Fix | Delete
/**
[7714] Fix | Delete
* Returns the ID of the post's parent.
[7715] Fix | Delete
*
[7716] Fix | Delete
* @since 3.1.0
[7717] Fix | Delete
* @since 5.9.0 The `$post` parameter was made optional.
[7718] Fix | Delete
*
[7719] Fix | Delete
* @param int|WP_Post|null $post Optional. Post ID or post object. Defaults to global $post.
[7720] Fix | Delete
* @return int|false Post parent ID (which can be 0 if there is no parent),
[7721] Fix | Delete
* or false if the post does not exist.
[7722] Fix | Delete
*/
[7723] Fix | Delete
function wp_get_post_parent_id( $post = null ) {
[7724] Fix | Delete
$post = get_post( $post );
[7725] Fix | Delete
[7726] Fix | Delete
if ( ! $post || is_wp_error( $post ) ) {
[7727] Fix | Delete
return false;
[7728] Fix | Delete
}
[7729] Fix | Delete
[7730] Fix | Delete
return (int) $post->post_parent;
[7731] Fix | Delete
}
[7732] Fix | Delete
[7733] Fix | Delete
/**
[7734] Fix | Delete
* Checks the given subset of the post hierarchy for hierarchy loops.
[7735] Fix | Delete
*
[7736] Fix | Delete
* Prevents loops from forming and breaks those that it finds. Attached
[7737] Fix | Delete
* to the {@see 'wp_insert_post_parent'} filter.
[7738] Fix | Delete
*
[7739] Fix | Delete
* @since 3.1.0
[7740] Fix | Delete
*
[7741] Fix | Delete
* @see wp_find_hierarchy_loop()
[7742] Fix | Delete
*
[7743] Fix | Delete
* @param int $post_parent ID of the parent for the post we're checking.
[7744] Fix | Delete
* @param int $post_id ID of the post we're checking.
[7745] Fix | Delete
* @return int The new post_parent for the post, 0 otherwise.
[7746] Fix | Delete
*/
[7747] Fix | Delete
function wp_check_post_hierarchy_for_loops( $post_parent, $post_id ) {
[7748] Fix | Delete
// Nothing fancy here - bail.
[7749] Fix | Delete
if ( ! $post_parent ) {
[7750] Fix | Delete
return 0;
[7751] Fix | Delete
}
[7752] Fix | Delete
[7753] Fix | Delete
// New post can't cause a loop.
[7754] Fix | Delete
if ( ! $post_id ) {
[7755] Fix | Delete
return $post_parent;
[7756] Fix | Delete
}
[7757] Fix | Delete
[7758] Fix | Delete
// Can't be its own parent.
[7759] Fix | Delete
if ( $post_parent == $post_id ) {
[7760] Fix | Delete
return 0;
[7761] Fix | Delete
}
[7762] Fix | Delete
[7763] Fix | Delete
// Now look for larger loops.
[7764] Fix | Delete
$loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_id, $post_parent );
[7765] Fix | Delete
if ( ! $loop ) {
[7766] Fix | Delete
return $post_parent; // No loop.
[7767] Fix | Delete
}
[7768] Fix | Delete
[7769] Fix | Delete
// Setting $post_parent to the given value causes a loop.
[7770] Fix | Delete
if ( isset( $loop[ $post_id ] ) ) {
[7771] Fix | Delete
return 0;
[7772] Fix | Delete
}
[7773] Fix | Delete
[7774] Fix | Delete
// There's a loop, but it doesn't contain $post_id. Break the loop.
[7775] Fix | Delete
foreach ( array_keys( $loop ) as $loop_member ) {
[7776] Fix | Delete
wp_update_post(
[7777] Fix | Delete
array(
[7778] Fix | Delete
'ID' => $loop_member,
[7779] Fix | Delete
'post_parent' => 0,
[7780] Fix | Delete
)
[7781] Fix | Delete
);
[7782] Fix | Delete
}
[7783] Fix | Delete
[7784] Fix | Delete
return $post_parent;
[7785] Fix | Delete
}
[7786] Fix | Delete
[7787] Fix | Delete
/**
[7788] Fix | Delete
* Sets the post thumbnail (featured image) for the given post.
[7789] Fix | Delete
*
[7790] Fix | Delete
* @since 3.1.0
[7791] Fix | Delete
*
[7792] Fix | Delete
* @param int|WP_Post $post Post ID or post object where thumbnail should be attached.
[7793] Fix | Delete
* @param int $thumbnail_id Thumbnail to attach.
[7794] Fix | Delete
* @return int|bool True on success, false on failure.
[7795] Fix | Delete
*/
[7796] Fix | Delete
function set_post_thumbnail( $post, $thumbnail_id ) {
[7797] Fix | Delete
$post = get_post( $post );
[7798] Fix | Delete
$thumbnail_id = absint( $thumbnail_id );
[7799] Fix | Delete
if ( $post && $thumbnail_id && get_post( $thumbnail_id ) ) {
[7800] Fix | Delete
if ( wp_get_attachment_image( $thumbnail_id, 'thumbnail' ) ) {
[7801] Fix | Delete
return update_post_meta( $post->ID, '_thumbnail_id', $thumbnail_id );
[7802] Fix | Delete
} else {
[7803] Fix | Delete
return delete_post_meta( $post->ID, '_thumbnail_id' );
[7804] Fix | Delete
}
[7805] Fix | Delete
}
[7806] Fix | Delete
return false;
[7807] Fix | Delete
}
[7808] Fix | Delete
[7809] Fix | Delete
/**
[7810] Fix | Delete
* Removes the thumbnail (featured image) from the given post.
[7811] Fix | Delete
*
[7812] Fix | Delete
* @since 3.3.0
[7813] Fix | Delete
*
[7814] Fix | Delete
* @param int|WP_Post $post Post ID or post object from which the thumbnail should be removed.
[7815] Fix | Delete
* @return bool True on success, false on failure.
[7816] Fix | Delete
*/
[7817] Fix | Delete
function delete_post_thumbnail( $post ) {
[7818] Fix | Delete
$post = get_post( $post );
[7819] Fix | Delete
if ( $post ) {
[7820] Fix | Delete
return delete_post_meta( $post->ID, '_thumbnail_id' );
[7821] Fix | Delete
}
[7822] Fix | Delete
return false;
[7823] Fix | Delete
}
[7824] Fix | Delete
[7825] Fix | Delete
/**
[7826] Fix | Delete
* Deletes auto-drafts for new posts that are > 7 days old.
[7827] Fix | Delete
*
[7828] Fix | Delete
* @since 3.4.0
[7829] Fix | Delete
*
[7830] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[7831] Fix | Delete
*/
[7832] Fix | Delete
function wp_delete_auto_drafts() {
[7833] Fix | Delete
global $wpdb;
[7834] Fix | Delete
[7835] Fix | Delete
// Cleanup old auto-drafts more than 7 days old.
[7836] Fix | Delete
$old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" );
[7837] Fix | Delete
foreach ( (array) $old_posts as $delete ) {
[7838] Fix | Delete
// Force delete.
[7839] Fix | Delete
wp_delete_post( $delete, true );
[7840] Fix | Delete
}
[7841] Fix | Delete
}
[7842] Fix | Delete
[7843] Fix | Delete
/**
[7844] Fix | Delete
* Queues posts for lazy-loading of term meta.
[7845] Fix | Delete
*
[7846] Fix | Delete
* @since 4.5.0
[7847] Fix | Delete
*
[7848] Fix | Delete
* @param WP_Post[] $posts Array of WP_Post objects.
[7849] Fix | Delete
*/
[7850] Fix | Delete
function wp_queue_posts_for_term_meta_lazyload( $posts ) {
[7851] Fix | Delete
$post_type_taxonomies = array();
[7852] Fix | Delete
$prime_post_terms = array();
[7853] Fix | Delete
foreach ( $posts as $post ) {
[7854] Fix | Delete
if ( ! ( $post instanceof WP_Post ) ) {
[7855] Fix | Delete
continue;
[7856] Fix | Delete
}
[7857] Fix | Delete
[7858] Fix | Delete
if ( ! isset( $post_type_taxonomies[ $post->post_type ] ) ) {
[7859] Fix | Delete
$post_type_taxonomies[ $post->post_type ] = get_object_taxonomies( $post->post_type );
[7860] Fix | Delete
}
[7861] Fix | Delete
[7862] Fix | Delete
foreach ( $post_type_taxonomies[ $post->post_type ] as $taxonomy ) {
[7863] Fix | Delete
$prime_post_terms[ $taxonomy ][] = $post->ID;
[7864] Fix | Delete
}
[7865] Fix | Delete
}
[7866] Fix | Delete
[7867] Fix | Delete
$term_ids = array();
[7868] Fix | Delete
if ( $prime_post_terms ) {
[7869] Fix | Delete
foreach ( $prime_post_terms as $taxonomy => $post_ids ) {
[7870] Fix | Delete
$cached_term_ids = wp_cache_get_multiple( $post_ids, "{$taxonomy}_relationships" );
[7871] Fix | Delete
if ( is_array( $cached_term_ids ) ) {
[7872] Fix | Delete
$cached_term_ids = array_filter( $cached_term_ids );
[7873] Fix | Delete
foreach ( $cached_term_ids as $_term_ids ) {
[7874] Fix | Delete
// Backward compatibility for if a plugin is putting objects into the cache, rather than IDs.
[7875] Fix | Delete
foreach ( $_term_ids as $term_id ) {
[7876] Fix | Delete
if ( is_numeric( $term_id ) ) {
[7877] Fix | Delete
$term_ids[] = (int) $term_id;
[7878] Fix | Delete
} elseif ( isset( $term_id->term_id ) ) {
[7879] Fix | Delete
$term_ids[] = (int) $term_id->term_id;
[7880] Fix | Delete
}
[7881] Fix | Delete
}
[7882] Fix | Delete
}
[7883] Fix | Delete
}
[7884] Fix | Delete
}
[7885] Fix | Delete
$term_ids = array_unique( $term_ids );
[7886] Fix | Delete
}
[7887] Fix | Delete
[7888] Fix | Delete
wp_lazyload_term_meta( $term_ids );
[7889] Fix | Delete
}
[7890] Fix | Delete
[7891] Fix | Delete
/**
[7892] Fix | Delete
* Updates the custom taxonomies' term counts when a post's status is changed.
[7893] Fix | Delete
*
[7894] Fix | Delete
* For example, default posts term counts (for custom taxonomies) don't include
[7895] Fix | Delete
* private / draft posts.
[7896] Fix | Delete
*
[7897] Fix | Delete
* @since 3.3.0
[7898] Fix | Delete
* @access private
[7899] Fix | Delete
*
[7900] Fix | Delete
* @param string $new_status New post status.
[7901] Fix | Delete
* @param string $old_status Old post status.
[7902] Fix | Delete
* @param WP_Post $post Post object.
[7903] Fix | Delete
*/
[7904] Fix | Delete
function _update_term_count_on_transition_post_status( $new_status, $old_status, $post ) {
[7905] Fix | Delete
// Update counts for the post's terms.
[7906] Fix | Delete
foreach ( (array) get_object_taxonomies( $post->post_type ) as $taxonomy ) {
[7907] Fix | Delete
$tt_ids = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'tt_ids' ) );
[7908] Fix | Delete
wp_update_term_count( $tt_ids, $taxonomy );
[7909] Fix | Delete
}
[7910] Fix | Delete
}
[7911] Fix | Delete
[7912] Fix | Delete
/**
[7913] Fix | Delete
* Adds any posts from the given IDs to the cache that do not already exist in cache.
[7914] Fix | Delete
*
[7915] Fix | Delete
* @since 3.4.0
[7916] Fix | Delete
* @since 6.1.0 This function is no longer marked as "private".
[7917] Fix | Delete
*
[7918] Fix | Delete
* @see update_post_cache()
[7919] Fix | Delete
* @see update_postmeta_cache()
[7920] Fix | Delete
* @see update_object_term_cache()
[7921] Fix | Delete
*
[7922] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[7923] Fix | Delete
*
[7924] Fix | Delete
* @param int[] $ids ID list.
[7925] Fix | Delete
* @param bool $update_term_cache Optional. Whether to update the term cache. Default true.
[7926] Fix | Delete
* @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true.
[7927] Fix | Delete
*/
[7928] Fix | Delete
function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache = true ) {
[7929] Fix | Delete
global $wpdb;
[7930] Fix | Delete
[7931] Fix | Delete
$non_cached_ids = _get_non_cached_ids( $ids, 'posts' );
[7932] Fix | Delete
if ( ! empty( $non_cached_ids ) ) {
[7933] Fix | Delete
$fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", implode( ',', $non_cached_ids ) ) );
[7934] Fix | Delete
[7935] Fix | Delete
if ( $fresh_posts ) {
[7936] Fix | Delete
// Despite the name, update_post_cache() expects an array rather than a single post.
[7937] Fix | Delete
update_post_cache( $fresh_posts );
[7938] Fix | Delete
}
[7939] Fix | Delete
}
[7940] Fix | Delete
[7941] Fix | Delete
if ( $update_meta_cache ) {
[7942] Fix | Delete
update_postmeta_cache( $ids );
[7943] Fix | Delete
}
[7944] Fix | Delete
[7945] Fix | Delete
if ( $update_term_cache ) {
[7946] Fix | Delete
$post_types = array_map( 'get_post_type', $ids );
[7947] Fix | Delete
$post_types = array_unique( $post_types );
[7948] Fix | Delete
update_object_term_cache( $ids, $post_types );
[7949] Fix | Delete
}
[7950] Fix | Delete
}
[7951] Fix | Delete
[7952] Fix | Delete
/**
[7953] Fix | Delete
* Prime the cache containing the parent ID of various post objects.
[7954] Fix | Delete
*
[7955] Fix | Delete
* @since 6.4.0
[7956] Fix | Delete
*
[7957] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[7958] Fix | Delete
*
[7959] Fix | Delete
* @param int[] $ids ID list.
[7960] Fix | Delete
*/
[7961] Fix | Delete
function _prime_post_parent_id_caches( array $ids ) {
[7962] Fix | Delete
global $wpdb;
[7963] Fix | Delete
[7964] Fix | Delete
$ids = array_filter( $ids, '_validate_cache_id' );
[7965] Fix | Delete
$ids = array_unique( array_map( 'intval', $ids ), SORT_NUMERIC );
[7966] Fix | Delete
[7967] Fix | Delete
if ( empty( $ids ) ) {
[7968] Fix | Delete
return;
[7969] Fix | Delete
}
[7970] Fix | Delete
[7971] Fix | Delete
$cache_keys = array();
[7972] Fix | Delete
foreach ( $ids as $id ) {
[7973] Fix | Delete
$cache_keys[ $id ] = 'post_parent:' . (string) $id;
[7974] Fix | Delete
}
[7975] Fix | Delete
[7976] Fix | Delete
$cached_data = wp_cache_get_multiple( array_values( $cache_keys ), 'posts' );
[7977] Fix | Delete
[7978] Fix | Delete
$non_cached_ids = array();
[7979] Fix | Delete
foreach ( $cache_keys as $id => $cache_key ) {
[7980] Fix | Delete
if ( false === $cached_data[ $cache_key ] ) {
[7981] Fix | Delete
$non_cached_ids[] = $id;
[7982] Fix | Delete
}
[7983] Fix | Delete
}
[7984] Fix | Delete
[7985] Fix | Delete
if ( ! empty( $non_cached_ids ) ) {
[7986] Fix | Delete
$fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.ID, $wpdb->posts.post_parent FROM $wpdb->posts WHERE ID IN (%s)", implode( ',', $non_cached_ids ) ) );
[7987] Fix | Delete
[7988] Fix | Delete
if ( $fresh_posts ) {
[7989] Fix | Delete
$post_parent_data = array();
[7990] Fix | Delete
foreach ( $fresh_posts as $fresh_post ) {
[7991] Fix | Delete
$post_parent_data[ 'post_parent:' . (string) $fresh_post->ID ] = (int) $fresh_post->post_parent;
[7992] Fix | Delete
}
[7993] Fix | Delete
[7994] Fix | Delete
wp_cache_add_multiple( $post_parent_data, 'posts' );
[7995] Fix | Delete
}
[7996] Fix | Delete
}
[7997] Fix | Delete
}
[7998] Fix | Delete
[7999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function