WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I need to customize the output of the shortcode of plugin A by using a function of plugin B. So I alter the shortcode function of plugin A by inserting a condition to check the value of the function of plugin B but I need to include the php file that supports this function. I tried all require_once, require and include but I get the following errors:

When using require_once('../../pluginname/pluginfunctions.php');

Error Warning: require_once(): open_basedir restriction in effect. File(../../magicmembers/core/libs/functions/mgm_misc_functions.php) is not within the allowed path(s)

When using include(WP_PLUGIN_URL . '/pluginname/pluginfunctions.php');

Error Warning: include(): URL file-access is disabled in the server configuration

What is the correct way?

share|improve this question

marked as duplicate by kaiser Jun 8 at 20:39

This question was marked as an exact duplicate of an existing question.

up vote 0 down vote accepted

The first error message means that there is restrictions in place on where you can include files from, set by the server. You could try with

require_once ABSPATH . '/wp-content/plugins/pluginname/pluginfunctions.php';

but I'm not sure if it would work.

With the second include you're trying to include an URL which is disabled by the server for security reasons.

However, why do you need to include the function of plugin B? If plugin B is present that means it's probably activated, which in turn means you can use the function directly from plugin A without needing to include the file specifically.

share|improve this answer
    
Hey, thanks for your reply! This might be the only method that I haven't tested and it works! Don't know really why the function wasn't working without including the file that supports it. Is it possible that plugin B isn't loaded yet when plugin A requires its file? Anyway thanks for your help! – vadims Aug 22 '12 at 10:29

The right function to use is: plugin_dir_path();

Example:

include_once plugin_dir_path( __FILE__ ).'plugin-functions.php';
share|improve this answer

If you're feeling lazy you could also do

require_once( ABSPATH . PLUGINDIR .'/pluginname/pluginfunctions.php' );

This helps if you like to keep your code lines short but isn't much different from pbd's answer.

share|improve this answer
    
Please … use the proper function: plugin_dir_path() instead of hard coding on constants that aren't meant to be used by themes and plugins. – kaiser Jun 8 at 20:36

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