user2983292
user2983292

Reputation: 33

Requiring a file from another WordPress plugin

I don't appear to be able to require a PHP file that is part of another plugin.

Let's say we're trying to include /wp-content/plugins/plugin-from/src/classes/admin-class.php

The require_once statements that we've tried so far provide a "no such file or directory" error, though declaring a class with the same name as the one included in admin-class.php returns a cannot redeclare class" error.

None of the following methods have produced results:

require_once 'admin-class.php';
require_once '../../plugin-from/src/classes/admin-class.php';
require_once __DIR__ . '/../../plugin-from/src/classes/admin-class.php';

Declaring a global object reference and calling it also returned NULL from var_dump

Once this is working the plan is to instantiate an object of the class in admin-class.php and pass a variable to it.

Upvotes: 2

Views: 4289

Answers (1)

Shellbot
Shellbot

Reputation: 276

Try:

require_once( ABSPATH . '/wp-content/plugins/plugin-from/src/classes/admin-class.php');

Upvotes: 3

Related Questions