Skip to content

Commit 29c8c31

Browse files
committed
chore: add main plugin.php boilerplate
1 parent 45f871d commit 29c8c31

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Main Plugin Class for WPGraphQL Debug Extensions.
4+
*
5+
* @package WPGraphQL\Debug
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace WPGraphQL\Debug;
11+
12+
use AxeWP\GraphQL\Helper\Helper;
13+
14+
/**
15+
* Plugin singleton class.
16+
*/
17+
if ( ! class_exists( 'WPGraphQL\Debug\Plugin' ) ) :
18+
19+
final class Plugin {
20+
21+
/**
22+
* Singleton instance.
23+
*
24+
* @var ?self
25+
*/
26+
private static ?self $instance = null;
27+
28+
/**
29+
* Get singleton instance.
30+
*
31+
* @return self
32+
*/
33+
public static function instance(): self {
34+
if ( ! isset( self::$instance ) ) {
35+
self::$instance = new self();
36+
self::$instance->includes();
37+
self::$instance->setup();
38+
}
39+
40+
/**
41+
* Plugin init action.
42+
*
43+
* @param self $instance
44+
*/
45+
do_action( 'graphql_debug_extensions_init', self::$instance );
46+
47+
return self::$instance;
48+
}
49+
50+
/**
51+
* Set up basic plugin components.
52+
* This method is intentionally minimal, serving as a scaffold.
53+
*/
54+
private function setup(): void {
55+
// Set the hook prefix for consistency across the plugin's actions/filters.
56+
// This can be used by other parts of the plugin if generic helpers are introduced.
57+
Helper::set_hook_prefix( 'graphql_debug_extensions' );
58+
}
59+
60+
/**
61+
* Include required files, specifically the Composer autoloader.
62+
*/
63+
private function includes(): void {
64+
// Check for the autoloader constant and plugin directory constant defined in the main plugin file.
65+
if (
66+
defined( 'WPGRAPHQL_DEBUG_EXTENSIONS_AUTOLOAD' )
67+
&& false !== WPGRAPHQL_DEBUG_EXTENSIONS_AUTOLOAD
68+
&& defined( 'WPGRAPHQL_DEBUG_EXTENSIONS_PLUGIN_DIR' )
69+
) {
70+
// Require the Composer autoloader.
71+
// This assumes 'vendor/autoload.php' exists relative to the plugin's root directory.
72+
require_once WPGRAPHQL_DEBUG_EXTENSIONS_PLUGIN_DIR . 'vendor/autoload.php';
73+
}
74+
}
75+
76+
/**
77+
* Prevent cloning.
78+
*/
79+
public function __clone() {
80+
_doing_it_wrong( __FUNCTION__, 'The plugin main class should not be cloned.', '0.0.1' );
81+
}
82+
/**
83+
* Prevent unserializing.
84+
*/
85+
public function __wakeup(): void {
86+
_doing_it_wrong( __FUNCTION__, 'De-serializing instances of the plugin main class is not allowed.', '0.0.1' );
87+
}
88+
}
89+
90+
endif;

plugins/wpgraphql-debug-extensions/wpgraphql-debug-extensions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ function wpgraphql_debug_extensions_init(): void {
109109
// Load text domain at the init hook
110110
add_action( 'init', 'WPGraphQL\Debug\wpgraphql_debug_extensions_load_textdomain' );
111111

112+
$plugin = new \WPGraphQL\Debug\Plugin();
113+
$plugin::instance();
112114
return;
113115
}
114116

0 commit comments

Comments
 (0)