Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions Functions/Enqueues.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Advanced_Multi_Block;

use Advanced_Multi_Block\Plugin_Paths;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Expand All @@ -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
Expand All @@ -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
);
}
}
}
16 changes: 0 additions & 16 deletions Functions/Plugin_Paths.php

This file was deleted.

12 changes: 5 additions & 7 deletions Functions/Register_Blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Advanced_Multi_Block;

use Advanced_Multi_Block\Plugin_Paths;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Expand All @@ -15,17 +13,17 @@ public function __construct() {

public function register_blocks() {
if ( function_exists( 'wp_register_block_types_from_metadata_collection' ) ) {
wp_register_block_types_from_metadata_collection( Plugin_Paths::plugin_path() . 'build/blocks', Plugin_Paths::plugin_path() . '/build/blocks-manifest.php' );
wp_register_block_types_from_metadata_collection( PLUGIN_DIR . '/build/blocks', PLUGIN_DIR . '/build/blocks-manifest.php' );
return;
}

if ( function_exists( 'wp_register_block_metadata_collection' ) ) {
wp_register_block_metadata_collection( Plugin_Paths::plugin_path() . 'build/blocks', Plugin_Paths::plugin_path() . '/build/blocks-manifest.php' );
wp_register_block_metadata_collection( PLUGIN_DIR . '/build/blocks', PLUGIN_DIR . '/build/blocks-manifest.php' );
}

$manifest_data = include Plugin_Paths::plugin_path() . 'build/blocks-manifest.php';
$manifest_data = include PLUGIN_DIR . '/build/blocks-manifest.php';
foreach ( array_keys( $manifest_data ) as $block_type ) {
register_block_type( Plugin_Paths::plugin_path() . "build/blocks/{$block_type}" );
register_block_type( PLUGIN_DIR . "/build/blocks/{$block_type}" );
}
}
}
}
32 changes: 25 additions & 7 deletions advanced-multi-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,43 @@
* @package CreateBlock
*/

namespace Advanced_Multi_Block;

if (! defined('ABSPATH') ) {
exit;
}

// Include Composer's autoload file.
if ( file_exists( plugin_dir_path( __FILE__ ) . 'vendor/autoload.php' ) ) {
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
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.
*
* 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__;

// 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,
Comment on lines +49 to +50
Copy link
Author

@tfirdaus tfirdaus Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the plugin namespace in the main file, so it's no longer necessary to reference the class with the full namespace.

Also, the Plugin_Paths file has been removed and replaced with constants when referring to the plugin directory or file. If we decide to keep the class, I don't think it needs to be included in the list or instantiated, since it only contains static methods since Composer will still autoload it when those methods are called.

);

foreach ( $advanced_multi_block_classes as $advanced_multi_block_class ) {
new $advanced_multi_block_class();
}
}
4 changes: 2 additions & 2 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down