Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to use a plugin function in a custom php file. Pasting this code at the top of my file i can use all the wordpress functions:

<?php 
$file = dirname(__FILE__);
$file = substr($file, 0, stripos($file, "wp-content") );
require( $file .'/wp-blog-header.php');

But i get this error when i call plugin function:

Fatal error: Call to undefined function wp_bannerize() in mysite/my-file.php

How to get wp_bannerize() in my-file.php ?

UPDATE:

If i call my-file.php in my browser like this:

http://localhost/~sdibenedetto/d-art/htdocs/wp-content/themes/d-art/infinite-posts.php?offset=3

I have no errors and wp_bannerize() works correctly

At the AJAX call i got the error... May depends that infinite-scroll jquery plugin uses load() instead $.ajax()?

share|improve this question
    
What is your main goal. Maybe you can avoid this kind of integration. You can try to include the plugin main file, usually "wp_contents/plugin_name/plugin_name.php" –  SpartakusMd Oct 16 '13 at 11:21
    
my-file.php answer to an ajax call and return an array of posts ( this is used for the "infinite-scroll" ). Beside this array i want to show a ADV banner. I use this plugin to menage ADV and banner... –  Salvatore Dibenedetto Oct 16 '13 at 12:27
1  
see AJAX in Plugins in Codex for the correct way to do AJAX with WordPress. –  Milo Oct 16 '13 at 16:46
add comment

2 Answers 2

You should make ajax requests via admin-ajax.php.

http://wp.smashingmagazine.com/2011/10/18/how-to-use-ajax-in-wordpress/

In this way you'll have access to all wordpress functions.

share|improve this answer
add comment

Salvatore! You can edit wp_bannerize manually (see file plugins/wp-bannerize/main.php) in order to look like this:

require_once( trailingslashit( dirname( __FILE__ ) ) . 'main.h.php' );
require_once( trailingslashit( dirname( __FILE__ ) ).'Classes/wpBannerizeClass.php' );

if ( @isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) ) {
    if ( is_admin() ) {
        require_once( trailingslashit( dirname( __FILE__) ) . 'Classes/wpBannerizeAdmin.php' );
        $wpBannerizeAdmin = new WPBannerizeAdmin( __FILE__ );
        require_once( trailingslashit( dirname( __FILE__) ) . 'Classes/wpBannerizeAjax.php' );
    }else{
        require_once( trailingslashit( dirname( __FILE__ ) ) . 'Classes/wpBannerizeFrontend.php' );
        $wpBannerizeFrontend = new WPBannerizeFrontend( __FILE__ );
        require_once( trailingslashit( dirname( __FILE__ ) ) . 'Classes/wpBannerizeFunctions.php' );

    }
}
else {
    if ( is_admin() ) {
        require_once( trailingslashit( dirname( __FILE__ ) ) . 'Classes/wpBannerizeAdmin.php' );
        //
        $wpBannerizeAdmin = new WPBannerizeAdmin( __FILE__ );
        $wpBannerizeAdmin->register_plugin_settings( __FILE__ );
        register_activation_hook( __FILE__, array( &$wpBannerizeAdmin, 'pluginDidActive' ) );
        register_activation_hook( __FILE__, array( &$wpBannerizeAdmin, 'pluginDidDeactive' ) );
    }
    else {
        require_once( trailingslashit( dirname( __FILE__ ) ) . 'Classes/wpBannerizeFrontend.php' );
        $wpBannerizeFrontend = new WPBannerizeFrontend( __FILE__ );
        require_once( trailingslashit( dirname( __FILE__ ) ) . 'Classes/wpBannerizeFunctions.php' );
    }
}

This will definitely help. The main reason why it's not working properly is condition in the 4th line (check for ajax-request).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.