• Resolved korchiy

    (@korchiy)


    Hi!
    I use your plugin WP-Optimize with the multilingual plugin Polylang. I see that when I publish a new post, WP-Optimize cleans the partial cache for the new posts feed of the main language and doesn't clean the partial cache for the new posts feed of the second language. But it needs to clean when the new post is published.
    I know how to hook to the post publishing event.
    add_action('transition_post_status',  'my_func', 10, 3);
    What code I need to use in my_func to partial clear the cache only of the desired page (in my case - to the new posts feed on the second language with address https://my_site/second_lang/)?
Viewing 11 replies - 1 through 11 (of 11 total)
  • @korchiy Sorry at the moment this is not a feature yet, you can only purge the full cache when you click purge cache.

    Thread Starter korchiy

    (@korchiy)

    Is the force deleting the .html, .php and .gz files of the required directory in WP Optimize cache folder equal with the partial clearing cache for this page?
    What will appear if I delete them?

    @korchiy If you delete the files the cache files will be deleted and it will generate new files when you visit the pages.

    Thread Starter korchiy

    (@korchiy)

    I searched the source of the WP Optimize plugin and found the function delete_cache_by_url in the WPO_Page_Cache class.
    So to clean cache for the different language, I wrote the following code. Maybe it will be useful for somebody else

    function wp_optimize_dlang_cache_clean($new_status, $old_status, $post) {
    	if(in_array($post->post_type, ['post', 'page']) && $new_status === 'publish') {
    		if(function_exists('pll_get_post_language') && function_exists('pll_default_language')) {
    			$post_lang = pll_get_post_language($post->ID); // fr
    			$def_lang = pll_default_language();  // en
    			if($post_lang && $def_lang && $post_lang != $def_lang) {
    				$url = home_url() . '/' . $post_lang . '/';
    				if(class_exists('WPO_Page_Cache')) {
    					WPO_Page_Cache::delete_cache_by_url($url, false);
    				}
    			}
    		}
    	}
    }
    add_action('transition_post_status', 'wp_optimize_dlang_cache_clean', 10, 3);

    pll_get_post_language and pll_default_language functions are from the Polylang plugin to get the current post language and the default site language.

    @korchiy Thanks for sharing the code, I’ll share the same with our development team, so it can be implemented in future release

    Hello.
    Do you think it can somehow be applied to woocomerce products?
    I have been looking for a solution for clearing the cache of a translated product for a long time.
    And everyone throws up their hands.
    Only the main language is cleared, the other language shows the wrong price or balances.
    They say to clear the cache manually .. But there are more than 5000 products.
    I’m sure there is a similar hook for products 🙂

    Thread Starter korchiy

    (@korchiy)

    Have you tried my code? If I’m not mistaken, the WooCommerce product pages are the common “post” pages. So I think my code could work with them too. Of course, it needs to be tested in practice.

    Now I have installed Polylang and need to prepare the translation.
    And I will test.
    Should this code be added to function.php?

    Thread Starter korchiy

    (@korchiy)

    Should this code be added to function.php?

    Yes, you need it in the functions.php to work.

    Tested tested …. Nothing worked.
    Changed the hosting everything worked out 🙂
    Thanks a lot for the hook.

    Thread Starter korchiy

    (@korchiy)

    It’s strange, the code doesn’t depend on hosting.

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Is there a way to call partial clear cache by hooks?’ is closed to new replies.