admin管理员组文章数量:1287148
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
?
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 Answer
Reset to default 1The 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.
本文标签: hooksHow do I use preoptionoptionname correctly
版权声明:本文标题:hooks - How do I use pre_option_{option_name} correctly? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741231499a2362193.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论