我想在我的 php 页面中使用来自 Wordpress WYSIJA 插件的类。我如何需要初始化一个插件才能访问它的类?
我正在尝试做的事情:
<?php
require_once(dirname(__FILE__).'/wp-blog-header.php');
require_once(dirname(__FILE__).'/wp-content/plugins/wysija-newsletters/core/base.php');
function display()
{
$myEmailVariable=$_POST['usremail'];
$myListId1='3';
echo($myEmailVariable);
$userData=array( 'email'=>$myEmailVariable, 'firstname'=>'', 'lastname'=>'');
$data=array( 'user'=>$userData, 'user_list'=>array('list_ids'=>array($myListId1)) );
$userHelper=&WYSIJA::get('user','helper');
print_r($data);
$userHelper->addSubscriber($data);
}
add_action('init','display');
我得到一个错误:致命错误:在编辑中找不到类'WYSIJA':现在我将处理表单的函数移到functions.php并编辑了代码:
<?php
require_once(dirname(__FILE__).'/wp-blog-header.php');
if (isset($_POST['usremail'])) {
add_subscriber_wys();
}
else {
//show form
?>
<body>
<div class="box_email">
<p>Секунду, мы перенаправляем Вас на страницу банка</p>
<div class='email_frame'>
<form method="post" action="<?php echo($_SERVER['PHP_SELF']) ?>">
<span class="email_label">Введите e-mail</span>
<input type="email" name="usremail" size="35" onfocus="stoptimer()" style="line-height: 60px;" >
<br>
<span>чтобы получать лучшие предложения от банков-партнеров</span>
</div>
<div>
<img src="http://moscow-kredit.ru/wp-content/themes/arthemia-premium/images/banki.png"></img>
</div>
<div class="or">
или просто нажмите
</div >
<div class='button'><input type="image" src="http://moscow-kredit.ru/wp-content/themes/arthemia-premium/images/knopka.png" alt="Далее" name='submit' /></div>
</form>
<?php
}
?>
</div>
<script>
var foo;
function redirectme(){
var refarray = new Array();
refarray['homenal'] = "http://test1.ru";
refarray['genal'] = "http://test2.ru";
refarray['domain3.com'] = "http://test3.ru";
for (var i in refarray) {
if (window.location.href.indexOf(i) != -1) window.location.replace(refarray[i]);
}
}
function stoptimer(){
clearTimeout(window.foo);
}
foo=setTimeout("redirectme();", 5000);
</script>
</body>
</html>
但它仍然没有显示表单,也没有显示错误。