Skip to content
This repository has been archived by the owner on Jul 20, 2022. It is now read-only.

Fatal error: ArgumentCountError on get_file_data() in Plugin.php #58

Open
schlessera opened this issue May 8, 2020 · 1 comment
Open
Labels
bug Something isn't working

Comments

@schlessera
Copy link

The following line throws a fatal error in PHP 7.4+:

$meta = get_file_data( $this->file );

Image 2020-05-08 at 2 11 44 PM

As can be seen in the documentation for get_file_data(), the second argument $default_headers is not optional and has to be provided.

@schlessera schlessera added the bug Something isn't working label May 8, 2020
@kasparsd
Copy link
Contributor

kasparsd commented May 8, 2020

Yes, the second argument is required. Here is how I fixed it in another plugin:

diff --git a/src/Plugin.php b/src/Plugin.php
index b51910c..d9f79cd 100644
--- a/src/Plugin.php
+++ b/src/Plugin.php
@@ -165,7 +165,12 @@ public function meta( $field = null ) {
 		static $meta;
 
 		if ( ! isset( $meta ) ) {
-			$meta = get_file_data( $this->file );
+			$meta = get_file_data(
+				$this->file,
+				array(
+					'Version' => 'Version',
+				)
+			);
 		}
 
 		if ( isset( $field ) ) {

We could also remove the static cache wrapper and pass the lookup field to get_file_data().

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants