From 1ea3194c18fbff88d0898a487e01e80300855e6e Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Fri, 12 Sep 2025 21:06:24 +0700 Subject: [PATCH 1/6] Add namespace in the main file --- advanced-multi-block.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/advanced-multi-block.php b/advanced-multi-block.php index 51050f6..5de042f 100644 --- a/advanced-multi-block.php +++ b/advanced-multi-block.php @@ -13,6 +13,8 @@ * @package CreateBlock */ +namespace Advanced_Multi_Block; + if (! defined('ABSPATH') ) { exit; } From cf8757abed4a233f92817bdd2c288cfd6143cd3b Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Fri, 12 Sep 2025 21:07:44 +0700 Subject: [PATCH 2/6] Add `PLUGIN_DIR` and `PLUGIN_FILE` constants --- advanced-multi-block.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/advanced-multi-block.php b/advanced-multi-block.php index 5de042f..c06aa1b 100644 --- a/advanced-multi-block.php +++ b/advanced-multi-block.php @@ -18,6 +18,23 @@ if (! defined('ABSPATH') ) { exit; } +/** + * Define the directory path to the plugin file. + * + * This constant provides a convenient reference to the plugin's directory path, + * useful for including or requiring files quickly relative to the plugin's + * directory. + */ +const PLUGIN_DIR = __DIR__; + +/** + * Define the path to the plugin file. + * + * This path can be used in various contexts, such as managing the activation + * and deactivation processes, loading the plugin text domain, adding action + * links, and more. + */ +const PLUGIN_FILE = __FILE__; // Include Composer's autoload file. if ( file_exists( plugin_dir_path( __FILE__ ) . 'vendor/autoload.php' ) ) { From 992380cb2eed0023a0a1a56dce71d3d38d511a55 Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Fri, 12 Sep 2025 21:29:45 +0700 Subject: [PATCH 3/6] Remove `Plugin_Paths` and the namespaces from the array list --- advanced-multi-block.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/advanced-multi-block.php b/advanced-multi-block.php index c06aa1b..312ba7b 100644 --- a/advanced-multi-block.php +++ b/advanced-multi-block.php @@ -46,11 +46,10 @@ // Instantiate the classes. $advanced_multi_block_classes = array( - \Advanced_Multi_Block\Plugin_Paths::class, - \Advanced_Multi_Block\Register_Blocks::class, - \Advanced_Multi_Block\Enqueues::class, + Register_Blocks::class, + Enqueues::class, ); foreach ( $advanced_multi_block_classes as $advanced_multi_block_class ) { new $advanced_multi_block_class(); -} \ No newline at end of file +} From 53f1031512d3d35bea1e855372bf1a64c936706a Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Fri, 12 Sep 2025 21:30:55 +0700 Subject: [PATCH 4/6] Use `__DIR__` to require the autoload file --- advanced-multi-block.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/advanced-multi-block.php b/advanced-multi-block.php index 312ba7b..5114d16 100644 --- a/advanced-multi-block.php +++ b/advanced-multi-block.php @@ -18,6 +18,14 @@ if (! defined('ABSPATH') ) { exit; } +// Include Composer's autoload file. +if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { + require_once __DIR__ . '/vendor/autoload.php'; +} else { + wp_trigger_error( 'Advanced Multi Block Plugin: Composer autoload file not found. Please run `composer install`.', E_USER_ERROR ); + return; +} + /** * Define the directory path to the plugin file. * @@ -36,14 +44,6 @@ */ const PLUGIN_FILE = __FILE__; -// Include Composer's autoload file. -if ( file_exists( plugin_dir_path( __FILE__ ) . 'vendor/autoload.php' ) ) { - require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; -} else { - wp_trigger_error( 'Advanced Multi Block Plugin: Composer autoload file not found. Please run `composer install`.', E_USER_ERROR ); - return; -} - // Instantiate the classes. $advanced_multi_block_classes = array( Register_Blocks::class, From 25d26f3b1c153ca4a0c8915f3a9ff80b740bdd78 Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Fri, 12 Sep 2025 21:32:28 +0700 Subject: [PATCH 5/6] Replace `Plugins_Paths` with constants --- Functions/Enqueues.php | 12 +++++------- Functions/Plugin_Paths.php | 16 ---------------- Functions/Register_Blocks.php | 12 +++++------- 3 files changed, 10 insertions(+), 30 deletions(-) delete mode 100644 Functions/Plugin_Paths.php diff --git a/Functions/Enqueues.php b/Functions/Enqueues.php index d3599ee..8905813 100644 --- a/Functions/Enqueues.php +++ b/Functions/Enqueues.php @@ -2,8 +2,6 @@ namespace Advanced_Multi_Block; -use Advanced_Multi_Block\Plugin_Paths; - if ( ! defined( 'ABSPATH' ) ) { exit; } @@ -18,11 +16,11 @@ public function __construct() { * Enqueues the block assets for the editor */ public function enqueue_block_assets() { - $asset_file = include Plugin_Paths::plugin_path() . 'build/editor-script.asset.php'; + $asset_file = include PLUGIN_DIR . '/build/editor-script.asset.php'; wp_enqueue_script( 'editor-script-js', - Plugin_Paths::plugin_url() . 'build/editor-script.js', + plugin_dir_url( PLUGIN_FILE ) . 'build/editor-script.js', $asset_file['dependencies'], $asset_file['version'], false @@ -33,14 +31,14 @@ public function enqueue_block_assets() { * Enqueues the block assets for the frontend */ public function enqueue_frontend_assets() { - $asset_file = include Plugin_Paths::plugin_path() . 'build/frontend-script.asset.php'; + $asset_file = include PLUGIN_DIR . '/build/frontend-script.asset.php'; wp_enqueue_script( 'frontend-script-js', - Plugin_Paths::plugin_url() . 'build/frontend-script.js', + plugin_dir_url( PLUGIN_FILE ) . 'build/frontend-script.js', $asset_file['dependencies'], $asset_file['version'], true ); } -} \ No newline at end of file +} diff --git a/Functions/Plugin_Paths.php b/Functions/Plugin_Paths.php deleted file mode 100644 index 7876ffd..0000000 --- a/Functions/Plugin_Paths.php +++ /dev/null @@ -1,16 +0,0 @@ - Date: Fri, 12 Sep 2025 21:32:34 +0700 Subject: [PATCH 6/6] Update Composer --- vendor/composer/installed.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index f35b388..c2992a7 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => 'wp-dev-blog/refactor-multi-block-plugin', 'pretty_version' => 'dev-trunk', 'version' => 'dev-trunk', - 'reference' => '500112a2822315caeaf450797e0e8471f83e37ad', + 'reference' => 'cf8757abed4a233f92817bdd2c288cfd6143cd3b', 'type' => 'wordpress-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -58,7 +58,7 @@ 'wp-dev-blog/refactor-multi-block-plugin' => array( 'pretty_version' => 'dev-trunk', 'version' => 'dev-trunk', - 'reference' => '500112a2822315caeaf450797e0e8471f83e37ad', + 'reference' => 'cf8757abed4a233f92817bdd2c288cfd6143cd3b', 'type' => 'wordpress-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(),