From c1cd6782579feb5a3e51df8ff687ca679e9e5778 Mon Sep 17 00:00:00 2001 From: eliot-akira Date: Fri, 21 Feb 2025 19:26:23 +0100 Subject: [PATCH] Support using module URL outside plugins folder during development --- admin/system.php | 5 +++-- core.php | 3 ++- editor/index.php | 3 ++- .../beaver/modules/tangible-template/tangible-template.php | 3 ++- language/index.php | 7 ++++--- loop/index.php | 4 +++- modules/codemirror-v5/index.php | 3 ++- modules/logic-v1/index.php | 3 ++- modules/mermaid/index.php | 3 ++- modules/module-loader/index.php | 3 ++- view/index.php | 3 ++- 11 files changed, 26 insertions(+), 14 deletions(-) diff --git a/admin/system.php b/admin/system.php index 7ae83cd5..7f8b11b5 100644 --- a/admin/system.php +++ b/admin/system.php @@ -2,8 +2,9 @@ /** * The System module is being replaced by new code organization in ../core.php. */ -use tangible\template_system; use tangible\date; +use tangible\framework; +use tangible\template_system; if (!function_exists('tangible_template_system')) { function tangible_template_system( $arg = false ) { @@ -27,7 +28,7 @@ function load() { $this->path = __DIR__; $this->file_path = __FILE__; // Keep trailing slash for backward compatibility - $this->url = plugins_url('/', __FILE__); + $this->url = trailingslashit( framework\module_url( __FILE__ ) ); tangible_template_system( $this ); $system = $plugin = $this; diff --git a/core.php b/core.php index 8c6a005b..3d295abd 100644 --- a/core.php +++ b/core.php @@ -12,6 +12,7 @@ */ namespace tangible; +use tangible\framework; class template_system { @@ -26,7 +27,7 @@ class template_system { template_system::$state = (object) [ 'version' => '20250125', // Automatically updated with npm run version 'path' => __DIR__, - 'url' => untrailingslashit( plugins_url( '/', __FILE__ ) ), + 'url' => framework\module_url( __FILE__ ), ]; template_system::$system = $plugin = $system; // From /admin/system diff --git a/editor/index.php b/editor/index.php index f30ce63c..349cfc41 100644 --- a/editor/index.php +++ b/editor/index.php @@ -4,6 +4,7 @@ */ namespace tangible\template_system; +use tangible\framework; use tangible\template_system; use tangible\template_system\editor; @@ -15,7 +16,7 @@ class editor { editor::$html = tangible_template(); editor::$state = (object) [ 'version' => template_system::$state->version, - 'url' => untrailingslashit( plugins_url('/', __FILE__) ), + 'url' => framework\module_url( __FILE__ ), ]; require_once __DIR__.'/enqueue.php'; diff --git a/integrations/beaver/modules/tangible-template/tangible-template.php b/integrations/beaver/modules/tangible-template/tangible-template.php index 288c6f29..52c10d52 100644 --- a/integrations/beaver/modules/tangible-template/tangible-template.php +++ b/integrations/beaver/modules/tangible-template/tangible-template.php @@ -1,5 +1,6 @@ true, 'icon' => 'editor-code.svg', 'dir' => __DIR__, - 'url' => plugins_url( '/', __FILE__ ) + 'url' => trailingslashit( framework\module_url( __FILE__ ) ) ]; /** diff --git a/language/index.php b/language/index.php index fee1d048..aa0424ee 100644 --- a/language/index.php +++ b/language/index.php @@ -9,11 +9,12 @@ * from /framework and /modules. */ -use tangible\template_system; use tangible\ajax; use tangible\date; -use tangible\select; +use tangible\framework; use tangible\html; +use tangible\select; +use tangible\template_system; if ( ! function_exists( 'tangible_template' ) ) : function tangible_template( $arg = false ) { @@ -50,7 +51,7 @@ function __construct() { $html->path = __DIR__; $html->file_path = __FILE__; - $html->url = untrailingslashit(plugins_url('/', __FILE__)); + $html->url = framework\module_url( __FILE__ ); $html->version = $this->version; /** diff --git a/loop/index.php b/loop/index.php index 0ca85c6f..c5035982 100644 --- a/loop/index.php +++ b/loop/index.php @@ -1,4 +1,6 @@ path = __DIR__; $loop->file_path = __FILE__; - $loop->url = untrailingslashit(plugins_url('/', __FILE__)); + $loop->url = framework\module_url( __FILE__ ); tangible_loop( $this ); diff --git a/modules/codemirror-v5/index.php b/modules/codemirror-v5/index.php index 9c51ca14..842d95a7 100644 --- a/modules/codemirror-v5/index.php +++ b/modules/codemirror-v5/index.php @@ -1,9 +1,10 @@ path = __DIR__; $this->file_path = __FILE__; - $this->url = untrailingslashit(plugins_url('/', __FILE__)); + $this->url = framework\module_url( __FILE__ ); // Backward compatibility $this->state['url'] = $this->url; diff --git a/modules/mermaid/index.php b/modules/mermaid/index.php index 8c166beb..ebb0acc6 100644 --- a/modules/mermaid/index.php +++ b/modules/mermaid/index.php @@ -6,6 +6,7 @@ * @see https://github.com/mermaid-js/mermaid */ namespace tangible\template_system\mermaid; +use tangible\framework; use tangible\template_system; function register() { @@ -44,7 +45,7 @@ function enqueue() { function register_mermaid_script() { - $url = untrailingslashit(plugins_url('/', __FILE__)) . '/build'; + $url = framework\module_url( __FILE__ ) . '/build'; $version = template_system::$state->version; wp_register_script( diff --git a/modules/module-loader/index.php b/modules/module-loader/index.php index 27fabca3..05b849c1 100644 --- a/modules/module-loader/index.php +++ b/modules/module-loader/index.php @@ -13,6 +13,7 @@ */ namespace tangible\template_system\module_loader; +use tangible\framework; use tangible\template_system; use tangible\template_system\module_loader; @@ -43,7 +44,7 @@ function enqueue() { $html->module_loader_script_registered = true; - $url = untrailingslashit(plugins_url('/', __FILE__)) . '/build'; + $url = framework\module_url( __FILE__ ) . '/build'; $version = template_system::$state->version; wp_register_script( diff --git a/view/index.php b/view/index.php index b81c76b6..fe6d25f4 100644 --- a/view/index.php +++ b/view/index.php @@ -4,6 +4,7 @@ */ namespace tangible\template_system; +use tangible\framework; use tangible\template_system; use tangible\template_system\view; @@ -13,7 +14,7 @@ class view { view::$state = (object) [ 'version' => template_system::$state->version, - 'url' => untrailingslashit( plugins_url('/', __FILE__) ), + 'url' => framework\module_url( __FILE__ ), ]; require_once __DIR__ . '/admin.php';