xwp / block-scaffolding-wp

WordPress plugin template for extending Gutenberg
https://join.xwp.co
18 stars 17 forks source link

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

Open schlessera opened 4 years ago

schlessera commented 4 years ago

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

https://github.com/xwp/block-scaffolding-wp/blob/412029a0be0f9b08468c195a985a2c4131415ffc/php/Plugin.php#L172

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.

kasparsd commented 4 years ago

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().