致命错误:调用未定义的函数wp_mail()

时间:2012-12-02 作者:Niraj Chauhan

我正在使用插件wordpress-simple-paypal-shopping-cart 对于我的购物车要求。我试图通过这个插件发送电子邮件时,一些付款是通过使用IPN。

我的代码:

$invoiceProducts = $_SESSION[\'simpleCart\'];
    if(isset($invoiceProducts) && !empty($invoiceProducts)){
        $html = renderHTML($invoiceProducts);
        generatePDF($html);
        unset($invoiceProducts);
    }

function renderHTML($param){
    $IPN = $_POST;

    $name = $IPN[\'first_name\'];
    $donationAmount = $IPN[\'payment_gross\'];
    $contributorsEmail = $IPN[\'payer_email\'];
    $contributorsPhone = $IPN[\'payer_email\'];
    $contributorsAddr = $IPN[\'address_name\'] . \', \' . $IPN[\'address_city\'] . \', \' . $IPN[\'address_country\'];

    //We will need to shoot email to laura of successfull payment.
    $to = \'[email protected]\';
    $subject = \'Donation made on your website\';
    $message = \'\';
    $message .= \'<html><body>\';
    $message .= \'<p>You have received a contribution from<strong>\'.$name.\'</strong> of <strong>\'.$donationAmount.\'</strong></p>\';
    $message .= \'<p>Contributor Information:</p>\';
    $message .= \'<ul>\';
    $message .= \'<li>Name:\'.$name.\'</li>\';
    $message .= \'<li>Amount:\'.$donationAmount.\'</li>\';
    $message .= \'<li>Email:\'.$contributorsEmail.\'</li>\';
    $message .= \'<li>Address:\'.$contributorsAddr.\'</li>\';
    $message .= \'</ul>\';
    $message .= \'</body></html>\';

    wp_mail( $to, $subject, $message, $headers, $attachments );
}
但调用此函数时,我会遇到以下错误:Fatal error: Call to undefined function wp_mail()

我知道为什么会出现这个错误,只是我的插件是先加载的,而不是先加载的wp_mail().

就我而言,我该怎么打电话wp_mail() 先是我的插件?

1 个回复
最合适的回答,由SO网友:fuxia 整理而成

wp_mail() 定义于wp-includes/pluggable.php. 此文件在加载插件之后加载,但在挂钩之前加载plugins_loaded 已被解雇<所以答案是:等等。

add_action( \'plugins_loaded\', \'renderHTML\' );
另请注意:prefix 函数名和全局变量。

结束

相关推荐