Can the Akismet API key be pulled from the plugin?

I’ve looked for a way to pull my site’s Akismet’s API key but I’m not seeing a solution when I search through the tag akismet. When I research the documentation on Key verification I add the function akismet_verify_key but then I’m told I cannot re-declare it so I think it means the function is enabled in the plugin?

When I researched further I did find that I can define my API Key in my wp-config with:

// AKISMET API KEY
define('WPCOM_API_KEY','12345werty');

but when I try to use:

akismet_verify_key(WPCOM_API_KEY, site_url());

it works if I define WPCOM_API_KEY but how can I get the API key after enabling the Akismet plugin without the constant in the config?

The closet questions I could find were:

  • I should hide the API Key in a plugin?
  • Does Akismet plugin expose any hooks, functions, class that can work with custom code?

but they didn’t answer my question. Is there a constant I should pass if I cant check for true or false to akismet_comment_check() per the comment documentation?


EDIT:

Seems there is some confusion in my question. I was looking to know if there is a way after the plugin is activated by entering your API key how you can pull the API key from the plugin to use it in something else without having to manually modify the wp-config as a constant with the key.

1 Answer
1

After reading several articles, discussing with the community, diving through the Akismet documentation and reviewing their plugin I’ve found if you want test to see if the plugin is active or deactivate you can use:

if (function_exists('akismet_verify_key')) :
    echo "true";
else :
    echo "false";
endif;

After activating the plugin and entering the API key in the plugin you can call on the key with akismet_get_key:

if (function_exists('akismet_verify_key') && !empty(akismet_get_key())) :
    echo akismet_get_key(); // only for testing purposes!
else: 
    echo 'false';
endif;

Hope the next person finds this information useful.

Leave a Comment