diff --git a/src/Domain/Package.php b/src/Domain/Package.php index d559a7169a1..23505f01fe4 100644 --- a/src/Domain/Package.php +++ b/src/Domain/Package.php @@ -27,6 +27,13 @@ class Package { */ private $path; + /** + * Holds locally the plugin_dir_url to avoid recomputing it. + * + * @var string + */ + private $plugin_dir_url; + /** * Holds the feature gating class instance. * @@ -45,6 +52,9 @@ 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' ); } /** @@ -77,8 +87,7 @@ public function get_path( $relative_path = '' ) { * @return string */ public function get_url( $relative_url = '' ) { - // Append index.php so WP does not return the parent directory. - return plugin_dir_url( $this->path . '/index.php' ) . $relative_url; + return $this->plugin_dir_url . $relative_url; } /**