clean_attachment_cache

函式
clean_attachment_cache ( $id, $clean_terms = false )
引數
  • (int) $id The attachment ID in the cache to clean.
    Required:
  • (bool) $clean_terms Optional. Whether to clean terms cache. Default false.
    Required:
    Default: false
定義位置
相關方法
clean_comment_cacheclean_term_cachewp_clean_themes_cacheclean_page_cacheclean_taxonomy_cache
引入
3.0.0
棄用
-

clean_attachment_cache: 這個函式清除了某個附件的快取。它用於確保附件的最新版本總是被顯示。

將清理快取中的附件。

清理意味著從快取中刪除。也可以選擇清理與該附件ID相關的術語物件快取。

如果$_wp_suspend_cache_invalidation不是空的,這個函式就不會執行。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function clean_attachment_cache( $id, $clean_terms = false ) {
global $_wp_suspend_cache_invalidation;
if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
return;
}
$id = (int) $id;
wp_cache_delete( $id, 'posts' );
wp_cache_delete( $id, 'post_meta' );
if ( $clean_terms ) {
clean_object_term_cache( $id, 'attachment' );
}
/**
* Fires after the given attachment's cache is cleaned.
*
* @since 3.0.0
*
* @param int $id Attachment ID.
*/
do_action( 'clean_attachment_cache', $id );
}
function clean_attachment_cache( $id, $clean_terms = false ) { global $_wp_suspend_cache_invalidation; if ( ! empty( $_wp_suspend_cache_invalidation ) ) { return; } $id = (int) $id; wp_cache_delete( $id, 'posts' ); wp_cache_delete( $id, 'post_meta' ); if ( $clean_terms ) { clean_object_term_cache( $id, 'attachment' ); } /** * Fires after the given attachment's cache is cleaned. * * @since 3.0.0 * * @param int $id Attachment ID. */ do_action( 'clean_attachment_cache', $id ); }
function clean_attachment_cache( $id, $clean_terms = false ) {
	global $_wp_suspend_cache_invalidation;

	if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
		return;
	}

	$id = (int) $id;

	wp_cache_delete( $id, 'posts' );
	wp_cache_delete( $id, 'post_meta' );

	if ( $clean_terms ) {
		clean_object_term_cache( $id, 'attachment' );
	}

	/**
	 * Fires after the given attachment's cache is cleaned.
	 *
	 * @since 3.0.0
	 *
	 * @param int $id Attachment ID.
	 */
	do_action( 'clean_attachment_cache', $id );
}

常見問題

FAQs
檢視更多 >