PluginProbe
Plugin Check (PCP) / 1.7.0
Plugin Check (PCP) v1.7.0
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.7.0, at cli.php

87 lines 2.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(
38 'plugin',
39 $plugin_command,
40 array(
41 /**
42 * This is a cleanup for the below hook which adds the object-cache.php drop-in.
43 *
44 * It is executed right after the command ran.
45 *
46 * Since the drop-in could be from somewhere else, a check of its contents is necessary
47 * to verify it is the one that was added below.
48 */
49 'after_invoke' => function () {
50 if ( ! defined( 'WP_CONTENT_DIR' ) ) {
51 // Defines WP_CONTENT_DIR just in case it is not defined.
52 define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
53 }
54 if (
55 file_exists( WP_CONTENT_DIR . '/object-cache.php' ) &&
56 false !== strpos( file_get_contents( WP_CONTENT_DIR . '/object-cache.php' ), 'WP_PLUGIN_CHECK_OBJECT_CACHE_DROPIN_VERSION' )
57 ) {
58 unlink( WP_CONTENT_DIR . '/object-cache.php' );
59 }
60 },
61 )
62 );
63
64 /*
65 * Add hook to set up the object-cache.php drop-in file.
66 *
67 * Runs after wp-config.php is loaded and thus ABSPATH is defined,
68 * but before any plugins are actually loaded.
69 */
70 WP_CLI::add_hook(
71 'after_wp_config_load',
72 function () {
73 if ( ! defined( 'WP_CONTENT_DIR' ) ) {
74 // Defines WP_CONTENT_DIR just in case it is not defined.
75 define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
76 }
77
78 if ( CLI_Runner::is_plugin_check() ) {
79 if ( ! file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
80 if ( ! copy( __DIR__ . '/drop-ins/object-cache.copy.php', WP_CONTENT_DIR . '/object-cache.php' ) ) {
81 WP_CLI::error( 'Unable to copy object-cache.php file.' );
82 }
83 }
84 }
85 }
86 );
87