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

Improve caching plugin_dir_url() in Package. #6260

Merged
merged 1 commit into from
Apr 14, 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
8 changes: 5 additions & 3 deletions src/Domain/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}

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

Expand Down