• Resolved wpublish2

    (@wpublish2)


    Hi,

    Do you have a filter/action to run once and right before the automatic preload/caching of URLs starts? Maybe something before run_scheduled_cache_preload() be called.

    I found these:

    do_action(‘ud_task_before_initialise’, $this, $options);
    do_action(‘ud_task_initialised’, $this);
    do_action(‘ud_task_started’, $this);
    do_action(‘ud_task_initialise_complete’, $this, $options);

    I need to append some custom URLs to sitemap.xml file.

    Or, I’d like to add custom URLs to the preload list.

    Thanks in advance.

Viewing 6 replies - 1 through 6 (of 6 total)
  • @wpublish2 At the moment you cannot preload the custom urls, however I’ll confirm with our development team if there’s a filter to preload custom urls.

    Hi @wpublish2,

    I don’t think the hooks you found will be helpful.
    I’ve added a filter to the list of URLs, and will post it here when it’s validated and included in our codebase, so you can use it before the next release if you wish.

    Marc

    Thread Starter wpublish2

    (@wpublish2)

    Hi Marc,

    I think a filter after this will do the job:

    public function create_tasks_for_preload_site_urls($type) {
    $urls = $this->get_site_urls();
    $urls = apply_filters(‘wpo_filter_preload_urls’, $urls);

    Thank you.

    @wpublish2 Great do let us know if the function works?

    @wpublish2 The filter will be added to get_site_urls().

    Here’s the updated method, with the filter wpo_preload_get_site_urls:

    /**
      * Check if sitemap exists then returns list of urls from sitemap file otherwise returns all posts urls.
      *
      * @return array
      */
    public function get_site_urls() {
    
    	if ($this->exists_sitemap_file() && (false !== ($urls = $this->get_sitemap_urls()))) {
    		$this->options->update_option('wpo_last_page_cache_preload_type', 'sitemap');
    	} else {
    		$urls = $this->get_post_urls();
    		$this->options->update_option('wpo_last_page_cache_preload_type', 'posts');
    	}
    
    	$this->log(sprintf(_n('%d url found.', '%d urls found.', count($urls), 'wp-optimize'), count($urls)));
    
    	/**
    	 * Filter the URLs which will be preloaded
    	 *
    	 * @param array $urls
    	 * @return array
    	 */
    	return apply_filters('wpo_preload_get_site_urls', $urls);
    }

    Marc

    Thread Starter wpublish2

    (@wpublish2)

    Yes, it works, thank you so much Marc and Harshad!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add URLs to the preload list or execute my PHP before automatic preload of URLs’ is closed to new replies.