mujahidi / acf-typography

A Typography Add-on for the Advanced Custom Fields Plugin
https://wordpress.org/plugins/acf-typography-field/
GNU General Public License v2.0
18 stars 6 forks source link

PHP Warning - Google API Key 400 Bad Request #27

Open codejp3 opened 2 years ago

codejp3 commented 2 years ago

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?