LoginSignup
0
0

More than 5 years have passed since last update.

update_optionでautoloadがyesになってしまう問題

Last updated at Posted at 2014-01-14

update_option()、超便利ですよね。
値が既に入っていればupdateしてくれて、新規だったら自動的にaddしてくれる。
素晴らしい関数です。

しかしながら惜しいことに、全ての値がデフォルトでautoload=yesに設定されてしまいます。
リソースの無駄遣い!

そういう時は、面倒くさいですが、丁寧にadd_option()しましょう、
というすげープチTIPSでした。

$key = 'option_key';
if (get_option($key) !== false)
{
  update_option($key, $value);
}
else
{
  $autoload = 'no';
  add_option($key, $value, null, $autoload);
}

で、まあ、大体こんな感じでワンラインにしてしまうという…。

(get_option($k) !== false) ? update_option($k, $v) : add_option($k, $v, null, 'no');
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0