From e3480c612689e268a050035b268c78ffe51caaa9 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 25 Oct 2024 10:38:37 +0200 Subject: [PATCH 1/6] Do not try to guess slug in `Abstract_Check_Runner` This can be handled by `Plugin_Context` --- includes/Checker/Abstract_Check_Runner.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php index 368418da3..bf427fa30 100644 --- a/includes/Checker/Abstract_Check_Runner.php +++ b/includes/Checker/Abstract_Check_Runner.php @@ -645,10 +645,6 @@ private function get_check_context() { final public function set_slug( $slug ) { if ( ! empty( $slug ) ) { $this->slug = $slug; - } else { - $basename = $this->get_plugin_basename(); - - $this->slug = ( '.' === pathinfo( $basename, PATHINFO_DIRNAME ) ) ? $basename : dirname( $basename ); } } From 48a3ed9cc5d14eae4605f1482aa7c03cb7903c77 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 25 Oct 2024 10:38:50 +0200 Subject: [PATCH 2/6] Use correct slug for single-file plugins --- includes/Plugin_Context.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Plugin_Context.php b/includes/Plugin_Context.php index 9cdde25fc..d62f0440b 100644 --- a/includes/Plugin_Context.php +++ b/includes/Plugin_Context.php @@ -81,7 +81,7 @@ public function __construct( $main_file, $slug = '' ) { if ( ! empty( $slug ) ) { $this->slug = $slug; } else { - $this->slug = basename( dirname( $this->main_file ) ); + $this->slug = $this->is_single_file_plugin() ? basename( $this->main_file, '.php' ) : basename( dirname( $this->main_file ) ); } } From 7b5bde68fd7fafcf54e58b35ab2ee6f93145700b Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 4 Nov 2024 09:34:09 +0100 Subject: [PATCH 3/6] Don't use `plugin_dir_path` --- includes/Plugin_Context.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Plugin_Context.php b/includes/Plugin_Context.php index d62f0440b..fb341f130 100644 --- a/includes/Plugin_Context.php +++ b/includes/Plugin_Context.php @@ -130,7 +130,7 @@ public function path( $relative_path = '/' ) { if ( is_dir( $this->main_file ) ) { return trailingslashit( $this->main_file ) . ltrim( $relative_path, '/' ); } else { - return plugin_dir_path( $this->main_file ) . ltrim( $relative_path, '/' ); + return trailingslashit( dirname( $this->main_file ) ) . ltrim( $relative_path, '/' ); } } From a184b20f6552a4fd7d643a4e9d5547baae855fe4 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 4 Nov 2024 09:44:03 +0100 Subject: [PATCH 4/6] No `trailingslashit` --- includes/Plugin_Context.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Plugin_Context.php b/includes/Plugin_Context.php index fb341f130..bce76ed1c 100644 --- a/includes/Plugin_Context.php +++ b/includes/Plugin_Context.php @@ -128,9 +128,9 @@ public function slug() { */ public function path( $relative_path = '/' ) { if ( is_dir( $this->main_file ) ) { - return trailingslashit( $this->main_file ) . ltrim( $relative_path, '/' ); + return $this->main_file . '/' . ltrim( $relative_path, '/' ); } else { - return trailingslashit( dirname( $this->main_file ) ) . ltrim( $relative_path, '/' ); + return dirname( $this->main_file ) . '/' . ltrim( $relative_path, '/' ); } } From ce049d59cf0616bb05c6ec2c269d3a517ee01faf Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 4 Nov 2024 09:45:51 +0100 Subject: [PATCH 5/6] Remove errant space --- includes/Plugin_Context.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Plugin_Context.php b/includes/Plugin_Context.php index bce76ed1c..630e14a96 100644 --- a/includes/Plugin_Context.php +++ b/includes/Plugin_Context.php @@ -128,7 +128,7 @@ public function slug() { */ public function path( $relative_path = '/' ) { if ( is_dir( $this->main_file ) ) { - return $this->main_file . '/' . ltrim( $relative_path, '/' ); + return $this->main_file . '/' . ltrim( $relative_path, '/' ); } else { return dirname( $this->main_file ) . '/' . ltrim( $relative_path, '/' ); } From 16f8e0998a9d882481464709148dab7380b750c3 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 6 Nov 2024 18:26:26 +0100 Subject: [PATCH 6/6] Don't use in constructor --- includes/Checker/Abstract_Check_Runner.php | 2 +- includes/Plugin_Context.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Checker/Abstract_Check_Runner.php b/includes/Checker/Abstract_Check_Runner.php index e0489e9e1..a5d33786a 100644 --- a/includes/Checker/Abstract_Check_Runner.php +++ b/includes/Checker/Abstract_Check_Runner.php @@ -627,7 +627,7 @@ final protected function get_slug() { private function get_check_context() { $plugin_basename = $this->get_plugin_basename(); $plugin_path = is_dir( $plugin_basename ) ? $plugin_basename : WP_PLUGIN_DIR . '/' . $plugin_basename; - return new Check_Context( $plugin_path, $this->get_slug() ); + return new Check_Context( $plugin_path, $this->get_slug() ? $this->get_slug() : basename( $plugin_path, '.php' ) ); } /** diff --git a/includes/Plugin_Context.php b/includes/Plugin_Context.php index 630e14a96..0f2f9b8ea 100644 --- a/includes/Plugin_Context.php +++ b/includes/Plugin_Context.php @@ -81,7 +81,7 @@ public function __construct( $main_file, $slug = '' ) { if ( ! empty( $slug ) ) { $this->slug = $slug; } else { - $this->slug = $this->is_single_file_plugin() ? basename( $this->main_file, '.php' ) : basename( dirname( $this->main_file ) ); + $this->slug = basename( dirname( $this->main_file ), '.php' ); } }