0

I am absolutely terrible with using 'require', 'include' and 'require_once' to locate my files and include them inside other .php files and would like some assistance.

The class where it's located:

htdocs (Main)  
- wp-content  
-- mu-plugins  
--- extensions  
---- _process  
----- pp  
------ classes  
------- Control.php (Class)

Now I need to require_once the class 'Control.php' in the following structure:

htdocs (Main)  
- wp-content  
-- mu-plugins  
--- extensions  
---- _process  
----- oc  
------ run.php (Need to call inside this file)

How would I be able to achieve this? I've tried everything and can't figure out how to call files and structures.

I've tried this and it didn't work inside run.php:

require_once (__DIR__.'/../pp/classes/Control.php');
M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
Sema
  • 81
  • 6

1 Answers1

3

Personally, when I have to make the include or require of the case, I create a constant and use the global variable SERVER.

Example.

define( "PATH", $_SERVER['DOCUMENT_ROOT']);
require PATH . "/wp-content/mu-plugins/extensions/_process/pp/classes/Control.php"

In this way, using the SERVER variable, your path will always start from the main root of the site.

I hope it helps you.

Having said that, being in Wordpress, why don't you use the wp-load.php file?

By including that file in your project, you automatically have everything that is part of wordpress available to you. Think about it, it might come in handy later in the other files.

Enjoy :)

Stefano Pascazi
  • 363
  • 1
  • 11