PluginProbe
Plugin Check (PCP) / 1.0.2
Plugin Check (PCP) v1.0.2
2.1.0 trunk 0.1 0.2.0 0.2.1 0.2.2 0.2.3 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.3.0 1.3.1 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 ci-artifacts
plugin-check / cli.php

cli.php in Plugin Check (PCP) 1.0.2, at cli.php

57 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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