I'm developing a custom plugin, which requires input of authentication data for a remote API, and this data needs to be saved. I want to encrypt it before saving to db.

I've added a settings page, containing:

<form method="post" action="options.php">
  <!-- form fields here... -->

Rather than having each option saved as a different entry in {wp_table_prefix}_options table, I want them saved as an object in only one row, so the name attributes are of this type:

<input name="plugin-slug[option-key]" ...> 

The question is fairly simple: what is the proper way to encrypt the data before saving it in db? I'd like to hash the entire object and I'm going to decrypt it back after get_option('plugin-slug').

Is there a default method to filter the sent request to options.php, before saving it in db? I haven't been able to find anything on the topic or an example that already does it. It's hard to believe nobody needed something similar before.

I also tried finding a filter or action called inside into options.php but, as you can see, it has a fairly convoluted logic and some backwards compatibility code... I was hoping there's a more straight-forward way of doing it than pinning toothpicks into options.php.

  • putting encryption and hashing randomly do not improve security. just don't do it, it is pointless Apr 22, 2018 at 17:25
  • @Mark, could you expand on "randomly"? I believe I am encrypting exactly what I want. There's nothing random about it. In the system I'm providing the plugin for, which happens to be quite large, people who can look in the database are not supposed to see the unencrypted password from the remote API. I'm not here to speculate whether or not the choice to encrypt it has or not any point. I'm supposed to provide a method to do it. I would like to know if WordPress exposes the posted information before storing it in DB, through any known filter.
    – tao
    Apr 22, 2018 at 17:43
  • "random" === "no plan", meaning that the reason for selecting some method is not the result of some analysis of the problem, but rather is based on "easy" or just random thought process. To be specific, if this is an API key that you need to use with the API, you either can use it as you store it, or you have a code on your server that encodes it. This means anyone with access to your server will be able to see and use the key, and if you were hired to prevent that, then your method will fail. Wordpress do not have any storage methods that support secrets, and you are unlikely to create one. Apr 22, 2018 at 18:10
  • The system users are logging in is ancient, uses username and password. These credentials need to be stored in WordPress so they are not required again, once they were provided, for current user. So I'm going to use an external system to store the key. But I don't want the users to provide the API key for the system used to encrypt. I want them to provide the password to the old system, because that's what they have. So, I don't want WP to provide an encryption method. I got that part covered. I want to know if WP provides a filter function for the posted data before saving it. @Mark
    – tao
    Apr 22, 2018 at 18:46
  • What I am trying to say is that In the end of the day if information X is in the DB and can be used to login to service Y, than it does not matter at all in what format X is stored. even modern security standards like oauth2 do not actually solve this problem, and the only way to solve it is by not storing it on the server at all. For user initiated action you can store the information in cookies, but for cron type actions it is not possible and you are left with the security risk, and there is not much you can do about it Apr 22, 2018 at 19:09

1 Answer 1


Found them:

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.