Complete the code to enable page caching in WordPress using a plugin.
<?php // Activate caching plugin add_action('init', function() { if (!function_exists('[1]')) { return; } [1](); });
The wp_cache_init function initializes the WordPress caching system. It is used by caching plugins to start caching.
Complete the code to clear the cache when a post is updated.
<?php add_action('save_post', function($post_id) { if (wp_is_post_revision($post_id)) { return; } [1](); });
The wp_cache_flush function clears the entire cache in WordPress. It is commonly used after content updates.
Fix the error in the code to set cache expiration time correctly.
<?php
function set_cache_expiration() {
$expiration = [1] * 60; // minutes to seconds
wp_cache_set('cache_expiration', $expiration);
}The expiration time should be set as an integer representing minutes. Multiplying by 60 converts minutes to seconds.
Fill both blanks to create a transient cache with expiration.
<?php set_transient('[1]', $data, [2]);
The first blank is the cache key as a string. The second blank is the expiration time in seconds (3600 = 1 hour).
Fill all three blanks to retrieve cached data safely.
<?php $cache = get_transient([1]); if ([2] === false) { $cache = fetch_data(); set_transient([3], $cache, 3600); }
The cache key is used to get and set the transient. The variable $cache is checked to see if the cache is empty (false).