From 3bf185b6aff460403c3e80c8db30420993e75532 Mon Sep 17 00:00:00 2001 From: Miguel Lezama Date: Thu, 23 Mar 2023 13:13:27 -0300 Subject: [PATCH 1/4] Make it work when not installed under wp-content/plugins --- src/plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugin.php b/src/plugin.php index 7010528f..0271feff 100644 --- a/src/plugin.php +++ b/src/plugin.php @@ -64,5 +64,5 @@ function () { } function root_url(): string { - return plugins_url() . '/chatrix/build'; + return plugins_url( 'build/', dirname(__FILE__ ) ); } From 85fd531ffe0933477078dfcbfac653001c087c1f Mon Sep 17 00:00:00 2001 From: Ashfame Date: Fri, 24 Mar 2023 13:34:20 +0400 Subject: [PATCH 2/4] fix linter & remove trailing slash --- src/plugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugin.php b/src/plugin.php index 0271feff..21da21cb 100644 --- a/src/plugin.php +++ b/src/plugin.php @@ -64,5 +64,5 @@ function () { } function root_url(): string { - return plugins_url( 'build/', dirname(__FILE__ ) ); + return plugins_url( 'build', __DIR__ ); } From 99890b6eccbf9768fe76335cb928115b6222527f Mon Sep 17 00:00:00 2001 From: Ashfame Date: Fri, 24 Mar 2023 13:36:29 +0400 Subject: [PATCH 3/4] use dynamic path in site_status_tests as well --- src/Block/block.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Block/block.php b/src/Block/block.php index 0157e978..cd0ffcfe 100644 --- a/src/Block/block.php +++ b/src/Block/block.php @@ -65,12 +65,14 @@ function register_site_status_test( string $block_json_path ) { $badge = 'red'; } + $relative_path = str_replace( ABSPATH, '', $block_json_path ); + add_filter( 'site_status_tests', - function ( array $tests ) use ( $label, $status, $badge ) { + function ( array $tests ) use ( $label, $status, $badge, $relative_path ) { $tests['direct']['chatrix-block-json'] = array( 'label' => __( 'The block.json file exists', 'chatrix' ), - 'test' => function () use ( $label, $status, $badge ) { + 'test' => function () use ( $label, $status, $badge, $relative_path ) { return array( 'label' => wp_kses_post( $label ), 'status' => $status, @@ -80,7 +82,7 @@ function ( array $tests ) use ( $label, $status, $badge ) { ), 'description' => '

' . - __( 'If a block.json file is not found under wp-content/plugins/chatrix/build/block/block.json, the Chatrix block will not be available.', 'chatrix' ) . + sprintf( __( 'If a block.json file is not found under %s, the Chatrix block will not be available.', 'chatrix' ), '' . $relative_path . '' ) . '

', 'test' => 'chatrix-block-json', ); From f9d0871f2e28d6cf795e80abb07e1157493920c9 Mon Sep 17 00:00:00 2001 From: Ashfame Date: Fri, 24 Mar 2023 14:00:02 +0400 Subject: [PATCH 4/4] add translators comment and make file name a variable as well --- src/Block/block.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Block/block.php b/src/Block/block.php index cd0ffcfe..9faee486 100644 --- a/src/Block/block.php +++ b/src/Block/block.php @@ -82,7 +82,12 @@ function ( array $tests ) use ( $label, $status, $badge, $relative_path ) { ), 'description' => '

' . - sprintf( __( 'If a block.json file is not found under %s, the Chatrix block will not be available.', 'chatrix' ), '' . $relative_path . '' ) . + sprintf( + /* translators: %1$s is the file name, %2$s is the file path */ + __( 'If a %1$s file is not found under %2$s, the Chatrix block will not be available.', 'chatrix' ), + 'block.json', + '' . $relative_path . '' + ) . '

', 'test' => 'chatrix-block-json', );