Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Avoid calling plugin_dir_url a lot (#5915)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinleroy authored and Saad Tarhi committed Feb 26, 2022
1 parent 5ce7558 commit ee55aa5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Domain/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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' );
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit ee55aa5

Please sign in to comment.