PluginProbe
Plugin Check (PCP) / trunk
Plugin Check (PCP) vtrunk
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 / includes / Checker / Default_Check_Repository.php

Default_Check_Repository.php in Plugin Check (PCP) trunk, at includes/Checker/Default_Check_Repository.php

116 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class WordPress\Plugin_Check\Checker\Default_Check_Repository
4 *
5 * @package plugin-check
6 */
7
8 namespace WordPress\Plugin_Check\Checker;
9
10 /**
11 * Default Check Repository class.
12 *
13 * @since 1.0.0
14 */
15 class Default_Check_Repository extends Empty_Check_Repository {
16
17 /**
18 * True if the class was fully initialized.
19 *
20 * If the class is instantiated before plugins are loaded, this will be set to false.
21 * This way the checks will be re-initialized once plugins have been loaded, and only then it is set to true.
22 *
23 * @since 1.3.0
24 * @var bool
25 */
26 protected $fully_initialized;
27
28 /**
29 * Initializes checks.
30 *
31 * @since 1.0.0
32 */
33 public function __construct() {
34 $this->fully_initialized = did_action( 'plugins_loaded' ) > 0;
35 $this->register_default_checks();
36 }
37
38 /**
39 * Returns an array of checks.
40 *
41 * @since 1.0.0
42 *
43 * @param int $flags The check type flag.
44 * @return Check_Collection Check collection providing an indexed array of check instances.
45 */
46 public function get_checks( $flags = self::TYPE_ALL ) {
47 // Once plugins have been loaded, re-initialize the checks.
48 if ( ! $this->fully_initialized && did_action( 'plugins_loaded' ) ) {
49 $this->fully_initialized = true;
50 $this->runtime_checks = array();
51 $this->static_checks = array();
52 $this->register_default_checks();
53 }
54
55 return parent::get_checks( $flags );
56 }
57
58 /**
59 * Registers Checks.
60 *
61 * @since 1.0.0
62 */
63 private function register_default_checks() {
64 /**
65 * Filters the available plugin check classes.
66 *
67 * @since 1.0.0
68 *
69 * @param array $checks An array map of check slugs to Check instances.
70 */
71 $checks = apply_filters(
72 'wp_plugin_check_checks',
73 array(
74 'i18n_usage' => new Checks\General\I18n_Usage_Check(),
75 'php_error_reporting' => new Checks\General\PHP_Error_Reporting_Check(),
76 'enqueued_scripts_size' => new Checks\Performance\Enqueued_Scripts_Size_Check(),
77 'enqueued_styles_size' => new Checks\Performance\Enqueued_Styles_Size_Check(),
78 'code_obfuscation' => new Checks\Plugin_Repo\Code_Obfuscation_Check(),
79 'plugin_content' => new Checks\Plugin_Repo\Plugin_Content_Check(),
80 'file_type' => new Checks\Plugin_Repo\File_Type_Check(),
81 'plugin_header_fields' => new Checks\Plugin_Repo\Plugin_Header_Fields_Check(),
82 'late_escaping' => new Checks\Security\Late_Escaping_Check(),
83 'safe_redirect' => new Checks\Security\Safe_Redirect_Check(),
84 'plugin_updater' => new Checks\Plugin_Repo\Plugin_Updater_Check(),
85 'plugin_uninstall' => new Checks\Plugin_Repo\Plugin_Uninstall_Check(),
86 'plugin_review_phpcs' => new Checks\Plugin_Repo\Plugin_Review_PHPCS_Check(),
87 'direct_db_queries' => new Checks\Security\Direct_DB_Queries_Check(),
88 'performant_wp_query_params' => new Checks\Performance\Performant_WP_Query_Params_Check(),
89 'enqueued_scripts_in_footer' => new Checks\Performance\Enqueued_Scripts_In_Footer_Check(),
90 'enqueued_resources' => new Checks\Performance\Enqueued_Resources_Check(),
91 'plugin_readme' => new Checks\Plugin_Repo\Plugin_Readme_Check(),
92 'enqueued_styles_scope' => new Checks\Performance\Enqueued_Styles_Scope_Check(),
93 'enqueued_scripts_scope' => new Checks\Performance\Enqueued_Scripts_Scope_Check(),
94 'localhost' => new Checks\Plugin_Repo\Localhost_Check(),
95 'no_unfiltered_uploads' => new Checks\Plugin_Repo\No_Unfiltered_Uploads_Check(),
96 'trademarks' => new Checks\Plugin_Repo\Trademarks_Check(),
97 'non_blocking_scripts' => new Checks\Performance\Non_Blocking_Scripts_Check(),
98 'offloading_files' => new Checks\Plugin_Repo\Offloading_Files_Check(),
99 'write_file' => new Checks\Plugin_Repo\Write_File_Check(),
100 'setting_sanitization' => new Checks\Plugin_Repo\Setting_Sanitization_Check(),
101 'prefixing' => new Checks\Plugin_Repo\Prefixing_Check(),
102 'direct_db' => new Checks\Security\Direct_DB_Check(),
103 'minified_files' => new Checks\Plugin_Repo\Minified_Files_Check(),
104 'direct_file_access' => new Checks\Plugin_Repo\Direct_File_Access_Check(),
105 'external_admin_menu_links' => new Checks\Plugin_Repo\External_Admin_Menu_Links_Check(),
106 'wp_functions_compatibility' => new Checks\Plugin_Repo\WP_Functions_Compatibility_Check(),
107 'ai_provider' => new Checks\General\AI_Provider_Check(),
108 )
109 );
110
111 foreach ( $checks as $slug => $check ) {
112 $this->register_check( $slug, $check );
113 }
114 }
115 }
116