From d8b2fe054cdfc61220023a3d8b898cfb00234c3d Mon Sep 17 00:00:00 2001 From: kristianwind Date: Wed, 16 Sep 2026 10:36:33 +0200 Subject: [PATCH] Read the update header once per request, not on every page load The filter is registered on every request a shop serves, not just in wp-admin, and get_file_data() opens and scans the plugin file each time it is asked. Co-Authored-By: Claude Opus 5 (1M context) --- includes/class-updater.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/includes/class-updater.php b/includes/class-updater.php index c11319c..fb1ec6a 100644 --- a/includes/class-updater.php +++ b/includes/class-updater.php @@ -57,15 +57,30 @@ class WC_EDM_Updater { add_action( 'upgrader_process_complete', array( $this, 'forget' ), 10, 0 ); } + /** + * Memoised update URI, so the plugin file is read at most once a request. + * + * @var string|null + */ + private static $uri = null; + /** * The repository this plugin updates from, as stated in its own header. * + * Read from the header rather than a constant so that there is exactly one + * place saying where updates come from — but memoised, because the filter + * is registered on every request a shop serves, not just in wp-admin, and + * get_file_data() opens and scans the file each time it is asked. + * * @return string */ public static function update_uri() { - $data = get_file_data( WC_EDM_PLUGIN_FILE, array( 'uri' => 'Update URI' ) ); + if ( null === self::$uri ) { + $data = get_file_data( WC_EDM_PLUGIN_FILE, array( 'uri' => 'Update URI' ) ); + self::$uri = isset( $data['uri'] ) ? trim( $data['uri'] ) : ''; + } - return isset( $data['uri'] ) ? trim( $data['uri'] ) : ''; + return self::$uri; } /**