To add additional target URLs in the sunny plugin. The main use of sunny plugin is for purging of “full page cache” upon the occurrence of different instances.

There are 2 types of URLs in the sunny plugin

  1. Related URL: The set of URLs which should be purged on update/edit/create any content or post on the website. Eg. categories pages.
  2. Target URL: This is the URL which is purged “every time” any of the content is updated. By default, the plugin only contains the site URL i.e the homepage of the website.

Locate the following file in your website files :

Purger.php

File location : public_html/wp-content/plugins/sunny/src/Caches/Purger.php

Replace public_html with your website home directory. Also,  need to modify a function in this file.

public function execute(PurgeCommand $command)
    {
        $randomNoticeId = 'sunny_purger_execute_' . wp_hash(date('c') . random_int(10, 15));

        // Translators: %1$s is the reason to purge.
        $noticeMessageFormat = __('<b>Sunny</b>: Purge initiated.<br/>Reason: %1$s', 'sunny');
        $noticeMessage = sprintf(
            $noticeMessageFormat,
            $command->getReason()
        );

        $this->notifier->enqueue($randomNoticeId, $noticeMessage);

        $batches = array_chunk(
            $command->getUrls(),
            30
        );

        foreach ($batches as $batch) {
            $this->cache->purgeFiles(
                ...$batch
            );
        
        }
        
        // <---altered by instainternet 
       //Add your extra target URL here      
        $custom_url = "https://www.instainternet.com/";
        $this->cache->purgeFiles($custom_url);
        //-----done-----> 
    }

Save the file! If you have more target URLs then simply add the same set of code or can make an array of custom_url for the set of URLs.

Basically, the purgeFiles function is called for purging the set of URLs which are usually defined in the batch variable. We added extra code to purge the URL by calling the same function with our extra target URL.

 

Leave a Comment

Your email address will not be published. Required fields are marked *