acf-typography icon indicating copy to clipboard operation
acf-typography copied to clipboard

PHP Warning - Google API Key 400 Bad Request

Open codejp3 opened this issue 3 years ago • 0 comments

I've been testing my last pull request today by throwing a bunch of junk data at the plugin to see how it handles it. Found an issue affecting every "file_get_contents" function call. Here's an example when a bad API Key string is supplied:

file_get_contents (wp-content/plugins/acf-typography-field/includes/functions.php => 45)
file_get_contents(https://www.googleapis.com/webfonts/v1/webfonts?key=BAD_API_KEY_STRING): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request

I'm already patching this. PR will also include this patch.

In admin_settings.php: It will now check the key against the Google API Key URL. If it encounters any errors, a message will be displayed showing the response header error message.

In functions.php: Every "file_get_contents" function will suppress displaying error messages publicly and only process the output if there was no error message.

Idea / Enhancement - Possibly add a debug log and an "enable/disable debugging" admin setting to capture file and URL read/write errors?

codejp3 avatar Oct 06 '22 21:10 codejp3