LoginSignup
6
6

More than 5 years have passed since last update.

[WordPress]ユーザーログインのアクションフック

Posted at

何度も忘れてしまうので備忘録。

ユーザーログイン後に何か処理をしたい場合には、wp_login のアクションフックを使う。

functions.php
add_action( 'wp_login', 'hoge_func', 10, 2 );
function hoge_func ( $user_login , $current_user ) {
  /* 何かしらの処理 */
}

ログ出力して確認してみたところ、引数の user_login と current_user にはそれぞれ以下の情報が渡されてくる模様。

user_login: ユーザー名(wp_users テーブルの "user_login" と同じ値)
current_user: ログインしたユーザーのWP_Userクラス

6
6
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
6
6