0

Inside one of small custom plugins I really need to inlcude a file from another plugin, in order to be able to create and save obhect of a class that is declared there.

What I have tried and the closest is this:

include_once($plugin_url.'plugin-name/classes/event.php');

The error I get in the debug logs is the following:

PHP Warning:  include_once(http://.../plugin-name/classes/event.php): failed to open stream: no suitable wrapper could be found in ..

I wonder what would be the correct way to reuse the logic of that class to only be able to create and save objects.

Any help or guidance is much appreciated.

1
  • $plugins_url is going use an absolute path which leads to a security problem on your server. Have you tried plugin_basename to grab a variable and try a relative path ? codex.wordpress.org/Function_Reference/plugin_basename Commented Jun 9, 2016 at 13:26

1 Answer 1

2

Including a PHP file requires to provide its exact file path, not the URL.

Try this instead:

include_once( WP_PLUGIN_DIR . '/plugin-name/classes/event.php' );

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.