From 09f4370fda8a7c2956a56096605870720c22fb12 Mon Sep 17 00:00:00 2001 From: Shendy Kurnia Date: Thu, 14 Apr 2022 19:26:20 +0700 Subject: [PATCH] Call plugin_dir_url() in Package::get_url() instead of from its constructor. --- src/Domain/Package.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Domain/Package.php b/src/Domain/Package.php index 23505f01fe4..e70b115ff2f 100644 --- a/src/Domain/Package.php +++ b/src/Domain/Package.php @@ -52,9 +52,6 @@ public function __construct( $version, $plugin_path, FeatureGating $feature_gati $this->version = $version; $this->path = $plugin_path; $this->feature_gating = $feature_gating; - - // Append index.php so WP does not return the parent directory. - $this->plugin_dir_url = plugin_dir_url( $this->path . '/index.php' ); } /** @@ -87,6 +84,11 @@ public function get_path( $relative_path = '' ) { * @return string */ public function get_url( $relative_url = '' ) { + if ( ! $this->plugin_dir_url ) { + // Append index.php so WP does not return the parent directory. + $this->plugin_dir_url = plugin_dir_url( $this->path . '/index.php' ); + } + return $this->plugin_dir_url . $relative_url; }