How to init a WP plugin to use its classes?

I want to use a class from WordPress WYSIJA plugin in my php page. How do I need to init a plugin to be able to access it’s classes?

What I’m trying to do:

Read More
<?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');

And I’m getting an error: Fatal error: Class ‘WYSIJA’ not found in
Edit:
Now I moved the function that processes the form to the functions.php and edited the code:

    <?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>

but it still is not even showing the form and no error is shown.

Related posts

Leave a Reply

1 comment

  1. Try something like this:

    <?php
    
    define( 'WP_USE_THEMES', false );
    require( './wp-load.php' );
    
    add_action( 'plugins_loaded', 'display_so_14638257' );
    
    function display_so_14638257() 
    {
        // Your stuff
    }
    

    Prefix or suffix your function names so there’s no risk of conflict with other functions.