0

I am using a filter to decrypt an api_key that is stored with encryption. I have registered the following hook:

// Decrypt API key after it is retrieved
add_filter('pre_option_percify_api_key', array( __CLASS__, 'decrypt_api_key') );

The problem is, I cannot get at the stored value in the callback:

public static function decrypt_api_key($encrypted) {
  // $encrypted is empty:

  echo($encrypted);
  // ...

Am I calling the function correctly? How do I access the stored value of percify_api_key within decrypt_api_key?

1

The pre_option_{$option} hook is used to filter the value of the option before it's retrieved. You need to hook after the value is retrieved so you can manipulate it.

In this case, you can use the option_{$option} hook. So your code will look like this:

add_filter('option_percify_api_key', array( __CLASS__, 'decrypt_api_key') );

For more info - take a look at the source of the get_option function here. Specifically line #225.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.