繁体   English   中英

Wordpress + Constant Contact PHP SDK 包含路径

[英]Wordpress + Constant Contact PHP SDK include path

我目前正在尝试将 Constant Contact PHP sdk 实施到 wordpress 站点中。 询问 SDK 的一部分,您必须包含一些核心 PHP 文件才能使电子邮件代码正常工作。 如果没有找到这些文件,页面就会死掉,没有 PHP 错误。 目前,我在网站主题的根目录(/wp-content/themes/mytheme/src...)中有一个名为“src”的文件夹(它们的命名约定不是我的)。

这是调用文件的电子邮件表单代码:

<?php
// require the autoloader
require_once(TEMPLATEPATH . '/src/Ctct/autoload.php');

use Ctct\ConstantContact;
use Ctct\Components\Contacts\Contact;
use Ctct\Components\Contacts\ContactList;
use Ctct\Components\Contacts\EmailAddress;
use Ctct\Exceptions\CtctException;

// Enter your Constant Contact APIKEY and ACCESS_TOKEN
define("APIKEY", "XXXXXX");
define("ACCESS_TOKEN", "XXXXXX");

$cc = new ConstantContact(APIKEY);

// attempt to fetch lists in the account, catching any exceptions and printing the errors to screen
try {
    $lists = $cc->getLists(ACCESS_TOKEN);
} catch (CtctException $ex) {
    foreach ($ex->getErrors() as $error) {
        print_r($error);
    }
}

// check if the form was submitted
if (isset($_POST['email']) && strlen($_POST['email']) > 1) {
    $action = "Getting Contact By Email Address";
    try {
        // check to see if a contact with the email addess already exists in the account
        $response = $cc->getContactByEmail(ACCESS_TOKEN, $_POST['email']);

        // create a new contact if one does not exist
        if (empty($response->results)) {
            $action = "Creating Contact";

            $contact = new Contact();
            $contact->addEmail($_POST['email']);
            $contact->addList($_POST['list']);
            $contact->first_name = $_POST['first_name'];
            $contact->last_name = $_POST['last_name'];

            /*
             * The third parameter of addContact defaults to false, but if this were set to true it would tell Constant
             * Contact that this action is being performed by the contact themselves, and gives the ability to
             * opt contacts back in and trigger Welcome/Change-of-interest emails.
             *
             * See: http://developer.constantcontact.com/docs/contacts-api/contacts-index.html#opt_in
             */
            $returnContact = $cc->addContact(ACCESS_TOKEN, $contact, false);

            // update the existing contact if address already existed
        } else {
            $action = "Updating Contact";

            $contact = $response->results[0];
            $contact->addList($_POST['list']);
            $contact->first_name = $_POST['first_name'];
            $contact->last_name = $_POST['last_name'];

            /*
             * The third parameter of updateContact defaults to false, but if this were set to true it would tell
             * Constant Contact that this action is being performed by the contact themselves, and gives the ability to
             * opt contacts back in and trigger Welcome/Change-of-interest emails.
             *
             * See: http://developer.constantcontact.com/docs/contacts-api/contacts-index.html#opt_in
             */
            $returnContact = $cc->updateContact(ACCESS_TOKEN, $contact, false);
        }

        // catch any exceptions thrown during the process and print the errors to screen
    } catch (CtctException $ex) {
        echo '<span class="label label-important">Error ' . $action . '</span>';
        echo '<div class="container alert-error"><pre class="failure-pre">';
        print_r($ex->getErrors());
        echo '</pre></div>';
        die();
    }
}
?>

autoload.php 在它应该在http://www.thedaileymethod.com/_main_site/wp-content/themes/dailey-method/src/Ctct/autoload.php 的地方可用,这是我认为我在 PHP 文件中调用的,但页面对我来说一直在打破。

我的 require_once 路径不正确吗?

编辑:

当 for 代码加载时,页面 500 错误。 当我删除表单代码时,该错误消失并且页面加载正常。 从 PHP 错误的角度来看,日志中没有任何内容。

使用use关键字删除语句并更改

$cc = new ConstantContact(APIKEY);

$cc = new \Ctct\ConstantContact(APIKEY);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM