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) <noreply@anthropic.com>
This commit is contained in:
kristianwind
2026-09-16 10:36:33 +02:00
co-authored by Claude Opus 5
parent eca2851d35
commit d8b2fe054c
+17 -2
View File
@@ -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;
}
/**