Table of Contents

MainWP Cache-Control Custom Addition

Adding Additional 3rd-Party Plugin Support

The MainWP Cache Control Extension itself is designed to give the ability to tap into a class file that actually lives within the MainWP Child Plugin. So in order to add additional support for other 3rd-party Cache Plugins – you simply need to add the correct hooks to the class-mainwp-child-cache-purge.php file & then perform a Pull request on GitHub. Our Development team will go over your code & then perform the merge within a future release. 

How to fork a repository, push to GitHub & perform a GitHub Pull Request is out of the scope of this tutorial. You may read how to perform these tasks here: 

About Forks

Pushing commits to a remote repository

Pushing changes to GitHub from GitHub Desktop

Creating a pull request

Steps to follow

  1. Fork the MainWP Child Plugin ( https://github.com/mainwp/mainwp-child/tree/master )
  2. Updating the class file
  3. Push your changes to your fork
  4. Perform a Pull Request on MainWP Child Master Branch

Information you will need to add 3rd-Party plugin support

  • Plugin folder/slug
  • Plugin Name
  • Plugin Purge Class ( if applicable )
  • Plugin Purge Method to call
'swis-performance/swis-performance.php'  =>  'Swis Performance', 

case 'Swis Performance':
$information = $this->swis_performance_auto_purge_cache();
break; 

swis_performance_auto_purge_cache()

This is our custom method that will finally fire off the custom purge action. Each new addition will be slightly different due to the nature of “custom methods”, however, there are only a few lines within each custom method that need to stay the same in order to function seamlessly with the MainWP Dashboard. 

We will need to have our $success_message & $error_message & $bypass-Message pre-written for when we return the purge_result() array once our plugin has purged its cache. 

You will usually need to check if the plugins class has been initialized in order to call its methods. This method first checks if the public `swis` function is loaded & callable –  If the public `swis` function is not found it will throw the error message – if it is found it will continue on with the operation…

Next it will grab the saved cache settings & check to see if the built-in auto-purge function is active, so that two cache purge routines are not run simultaneously. If the setting is not set it will proceed to fire off the ‘swis_clear_complete_cache’  action & then record / return the purge_result()  array.

/**
* Purge Swis Performance plugin cache.
*
* @return array Purge results array.
*/
public function swis_performance_auto_purge_cache() {

   $success_message = 'Swis Performance => Cache auto cleared on: (' . current_time( 'mysql' ) . ')';
   $error_message   = 'Swis Performance => There was an issue purging your cache.';
   $bypass_message  = 'Swis Performance => Purge was bypassed due to Swis Auto Purge Settings.';


    if ( is_callable( 'swis' ) ) {
       $swis_cache_settings = swis()->cache->get_settings();


       if ( empty( $swis_cache_settings['clear_complete_cache_on_changed_plugin'] ) ) {
           do_action( 'swis_clear_complete_cache' );
       } else {

            return $this->purge_result( $bypass_message, 'SUCCESS' );

        }


       // record results. ( below needs to stay untouched )
       update_option( 'mainwp_cache_control_last_purged', time() );
       return $this->purge_result( $success_message, 'SUCCESS' );
   } else {
       return $this->purge_result( $error_message, 'ERROR' );
   }
} 

Where is the data?

After everything has been added the newly supported plugin data should be available after a Re-Sync & First Purge. This data is automatically displayed on the Sites Management Page under the “Cache Solution” & “Last Purged Cache” columns as well as on the Extensions > Cache Control > Logs page as shown below.