Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('swift_performance_warmup_urls_to_save', 'my_custom_warmup_likns');
- function my_custom_warmup_likns(){
- global $wpdb;
- $urls = $post_urls = $menu_elements = $archives = $already_added = array();
- set_transient('swift_performance_initial_prebuild_links', true, $timeout);
- // Home
- if (Swift_Performance_Cache::is_object_cacheable(home_url())){
- $urls[Swift_Performance::get_warmup_id(home_url())] = trailingslashit(home_url());
- }
- // Post types
- $post_types = array();
- foreach (Swift_Performance::get_post_types(Swift_Performance::get_option('exclude-post-types')) as $post_type){
- $post_types[] = "'{$post_type}'";
- // Archive
- if (Swift_Performance::check_option('cache-archive',1)){
- $archive = get_post_type_archive_link( $post_type );
- if ($archive !== false){
- $url = get_post_type_archive_link( $post_type );
- if (Swift_Performance_Cache::is_object_cacheable($url)){
- $archives[Swift_Performance::get_warmup_id($url)] = $url;
- }
- }
- }
- // Terms
- if (Swift_Performance::check_option('cache-terms',1)){
- $taxonomy_objects = get_object_taxonomies( $post_type, 'objects' );
- foreach ($taxonomy_objects as $key => $value) {
- $terms = get_terms($key);
- foreach ( $terms as $term ) {
- $url = get_term_link( $term );
- if (Swift_Performance_Cache::is_object_cacheable($url)){
- $archives[Swift_Performance::get_warmup_id($url)] = $url;
- }
- }
- }
- }
- }
- $menu_item_ids = $wpdb->get_col("SELECT meta_value FROM {$wpdb->postmeta} LEFT JOIN {$wpdb->posts} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.meta_value WHERE meta_key = '_menu_item_object_id' AND post_type != 'nav_menu_item'");
- $public_post_ids = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_status = 'publish' AND post_date > '2018-12-31' AND post_type IN(".implode(',', $post_types).") ORDER BY post_date DESC");
- $posts = array_merge((array)$menu_item_ids, (array)$public_post_ids);
- // WPML
- if ((!defined('SWIFT_PERFORMANCE_WPML_WARMUP') || SWIFT_PERFORMANCE_WPML_WARMUP) && function_exists('icl_get_languages') && class_exists('SitePress')){
- if($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}icl_translations'") == $wpdb->prefix . 'icl_translations') {
- $translations = $wpdb->get_col("SELECT DISTINCT element_id FROM {$wpdb->prefix}icl_translations WHERE language_code != source_language_code AND source_language_code IS NOT NULL and element_type LIKE 'post_%'");
- $posts = array_diff($posts, $translations);
- }
- global $sitepress;
- $languages = icl_get_languages('skip_missing=0&orderby=KEY&order=DIR&link_empty_to=str');
- foreach ($languages as $language){
- $sitepress->switch_lang($language['code'], true);
- foreach ($posts as $post_id){
- wp_cache_flush();
- $permalink = get_permalink($post_id);
- if (Swift_Performance_Cache::is_object_cacheable($permalink, $post_id)){
- if (in_array($post_id, $menu_item_ids)){
- $menu_elements[Swift_Performance::get_warmup_id($permalink)] = $permalink;
- }
- else {
- $post_urls[Swift_Performance::get_warmup_id($permalink)] = $permalink;
- }
- }
- }
- }
- }
- else {
- foreach ($posts as $post_id){
- wp_cache_flush();
- $permalink = get_permalink($post_id);
- if (Swift_Performance_Cache::is_object_cacheable($permalink, $post_id)){
- if (in_array($post_id, $menu_item_ids)){
- $menu_elements[Swift_Performance::get_warmup_id($permalink)] = $permalink;
- }
- else {
- $post_urls[Swift_Performance::get_warmup_id($permalink)] = $permalink;
- }
- }
- }
- }
- $urls = array_merge($urls, $menu_elements, $archives, $post_urls);
- // Limit pages
- $urls = array_slice($urls, 0, SWIFT_PERFORMANCE_WARMUP_LIMIT);
- return $urls;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement