PluginProbe
Plugin Check (PCP) / 0.2.1
Plugin Check (PCP) v0.2.1
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 / plugin.php

plugin.php in Plugin Check (PCP) 0.2.1, at plugin.php

108 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
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
8 * Text Domain: plugin-check
9 * License: GPLv2
10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
11 */
12
13 namespace WordPressdotorg\Plugin_Check;
14 use WordPressdotorg\Plugin_Directory\Readme\Parser as Readme_Parser;
15
16 const PLUGIN_DIR = __DIR__;
17
18 /**
19 * The current version of the plugin.
20 *
21 * @since 1.0.0
22 *
23 * @var string
24 */
25 const PLUGIN_CHECK_VERSION = '0.2.1';
26
27 include __DIR__ . '/export.php';
28 include __DIR__ . '/message.php';
29 include __DIR__ . '/checks/check-base.php';
30
31 define(
32 __NAMESPACE__ . '\HAS_VENDOR',
33 file_exists( __DIR__ . '/vendor/autoload.php' )
34 );
35 if ( HAS_VENDOR ) {
36 include __DIR__ . '/vendor/autoload.php';
37 }
38
39 /**
40 * Load the Administration UI.
41 */
42 add_action( 'admin_menu', function() {
43 require __DIR__ . '/admin/admin.php';
44 }, 1 );
45
46 /**
47 * Run all checks against a plugin.
48 */
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 ]
66 );
67
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 }
108