0

I've created a working plugin and now I've created a second one.

I would like to acces a file that's in the plugin 2 directory, from within the plugin 1 directory.

I've tried it by using the below code:

require_once '/wp-content/plugins/my-core/updare/plugin-update-checker.php';

However I'm getting the following error:

Warning: require_once(): open_basedir restriction in effect. File(//wp-content/plugins/my-core/updare/plugin-update-checker.php) is not within the allowed path(s):

It could be fixed by changing the .htaccess file by disabling my open_basedir settings, but due to security I'm not willing to disable it completely. How can I acces a from from plugin 1 towards plugin 2 without changing up the open_basedir globaly? Also, it should be in a .htaccess file because I'm planning on using the plugin on several websites.

2 Answers2

0

generally you should not be able to access other plugin files' content or even try to. If the second plugin is written in Object-oriented programming PHP language then you can easily hook into it using its class, if not, you can use its functions to do whatever you need. This is the goal of OOP, to access other sources without accessing entire file and violating security.

  • Thank you for your reply. Do you have an example code of such kind of a hook? – AartStaartjes Jun 27 '22 at 08:15
  • You can check WooCommerce for instance, the class WC_Product is defined in the WooCommerce plugin but it is accessible outside of the plugin and you can use it whenever WooCommerce is loaded. Just take a look at the WordPress plugin handbook and PHP.net documentation and look for Object-Oriented Programming. – Amirhossein Hosseinpour Jul 01 '22 at 21:25
0

You can use the WP_PLUGIN_DIR constant like this

require_once WP_PLUGIN_DIR . '/my-core/updare/plugin-update-checker.php';
Moshe Gross
  • 1,206
  • 1
  • 7
  • 14