当前執行的wordpress 5.6
我已经涉足PHP了很长時間,但是對修改wordpress還是陌生的.我最终希望在满足某些條件後在使用者登錄後立即為使用者修改資料庫.為此,我希望在使用者登錄後立即获得使用者ID。Ive尝試使用預設的wordpress add_action('wp_login','test_mail');.据我了解,應该在使用者登錄到wordpress後執行。
当使用者登錄並收到電子郵件時,以下功能会按預期觸發,但是我的使用者ID始终為0。我必须忽略一些簡單的建議。
function test_mail(){
$user = wp_get_current_user();
$message .= "CURRENT USER ID: " . $user->ID . "\n";
$to = "[email protected]";
$subject = "Testing mail from login";
$header = "";
$attachments = "";
wp_mail( $to, $subject, $message, $headers, $attachments );
}
add_action('wp_login', 'test_mail');
最新回復
- 6月前1 #
wp_login傳遞了两个引數,但是您需要更新钩子才能將其正確傳遞给函式:
在此處了解更多資訊:https://developer.wordpress.org/reference/hooks/wp_login/