我正在WordPress上设置付费会员页面。它使用一个表单来获取信用卡信息和电子邮件地址,然后运行该卡并在成功后设置一个新用户。我可以运行该卡,并创建一个新用户,但它不会向他们发送欢迎电子邮件,以便他们可以建立自己的密码。
我已经尝试为这个PHP页面找到包含文件的正确组合(使用echo语句查看代码中断的位置),并通过在页面顶部包含它们来解决了许多缺少的函数,但我仍然得到“致命错误:在/[…]中的非对象上调用成员函数get()”/wp包括/缓存。这是我创建的用于发送通知电子邮件的代码:
require_once(\'../wp-includes/capabilities.php\');
require_once(\'../wp-includes/cache.php\');
require_once(\'../wp-includes/option.php\');
require_once(\'../wp-includes/pluggable.php\');
require_once(\'../wp-includes/plugin.php\');
require_once(\'../wp-includes/formatting.php\');
function setWP($username){
global $wpdb, $wp_hasher;
echo("Globals<br />");
$user_login=$username;
echo($user_login."<br />");
if(empty($user_login)){
return false;
}else if(strpos($user_login, \'@\')){
$user_data=get_user_by(\'email\', trim($user_login));
if(empty($user_data))
return false;
}else{
$login=trim($user_login);
$user_data=get_user_by(\'login\', $login);
}
echo("user_login<br />");
do_action(\'lostpassword_post\');
if(!$user_data) return false;
// redefining user_login ensures we return the right case in the email
$user_login=$user_data->user_login;
$user_email=$user_data->user_email;
do_action(\'retreive_password\', $user_login); // Misspelled and deprecated
do_action(\'retrieve_password\', $user_login);
echo("retrieve_password<br />");
$allow=apply_filters(\'allow_password_reset\', true, $user_data->ID);
if(!$allow)
return false;
else if(is_wp_error($allow))
return false;
echo("allow<br />");
$key=wp_generate_password(20, false);
do_action(\'retrieve_password_key\', $user_login, $key);
if(empty($wp_hasher)){
require_once ABSPATH . \'wp-includes/class-phpass.php\';
$wp_hasher=new PasswordHash(8, true);
}
$hashed=$wp_hasher->HashPassword($key);
$wpdb->update($wpdb->users, array(\'user_activation_key\' => $hashed), array(\'user_login\' => $user_login));
echo("hashed<br />");
$message=__(\'Welcome!\') . "\\r\\n\\r\\n";
$message .= __(\'If you did not request a training series, send an email to [email protected].\') . "\\r\\n\\r\\n";
$message .= __(\'As a new student, you will need to set a password. Visit the following address:\') . "\\r\\n\\r\\n";
$message .= \'<\' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), \'login\') . ">\\r\\n";
$message .= sprintf(__(\'Username: %s\'), $user_login) . "\\r\\n\\r\\n";
if(is_multisite())
$blogname=$GLOBALS[\'current_site\']->site_name;
else
$blogname=wp_specialchars_decode(get_option(\'blogname\'), ENT_QUOTES);
echo("is_multisite<br />");
$title=sprintf(__(\'[%s] Password Reset\'), $blogname);
$title=apply_filters(\'retrieve_password_title\', $title);
$message=apply_filters(\'retrieve_password_message\', $message, $key);
echo("Prep to send<br />");
if($message && !wp_mail($user_email, $title, $message))
echo(\'The e-mail could not be sent.\');
else
echo("Message sent.");
}
有没有办法在WordPress框架之外向用户发送欢迎电子邮件?