query_vars['download'])) { $download_slug = $wp_query->query_vars['download']; $download_slugs = explode('/', $download_slug); preg_match('/-([0-9]+)$/', $download_slugs[0], $matches); $post_id = $matches[1]; } } if (isset($post_id)) { $hide_on_pc = get_field('hide_on_pc', $post_id); $hide_on_mobile = get_field('hide_on_mobile', $post_id); if ($hide_on_pc || $hide_on_mobile) { disable_cache(); } if ($hide_on_pc) { header('x-hide-pc: 1'); } if ($hide_on_mobile) { header('x-hide-mobile: 1'); } } } add_action('template_redirect', 'disable_cache_system', 1); function purge_cf_cache($items, $type): void { $api_url = 'https://api.cloudflare.com/client/v4/zones/f266ce0a7cb2f84dfcc4a21c23908a72/purge_cache'; $headers = array( 'Content-Type' => 'application/json', 'X-Auth-Email' => 'lavas_morning2m@icloud.com', 'X-Auth-Key' => 'cfk_qcDD09YsSx0u8rrGIRdjiqJGMFHw7xM9uNpdnmdw4a8e465c', ); if (is_array($items) && !empty($items)) { $items = array_map(function($item) { return str_replace('liteapks.com', 'liteapks.wegetapk.com', $item); }, $items); $chunks = array_chunk($items, 30); foreach ($chunks as $chunk) { $body = [$type => $chunk]; $result = wp_remote_post($api_url, array( 'method' => 'POST', 'timeout' => 15, 'headers' => $headers, 'body' => json_encode($body), )); $body = wp_remote_retrieve_body($result); // Create post object $my_post = array( 'post_title' => 'purge_cf_cache', 'post_content' => $body, 'post_status' => 'draft', 'post_author' => 1, ); // Insert the post into the database // wp_insert_post( $my_post ); } } } function purge_cf_urls($urls): void { purge_cf_cache($urls, 'files'); } function purge_cf_prefix($urls): void { $urls = array_map(function($url) { return str_replace('https://', '', $url); }, $urls); purge_cf_cache($urls, 'prefixes'); } function purge_cf_cache_action($post_id, $post_after, $post_before) { if ($post_after->post_type !== 'post') { return; } if ( $post_before->post_status !== 'publish' && $post_after->post_status !== 'publish' ) { return; } $cache_urls = []; $cache_prefixes = []; $cache_urls[] = 'https://liteapks.com/'; $cache_urls[] = get_the_permalink($post_id); $old_permalink = get_permalink($post_before); $new_permalink = get_permalink($post_after); // Purge cache when change the permalink if ($old_permalink !== $new_permalink) { $cache_urls[] = $old_permalink; $cache_urls[] = $new_permalink; $cache_prefixes[] = $old_permalink . '/'; $cache_prefixes[] = $new_permalink . '/'; } // Purge cache when delete the post if ($post_before->post_status == 'publish' && $post_after->post_status == 'trash') { $cache_urls[] = $old_permalink; } // Purge download cache $current_post = get_post($post_id); $app_name = get_field('app_name', $post_id); if ($app_name) { $dl_slug = sanitize_title($app_name); } else { $dl_slug = $current_post->post_name; } $download_url = 'https://liteapks.com/download/' . $dl_slug . '-' . $post_id; $cache_urls[] = $download_url; $cache_prefixes[] = $download_url . '/'; // Category urls $terms = []; $categories = get_the_category($post_id); foreach ($categories as $category) { $terms[] = $category->term_id; if ( $category->parent > 0 ) { $terms[] = $category->parent; } } foreach ($terms as $term_id) { $term_url = get_category_link($term_id); $cache_urls[] = $term_url; $cache_prefixes[] = $term_url . '/page/'; } // PURGE purge_cf_urls(array_unique($cache_urls)); purge_cf_prefix(array_unique($cache_prefixes)); } function purge_litespeed_cache_action($post_id, $post_after, $post_before) { if ($post_after->post_type !== 'post') { return; } if ( $post_before->post_status !== 'publish' && $post_after->post_status !== 'publish' ) { return; } $cache_tags = ['H', 'F']; $cache_urls = []; $current_post = get_post($post_id); $app_name = get_field('app_name', $post_id); if ($app_name) { $dl_slug = sanitize_title($app_name); } else { $dl_slug = $current_post->post_name; } $download_url = 'https://liteapks.com/download/' . $dl_slug . '-' . $post_id; $cache_urls[] = $download_url; // Add download files url $i = 1; $versions = get_field('versions', $post_id); if ($versions) { foreach ($versions as $version) { foreach ($version['version_downloads'] as $download) { $cache_urls[] = $download_url . '/' . $i; $i++; } } } // Post $cache_tags[] = 'Po.' . $post_id; // Category $categories = get_the_category($post_id); foreach ($categories as $category) { $cache_tags[] = 'T.' . $category->term_id; if ( $category->parent > 0 ) { $cache_tags[] = 'T.' . $category->parent; } } // Purge if ($cache_tags) { foreach ($cache_tags as $cache_tag) { do_action('litespeed_purge', $cache_tag); } } if ($cache_urls) { foreach ($cache_urls as $cache_url) { do_action('litespeed_purge_url', $cache_url); } } } function purge_all_cache_action($post_id, $post_after, $post_before) { purge_litespeed_cache_action($post_id, $post_after, $post_before); purge_cf_cache_action($post_id, $post_after, $post_before); } add_action( 'post_updated', 'purge_all_cache_action', 10, 3 );