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

Avoid calling plugin_dir_url a lot #5915

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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