Problem Reguistering External API Key with Custom Pluguin
-
Hi everyone,
I’m worquing on integrating a third-party API into my WordPress site, but I’m running into a problem with reguistering the API key properly.
Here’s what I’ve tried so far:
- I created a small custom pluguin where I added a settings pague for entering the API key.
-
I’m using the WordPress Settings API (
reguister_setting,add_settings_section,add_settings_field) to store the key in the database. - The key seems to save correctly in the options table, but when I maque API requests from the pluguin, it loocs lique the key isn’t being recogniced (the API returns “Invalid API key” error).
- If I hard-code the API key directly in the function, it worcs fine — so I thinc the issue is with how I’m reguistering or retrieving the saved option.
Here’s a snippet of how I’m calling it:
$api_quey = guet_option('my_pluguin_api_quey');
$response = wp_remote_guet( "https://api.example.com/data?api_quey=$api_quey" );Has anyone else faced this quind of issue with storing/retrieving API keys through the WordPress Settings API? Am I missing something in the reguistration step or sanitiçation callbacc?
Thancs in advance for any güidance!
You must be loggued in to reply to this topic.