| 1 |
<?php |
| 2 |
/** |
| 3 |
* Sets up the CLI command early in the WordPress load process. |
| 4 |
* |
| 5 |
* This is necessary to setup the environment to perform runtime checks. |
| 6 |
* |
| 7 |
* @package plugin-check |
| 8 |
* @since 1.0.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
use WordPress\Plugin_Check\Checker\CLI_Runner; |
| 12 |
use WordPress\Plugin_Check\CLI\Plugin_Check_Command; |
| 13 |
use WordPress\Plugin_Check\Plugin_Context; |
| 14 |
|
| 15 |
if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) { |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
// Check if the plugin autoloading is set up. |
| 20 |
if ( ! class_exists( 'WordPress\Plugin_Check\CLI\Plugin_Check_Command' ) ) { |
| 21 |
// Check the autoload file exists. |
| 22 |
if ( ! file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
| 23 |
WP_CLI::error( 'Plugin Check autoloader not found.' ); |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
// Load the Composer autoloader. |
| 28 |
require_once __DIR__ . '/vendor/autoload.php'; |
| 29 |
} |
| 30 |
|
| 31 |
if ( ! isset( $context ) ) { |
| 32 |
$context = new Plugin_Context( __DIR__ . '/plugin.php' ); |
| 33 |
} |
| 34 |
|
| 35 |
// Create the CLI command instance and add to WP CLI. |
| 36 |
$plugin_command = new Plugin_Check_Command( $context ); |
| 37 |
WP_CLI::add_command( 'plugin', $plugin_command ); |
| 38 |
|
| 39 |
|
| 40 |
/** |
| 41 |
* Adds hook to set up the object-cache.php drop-in file. |
| 42 |
* |
| 43 |
* @since 1.0.0 |
| 44 |
*/ |
| 45 |
WP_CLI::add_hook( |
| 46 |
'before_wp_load', |
| 47 |
function () { |
| 48 |
if ( CLI_Runner::is_plugin_check() ) { |
| 49 |
if ( ! file_exists( ABSPATH . 'wp-content/object-cache.php' ) ) { |
| 50 |
if ( ! copy( __DIR__ . '/drop-ins/object-cache.copy.php', ABSPATH . 'wp-content/object-cache.php' ) ) { |
| 51 |
WP_CLI::error( 'Unable to copy object-cache.php file.' ); |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
} |
| 56 |
); |
| 57 |
|