LoginSignup
0
0

More than 5 years have passed since last update.

option_name = 'gmt_offset' のレコードがおかしい?

Posted at

WordPress では標準時との差を取得するのに以下の関数で取得した値を使うことができます。

get_option( 'gmt_offset' );

これなんですが、素直にみると WP_OPTIONS 表に option_name = 'gmt_offset' のレコードがありそうに見えます。で、実際にレコードはあるのですが、値が空だったりします。

実はこのレコードは使用されておらず、option_name = 'timezone_string' のレコードの値 ('Asia/Tokyo' とか) に従って get_option( 'gmt_offset' ) の戻り値が決まります。これらの処理は、以下のように wp-includes/default-filters.php の中でデフォルトフィルターが設定されていて、get_option よりこの wp_timezone_override_offset が呼ばれてその中で処理されています。

add_filter( 'pre_option_gmt_offset','wp_timezone_override_offset' );

このように get_option 内で特別な振る舞いをするオプション値があるので注意が必要です。

この記事は WordPress 3.7 をベースにして書いています。

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