-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.php
61 lines (50 loc) · 1.94 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* Plugin name: WordPress.org Code Analysis
* Description: Tools for analyzing plugin and theme code.
* Version: 0.1
* Author: WordPress.org
* Author URI: http://wordpress.org/
* License: GPLv2 or later
*/
namespace WordPressDotOrg\Code_Analysis;
defined( 'WPINC' ) || die();
define( __NAMESPACE__ . '\PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( __NAMESPACE__ . '\PLUGIN_URL', plugins_url( '/', __FILE__ ) );
/**
* Actions and filters.
*/
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_files' );
/**
* Load the other PHP files for the plugin.
*
* @return void
*/
function load_files() {
require PLUGIN_DIR . 'includes/class-phpcs.php';
require PLUGIN_DIR . 'includes/class-scanner.php';
require PLUGIN_DIR . 'admin/class-scan-metabox.php';
}
function register_admin_metabox( $post_type, $post ) {
if ( 'plugin' !== $post_type ) {
return;
}
// Only load the metabox if the plugin directory plugin is active
if ( !class_exists( '\WordPressDotOrg\Plugin_Directory\Plugin_Directory' ) ) {
return;
}
add_meta_box(
'code-scanner',
__( 'Code Scanner', 'wporg-plugins' ),
array( __NAMESPACE__ . '\Admin\Scan_Metabox', 'maybe_display_ajax' ),
'plugin', 'normal', 'high'
);
wp_enqueue_script( 'code-scan-metabox-js', plugins_url( 'admin/metabox.js', __FILE__ ), array( 'wp-util' ), 3 );
wp_enqueue_style( 'code-scan-metabox-css', plugins_url( 'admin/metabox.css', __FILE__ ), array(), 1 );
wp_enqueue_script( 'code-scan-prism-js', plugins_url( 'admin/prism.js', __FILE__ ), array(), 3 );
wp_enqueue_style( 'code-scan-prism-css', plugins_url( 'admin/prism.css', __FILE__ ), array(), 1 );
}
add_action( 'add_meta_boxes', __NAMESPACE__ . '\register_admin_metabox', 10, 2 );
add_filter( 'wp_ajax_scan-plugin', array( __NAMESPACE__ . '\Admin\Scan_Metabox', 'get_ajax_response' ) );
// TODO: Async this?
add_action( 'wporg_plugins_imported', array( __NAMESPACE__ . '\Scanner', 'scan_imported_plugin' ), 10, 5 );