Skip to content

Commit c88a566

Browse files
committed
Merge branch 'develop'
2 parents c8958d6 + 65a80de commit c88a566

5 files changed

Lines changed: 211 additions & 118 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"require": {
33
"ziorwebdev/wordpress-blocks": "^1.1"
44
}
5-
}
5+
}

composer.lock

Lines changed: 121 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/class-plugin.php

Lines changed: 54 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,159 +1,115 @@
11
<?php
22
/**
3-
* Main plugin controller class for SimpliBlocks.
3+
* Plugin bootstrap class for SimpliBlocks.
44
*
5-
* This class bootstraps the plugin, loads dependencies, sets up internationalization,
6-
* and initializes core services including the plugin updater.
5+
* This class is responsible for initializing the plugin by defining constants
6+
* and loading core services. It does not maintain runtime state and therefore
7+
* does not implement the singleton pattern.
78
*
89
* @package ZIORWebDev\SimpliBlocks
910
*/
1011

1112
namespace ZIORWebDev\SimpliBlocks;
1213

13-
use ZIORWebDev\WordPressBlocks;
14+
use ZIORWebDev\WordPressBlocks\Loader as BlocksLoader;
1415

1516
// Exit if accessed directly.
1617
if ( ! defined( 'ABSPATH' ) ) {
17-
exit();
18+
exit;
1819
}
1920

2021
/**
21-
* The core plugin class for SimpliBlocks.
22+
* Main plugin bootstrap class.
2223
*
23-
* Responsible for defining core constants, loading dependencies, setting up localization,
24-
* and initializing the plugin loader and updater.
24+
* Handles plugin initialization, constant definition, and service bootstrapping.
25+
* All methods are static to avoid unnecessary global instances.
2526
*
26-
* Implements the singleton pattern to ensure only one instance is used.
27-
*
28-
* @package ZIORWebDev\SimpliBlocks.
27+
* @since 1.0.0
2928
*/
3029
final class Plugin {
3130

32-
/**
33-
* Path to the main plugin file.
34-
*
35-
* @var string
36-
*/
37-
protected $plugin_file;
38-
39-
/**
40-
* Name of the plugin.
41-
*
42-
* @var string
43-
*/
44-
protected $plugin_name = '';
45-
46-
/**
47-
* Singleton instance of the Plugin class.
48-
*
49-
* @var Plugin
50-
*/
51-
protected static $instance;
52-
53-
/**
54-
* Current version of the plugin.
55-
*
56-
* @var string
57-
*/
58-
protected $plugin_version = '';
59-
60-
/**
61-
* Class constructor.
62-
*/
63-
private function __construct( string $plugin_file ) {
64-
$this->plugin_file = $plugin_file;
65-
}
66-
6731
/**
6832
* Initialize the plugin.
6933
*
70-
* Sets up constants, includes required files, and initializes the plugin updater.
34+
* Defines core constants and boots required services.
35+
* This method should be called once from the main plugin file.
7136
*
7237
* @since 1.0.0
38+
*
39+
* @param string $plugin_file Absolute path to the main plugin file.
7340
* @return void
7441
*/
75-
private function init(): void {
76-
$this->setup_constants();
77-
$this->include_classes();
78-
79-
/**
80-
* Load WordPress Blocks library.
81-
*/
82-
WordPressBlocks\Load::get_instance();
42+
public static function init( string $plugin_file ): void {
43+
self::define_constants( $plugin_file );
44+
self::init_services();
8345
}
8446

8547
/**
86-
* Include required plugin files.
48+
* Define plugin constants.
8749
*
88-
* Loads configuration, core functions, loader class, and the updater helper.
50+
* Constants are only defined once to prevent redefinition errors.
51+
* These constants are used throughout the plugin.
8952
*
9053
* @since 1.0.0
54+
*
55+
* @param string $plugin_file Absolute path to the main plugin file.
9156
* @return void
9257
*/
93-
private function include_classes(): void {
94-
require_once ZIOR_SIMPLIBLOCKS_PLUGIN_DIR . 'vendor/autoload.php';
58+
private static function define_constants( string $plugin_file ): void {
59+
define( 'ZIOR_SIMPLIBLOCKS_PLUGIN_FILE', $plugin_file );
60+
define( 'ZIOR_SIMPLIBLOCKS_PLUGIN_DIR', plugin_dir_path( $plugin_file ) );
61+
define( 'ZIOR_SIMPLIBLOCKS_PLUGIN_URL', plugin_dir_url( $plugin_file ) );
9562
}
9663

9764
/**
98-
* Defines plugin constants used throughout the plugin.
65+
* Boot core plugin services.
66+
*
67+
* Responsible for initializing external libraries, loaders,
68+
* and other core services required by the plugin.
9969
*
10070
* @since 1.0.0
71+
*
10172
* @return void
10273
*/
103-
private function setup_constants(): void {
104-
define( 'ZIOR_SIMPLIBLOCKS_PLUGIN_DIR', plugin_dir_path( $this->plugin_file ) );
105-
define( 'ZIOR_SIMPLIBLOCKS_PLUGIN_URL', plugin_dir_url( $this->plugin_file ) );
106-
define( 'ZIOR_SIMPLIBLOCKS_PLUGIN_FILE', $this->plugin_file );
107-
define( 'ZIOR_SIMPLIBLOCKS_PLUGIN_VERSION', $this->plugin_version );
74+
private static function init_services(): void {
75+
( new BlocksLoader() )->init();
10876
}
10977

11078
/**
111-
* Get the singleton instance of the Plugin class.
79+
* Plugin activation callback.
11280
*
113-
* @param string $plugin_file
114-
* @return Plugin
115-
* @since 1.0.0
116-
*/
117-
public static function get_instance( string $plugin_file ): Plugin {
118-
if ( is_null( self::$instance ) ) {
119-
self::$instance = new self( $plugin_file );
120-
self::$instance->init();
121-
}
122-
123-
return self::$instance;
124-
}
125-
126-
/**
127-
* Load the plugin textdomain.
81+
* Fires a custom action that other components can hook into
82+
* to perform activation-related tasks.
12883
*
129-
* @return void
13084
* @since 1.0.0
131-
*/
132-
public function load_textdomain(): void {
133-
load_plugin_textdomain(
134-
'zior-simpliblocks',
135-
false,
136-
ZIOR_SIMPLIBLOCKS_PLUGIN_DIR . '/languages/',
137-
);
138-
}
139-
140-
/**
141-
* Activate the plugin.
14285
*
14386
* @return void
144-
* @since 1.0.0
14587
*/
146-
public function activate_plugin(): void {
88+
public static function activate_plugin(): void {
89+
/**
90+
* Fires when the SimpliBlocks plugin is activated.
91+
*
92+
* @since 1.0.0
93+
*/
14794
do_action( 'zior_simpliblocks_activation' );
14895
}
14996

15097
/**
151-
* Deactivate the plugin.
98+
* Plugin deactivation callback.
99+
*
100+
* Fires a custom action that other components can hook into
101+
* to perform deactivation-related cleanup.
152102
*
153-
* @return void
154103
* @since 1.0.0
104+
*
105+
* @return void
155106
*/
156-
public function deactivate_plugin(): void {
107+
public static function deactivate_plugin(): void {
108+
/**
109+
* Fires when the SimpliBlocks plugin is deactivated.
110+
*
111+
* @since 1.0.0
112+
*/
157113
do_action( 'zior_simpliblocks_deactivation' );
158114
}
159115
}

0 commit comments

Comments
 (0)