我在函数的user\\u register filter中获取ID时遇到问题。php。。。
这是我得到的
add_action( \'user_register\', \'sendanotheremail\' );
function sendanotheremail($user_id) {
$user = new WP_User($user_id);
$user_login = stripslashes($user->user_login);
$user_email = stripslashes($user->user_email);
$getid = $user->ID;
global $wpdb;
$getunion = $wpdb->get_results("SELECT value from wp_bp_xprofile_data where user_id = $getid AND field_id = 4", "ARRAY_N");
$message = sprintf(__(\'New user registration on %s:\'), get_option(\'blogname\')) . "\\r\\n\\r\\n";
$message .= sprintf(__(\'Username: %s\'), $user_login) . "\\r\\n\\r\\n";
$message .= sprintf(__(\'E-mail: %s\'), $user_email) . "\\r\\n";
$message .= "<br /> Please go here to approve the new user <a href=\\"http://xxx.com/wp-admin/admin.php?page=bp_registration_options_member_requests\\">Approve/Deny</a>";
if(!($getunion)) {
$message .= "nothing there";
}
else {
$message .= "yes";
}
$headers = \'From: xxx <[email protected]>\';
add_filter(\'wp_mail_content_type\',create_function(\'\', \'return "text/html";\'));
wp_mail(\'[email protected]\', \'New User Registration to xxx website\', $message, $headers);
}
我正在测试getunion,如果它是空的,我将返回“nothing there”。
So all of the other variables are getting me email with right data, but $getunion is empty...
当我在这里手动传递ID时
$getunion = $wpdb->get_results("SELECT value from wp_bp_xprofile_data where user_id = $get_id AND field_id = 4", "ARRAY_N");
它起作用了。。。那我怎么才能拿到身份证呢?
最合适的回答,由SO网友:s_ha_dum 整理而成
你在付出$wpdb->get_results
第二个参数的字符串。它应该是一个常数--ARRAY_N
-- 意味着您需要删除引号
$getunion = $wpdb->get_results(
"SELECT value from wp_bp_xprofile_data where user_id = $getid AND field_id = 4",
ARRAY_N
);
既然你声称它在二审中有效,我假设
$wpdb
补偿,但我还没有证实。我想我应该提一下。
我认为你的问题在于:
$user = new WP_User($user_id);
$user_login = stripslashes($user->user_login);
$user_email = stripslashes($user->user_email);
$getid = $user->ID;
您的用户ID作为
$user_id
. 我不知道你为什么要创建另一个用户。我认为,用以下内容替换这四行可以解决问题。
$user = get_user_by(\'id\',$user_id);
$user_login = stripslashes($user->user_login);
$user_email = stripslashes($user->user_email);
// $getid = $user->ID; // you already have the user ID -> $user_id; use that below or change this line to
$getid = $user_id; // if you must