Title: call Preload function
Last modified: April 9, 2023

---

# call Preload function

 *  Resolved [fkoomek](https://wordpress.org/support/users/fkoomek/)
 * (@fkoomek)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/call-preload-function/)
 * Hello.
 * Is it possible to call preload function programatically? I would like to call
   preload every time the cache is purged.
 * Thanks.

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

 *  Plugin Contributor [Venkat Raj](https://wordpress.org/support/users/webulous/)
 * (@webulous)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/call-preload-function/#post-16640870)
 * [@fkoomek](https://wordpress.org/support/users/fkoomek/) You could use `Schedule
   preloader` option and set `schedule type` as `same as cache lifespan` 
   This runs
   preload whenever the cache is purged.
 *  Thread Starter [fkoomek](https://wordpress.org/support/users/fkoomek/)
 * (@fkoomek)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/call-preload-function/#post-16654519)
 * Hi.
 * I don’t think that when I clear the cache manually, preloading starts. However,
   I found in the code function for this:
 *     ```wp-block-code
       WP_Optimize_Page_Cache_Preloader::instance()->run('manual');
       ```
   
 * How would I hook this function to the moment when I manually clear cache?
 * Thanks.
 * Radan
 *  Plugin Contributor [Venkat Raj](https://wordpress.org/support/users/webulous/)
 * (@webulous)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/call-preload-function/#post-16654635)
 * Hi [@fkoomek](https://wordpress.org/support/users/fkoomek/) 
   You can use this
   hook `wpo_cache_flush` to do that.
 *  Thread Starter [fkoomek](https://wordpress.org/support/users/fkoomek/)
 * (@fkoomek)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/call-preload-function/#post-16656312)
 * Hello. I used the code like this and it works if go to the WP-Optimize menu, 
   click Cache, and click Clear Cache. It doesn’t work for the top bar if I click
   clear all cache. How to hook up there?
 *     ```wp-block-code
       add_action('wpo_cache_flush ', 'purge_all_caches');
       function purge_all_caches()
       {
   
       WP_Optimize_Page_Cache_Preloader::instance()->run('manual');
   
       }
       ```
   
 * Thanks.
 * Radan
 *  [Hadis](https://wordpress.org/support/users/hadis89/)
 * (@hadis89)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/call-preload-function/#post-16663356)
 * I am also searching for same. I figured that logged in user can call: `WP_Optimize_Page_Cache_Preloader::
   instance()->run('manual');` But from cronjob script is not executed as it need.
 * It also works with bash script, but it’s not good solution for me:
 *     ```wp-block-code
       #!/usr/bin/env bash
   
       site="https://www.web.com/"
       login_address="$site/wp-login.php"
       log="user"
       pwd="pass"
       cookies="/tmp/cookies.txt"
       agent="Mozilla/5.0"
   
       # authenticate and save cookies
       wget \
           --user-agent="$agent" \
           --save-cookies $cookies \
           --keep-session-cookies \
           --delete-after \
           --post-data="log=$log&pwd=$pwd&testcookie=1" \
           "$login_address"
   
       # access home page with authenticated cookies
       wget \
           --user-agent="$agent" \
           --load-cookies $cookies \
           "www.web.com/test.php"
       ```
   
 *  Plugin Contributor [Venkat Raj](https://wordpress.org/support/users/webulous/)
 * (@webulous)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/call-preload-function/#post-16664982)
 * [@fkoomek](https://wordpress.org/support/users/fkoomek/) Both menu run a `purge`
   method which contains the hook, I mentioned. Your script worked for me for both
   places, except that it had a white space at the end of `wpo_cache_flush`
 *  Thread Starter [fkoomek](https://wordpress.org/support/users/fkoomek/)
 * (@fkoomek)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/call-preload-function/#post-16666226)
 * [@webulous](https://wordpress.org/support/users/webulous/) Hi. You are right.
   I have there extra space. 
   After I corrected it I am actually getting some errors
   and notices. For example when I deactivate some plugin a get a white screen saying:{“
   success”:true}:
 *  Plugin Contributor [Venkat Raj](https://wordpress.org/support/users/webulous/)
 * (@webulous)
 * [3 years, 1 month ago](https://wordpress.org/support/topic/call-preload-function/#post-16668208)
 * [@fkoomek](https://wordpress.org/support/users/fkoomek/) That is because upon
   plugin deactivation the cache are purged and started to preload again. We’ll 
   look into this.

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

The topic ‘call Preload function’ is closed to new replies.

 * ![](https://ps.w.org/wp-optimize/assets/icon-256x256.png?rev=1552899)
 * [WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance](https://wordpress.org/plugins/wp-optimize/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-optimize/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-optimize/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-optimize/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-optimize/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-optimize/reviews/)

 * 8 replies
 * 3 participants
 * Last reply from: [Venkat Raj](https://wordpress.org/support/users/webulous/)
 * Last activity: [3 years, 1 month ago](https://wordpress.org/support/topic/call-preload-function/#post-16668208)
 * Status: resolved