| @@ -1,107 +1,82 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Plugin Name: Plugin Check | |
| 4 | - * Plugin URI: https://github.com/10up/plugin-check/ | |
| 5 | - * Description: Runs checks against a plugin to verify the latest WordPress standards and practices. | |
| 6 | - * Author: Plugin Review Team | |
| 7 | - * Version: 0.2.1 | |
| 3 | + * Plugin Name: Plugin Check (PCP) | |
| 4 | + * Plugin URI: https://github.com/WordPress/plugin-check | |
| 5 | + * Description: Plugin Check is a WordPress.org tool which provides checks to help plugins meet the directory requirements and follow various best practices. | |
| 6 | + * Requires at least: 6.3 | |
| 7 | + * Requires PHP: 7.4 | |
| 8 | + * Version: 2.1.0 | |
| 9 | + * Author: WordPress Performance Team and Plugins Team | |
| 10 | + * License: GPLv2 or later | |
| 11 | + * License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html | |
| 8 | 12 | * Text Domain: plugin-check |
| 9 | - * License: GPLv2 | |
| 10 | - * License URI: https://www.gnu.org/licenses/gpl-2.0.html | |
| 13 | + * | |
| 14 | + * @package plugin-check | |
| 11 | 15 | */ |
| 12 | 16 | |
| 13 | -namespace WordPressdotorg\Plugin_Check; | |
| 14 | -use WordPressdotorg\Plugin_Directory\Readme\Parser as Readme_Parser; | |
| 17 | +use WordPress\Plugin_Check\Plugin_Main; | |
| 15 | 18 | |
| 16 | -const PLUGIN_DIR = __DIR__; | |
| 19 | +define( 'WP_PLUGIN_CHECK_VERSION', '2.1.0' ); | |
| 20 | +define( 'WP_PLUGIN_CHECK_MINIMUM_PHP', '7.4' ); | |
| 21 | +define( 'WP_PLUGIN_CHECK_MAIN_FILE', __FILE__ ); | |
| 22 | +define( 'WP_PLUGIN_CHECK_PLUGIN_DIR_PATH', plugin_dir_path( WP_PLUGIN_CHECK_MAIN_FILE ) ); | |
| 23 | +define( 'WP_PLUGIN_CHECK_PLUGIN_DIR_URL', plugin_dir_url( WP_PLUGIN_CHECK_MAIN_FILE ) ); | |
| 17 | 24 | |
| 18 | 25 | /** |
| 19 | - * The current version of the plugin. | |
| 26 | + * Checks basic requirements and loads the plugin. | |
| 20 | 27 | * |
| 21 | 28 | * @since 1.0.0 |
| 22 | - * | |
| 23 | - * @var string | |
| 24 | 29 | */ |
| 25 | -const PLUGIN_CHECK_VERSION = '0.2.1'; | |
| 30 | +function wp_plugin_check_load() { | |
| 31 | + // Check for supported PHP version. | |
| 32 | + if ( version_compare( phpversion(), WP_PLUGIN_CHECK_MINIMUM_PHP, '<' ) ) { | |
| 33 | + add_action( 'admin_notices', 'wp_plugin_check_display_php_version_notice' ); | |
| 34 | + return; | |
| 35 | + } | |
| 26 | 36 | |
| 27 | -include __DIR__ . '/export.php'; | |
| 28 | -include __DIR__ . '/message.php'; | |
| 29 | -include __DIR__ . '/checks/check-base.php'; | |
| 37 | + // Check Composer autoloader exists. | |
| 38 | + if ( ! file_exists( WP_PLUGIN_CHECK_PLUGIN_DIR_PATH . 'vendor/autoload.php' ) ) { | |
| 39 | + add_action( 'admin_notices', 'wp_plugin_check_display_composer_autoload_notice' ); | |
| 40 | + return; | |
| 41 | + } | |
| 30 | 42 | |
| 31 | -define( | |
| 32 | - __NAMESPACE__ . '\HAS_VENDOR', | |
| 33 | - file_exists( __DIR__ . '/vendor/autoload.php' ) | |
| 34 | -); | |
| 35 | -if ( HAS_VENDOR ) { | |
| 36 | - include __DIR__ . '/vendor/autoload.php'; | |
| 43 | + // Load the Composer autoloader. | |
| 44 | + require_once WP_PLUGIN_CHECK_PLUGIN_DIR_PATH . 'vendor/autoload.php'; | |
| 45 | + | |
| 46 | + // Setup the plugin. | |
| 47 | + $instance = new Plugin_Main( WP_PLUGIN_CHECK_MAIN_FILE ); | |
| 48 | + $instance->add_hooks(); | |
| 37 | 49 | } |
| 38 | 50 | |
| 39 | 51 | /** |
| 40 | - * Load the Administration UI. | |
| 52 | + * Displays admin notice about unmet PHP version requirement. | |
| 53 | + * | |
| 54 | + * @since 1.0.0 | |
| 41 | 55 | */ |
| 42 | -add_action( 'admin_menu', function() { | |
| 43 | - require __DIR__ . '/admin/admin.php'; | |
| 44 | -}, 1 ); | |
| 56 | +function wp_plugin_check_display_php_version_notice() { | |
| 57 | + echo '<div class="notice notice-error"><p>'; | |
| 58 | + printf( | |
| 59 | + /* translators: 1: required version, 2: currently used version */ | |
| 60 | + esc_html__( 'Plugin Check requires at least PHP version %1$s. Your site is currently running on PHP %2$s.', 'plugin-check' ), | |
| 61 | + esc_html( WP_PLUGIN_CHECK_MINIMUM_PHP ), | |
| 62 | + esc_html( phpversion() ) | |
| 63 | + ); | |
| 64 | + echo '</p></div>'; | |
| 65 | +} | |
| 45 | 66 | |
| 46 | 67 | /** |
| 47 | - * Run all checks against a plugin. | |
| 68 | + * Displays admin notice about missing Composer autoload files. | |
| 69 | + * | |
| 70 | + * @since 1.0.0 | |
| 48 | 71 | */ |
| 49 | -function run_all_checks( $args ) { | |
| 50 | - if ( is_string( $args ) ) { | |
| 51 | - $args = [ | |
| 52 | - 'path' => $args | |
| 53 | - ]; | |
| 54 | - } | |
| 55 | - | |
| 56 | - $args = wp_parse_args( | |
| 57 | - $args, | |
| 58 | - [ | |
| 59 | - 'path' => '', | |
| 60 | - 'slug' => '', | |
| 61 | - 'readme' => false, | |
| 62 | - 'headers' => false, | |
| 63 | - 'plugin_file' => false, | |
| 64 | - 'files' => [], | |
| 65 | - ] | |
| 72 | +function wp_plugin_check_display_composer_autoload_notice() { | |
| 73 | + echo '<div class="notice notice-error"><p>'; | |
| 74 | + printf( | |
| 75 | + /* translators: composer command. */ | |
| 76 | + esc_html__( 'Your installation of the Plugin Check plugin is incomplete. Please run %s.', 'plugin-check' ), | |
| 77 | + '<code>composer install</code>' | |
| 66 | 78 | ); |
| 79 | + echo '</p></div>'; | |
| 80 | +} | |
| 67 | 81 | |
| 68 | - $args['path'] = trailingslashit( $args['path'] ); | |
| 69 | - $args['slug'] = $args['slug'] ?: basename( $args['path'] ); | |
| 70 | - | |
| 71 | - $top_level_files = glob( $args['path'] . '*' ); | |
| 72 | - | |
| 73 | - if ( ! $args['headers'] ) { | |
| 74 | - $php_files = preg_grep( '!\.php$!i', $top_level_files ); | |
| 75 | - foreach ( $php_files as $plugin_file ) { | |
| 76 | - $file_headers = get_plugin_data( $plugin_file, false, false ); | |
| 77 | - | |
| 78 | - if ( ! empty( $file_headers['Name'] ) ) { | |
| 79 | - $args['headers'] = $file_headers; | |
| 80 | - $args['plugin_file'] = $plugin_file; | |
| 81 | - break; | |
| 82 | - } | |
| 83 | - } | |
| 84 | - } | |
| 85 | - | |
| 86 | - if ( ! $args['readme'] ) { | |
| 87 | - $readme_txt = preg_grep( '!(^|/)readme.txt$!i', $top_level_files ); | |
| 88 | - $readme_md = preg_grep( '!(^|/)readme.md$!i', $top_level_files ); | |
| 89 | - if ( ! empty( $readme_txt ) ) { | |
| 90 | - $args['readme'] = new Readme_Parser( end( $readme_txt ) ); | |
| 91 | - } elseif ( ! empty( $readme_md ) ) { | |
| 92 | - $args['readme'] = new Readme_Parser( end( $readme_md ) ); | |
| 93 | - } | |
| 94 | - } | |
| 95 | - | |
| 96 | - if ( ! $args['files'] ) { | |
| 97 | - $args['files'] = []; | |
| 98 | - foreach ( new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( $args['path'] ) ) as $file ) { | |
| 99 | - if ( $file->isFile() ) { | |
| 100 | - $args['files'][] = substr( $file->getPathname(), strlen( $args['path'] ) ); | |
| 101 | - } | |
| 102 | - } | |
| 103 | - sort( $args['files'] ); | |
| 104 | - } | |
| 105 | - | |
| 106 | - return Checks\Check_Base::run_checks( $args ) ?: true; | |
| 107 | -} | |
| 82 | +wp_plugin_check_load(); | |