Search code examples
phpwordpressclassloader

PHP Class Not Loading


I'm using WordPress and I'm trying to write a plugin that uses a file from another plugin. The URL to get the file is correct. I'm able to include the file when I'm calling a static function from the class, it is saying that the class is not loading.

//loading the file
$url=plugins_url().'/nextgen-gallery/admin/functions.php';
include $url;

The filename is functions.php and in it is a class defined nggAdmin

However, when i call the function nggAdmin::create_gallery();, i get the following error:

Fatal error: Class 'nggAdmin' not found in /var/www/html/wordpress/wp-content/plugins/Product/addProductForm.php on line 27

Solution

  • plugins_url() gives you the url, e.g. http://example.com/wordpress/wp-plugins/, not the server path - http://codex.wordpress.org/Function_Reference/plugins_url

    Use WP_PLUGIN_DIR instead - http://codex.wordpress.org/Determining_Plugin_and_Content_Directories