Skip to content

Instantly share code, notes, and snippets.

@twfahey1
Created September 10, 2020 14:44
Show Gist options
  • Save twfahey1/0e3beae8e17b4f8d3aac591bae67d39f to your computer and use it in GitHub Desktop.
Save twfahey1/0e3beae8e17b4f8d3aac591bae67d39f to your computer and use it in GitHub Desktop.
Custom clear cache WP CLI plugin example
<?php
/*
Plugin Name: Custom clear cache
Description: Clears out the custom cache code
Author: Tyler Fahey
Version: 1.0.0
Author URI: https://tylerfahey.com
*/
class CCC_CLI {
/**
* Clears out the custom cache folder.
*
* @since 0.0.1
* @author Tyler Fahey
*/
public function clear() {
WP_CLI::line( 'Clearing out custom cache...' );
$files = glob('/files/cache/*'); // get all file names
foreach($files as $file){ // iterate files
if(is_file($file))
unlink($file); // delete file
}
WP_CLI::line( 'Done.' );
}
}
/**
* Registers our command when cli get's initialized.
*
* @since 1.0.0
* @author Tyler Fahey
*/
function ccc_cli_register_commands() {
WP_CLI::add_command( 'ccc', 'CCC_CLI' );
}
add_action( 'cli_init', 'ccc_cli_register_commands' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment