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 / Plugin_Main.php

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

92 lines 2.0 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\Plugin_Main
4 *
5 * @package plugin-check
6 */
7
8 namespace WordPress\Plugin_Check;
9
10 use WordPress\Plugin_Check\Admin\Admin_AJAX;
11 use WordPress\Plugin_Check\Admin\Admin_Page;
12 use WordPress\Plugin_Check\Admin\Settings_Page;
13 use WordPress\Plugin_Check\Admin\SVN_Checker_Page;
14
15 /**
16 * Main class for the plugin.
17 *
18 * @since 1.0.0
19 */
20 class Plugin_Main {
21
22 /**
23 * Context instance for the plugin.
24 *
25 * @since 1.0.0
26 * @var Plugin_Context
27 */
28 protected $context;
29
30 /**
31 * Constructor. Set the plugin main file.
32 *
33 * @since 1.0.0
34 *
35 * @param string $main_file Absolute path of the plugin main file.
36 */
37 public function __construct( $main_file ) {
38 $this->context = new Plugin_Context( $main_file );
39 }
40
41 /**
42 * Returns the Plugin Context.
43 *
44 * @since 1.0.0
45 *
46 * @return Plugin_Context
47 */
48 public function context() {
49 return $this->context;
50 }
51
52 /**
53 * Registers WordPress hooks for the plugin.
54 *
55 * @since 1.0.0
56 *
57 * @global Plugin_Context $context The plugin context instance.
58 */
59 public function add_hooks() {
60 // Initialize AI Client on init hook if the class exists.
61 if ( class_exists( '\WordPress\AI_Client\AI_Client' ) ) {
62 add_action( 'init', array( '\WordPress\AI_Client\AI_Client', 'init' ) );
63 }
64
65 if ( defined( 'WP_CLI' ) && WP_CLI ) {
66 global $context;
67
68 // Setup the CLI command.
69 $context = $this->context();
70 require_once WP_PLUGIN_CHECK_PLUGIN_DIR_PATH . 'cli.php';
71 }
72
73 $admin_ajax = new Admin_AJAX();
74 // Create the Admin page.
75 $admin_page = new Admin_Page( $admin_ajax );
76 $admin_page->add_hooks();
77
78 // Create the Settings page.
79 $settings_page = new Settings_Page();
80 $settings_page->add_hooks();
81
82 // Create the Plugin Check Namer tool page.
83 $namer_page_class = '\\WordPress\\Plugin_Check\\Admin\\Namer_Page';
84 $namer_page = new $namer_page_class();
85 $namer_page->add_hooks();
86
87 // Create the SVN Checker page.
88 $svn_checker_page = new SVN_Checker_Page();
89 $svn_checker_page->add_hooks();
90 }
91 }
92