I am trying to add a function from plugin 1(wp job manager) to plugin 2(woocommerce).
I have decided to do this by including the php file from plugin 1, however I am unable to locate the file directory. I have used:
include( plugin_dir_path( __FILE__ ) . 'wp-job-manager/includes/class-wp-job-manager-applications.php');
but it returns the following error:
Warning:
include(/home/content/p3pnexwpnas05_data02/78/2394078/html/wp-content/themes/listify-child/wp-job-manager/includes/class-wp-job-manager-applications.php): failed to open stream: No such file or directory in
/home/content/p3pnexwpnas05_data02/78/2394078/html/wp-content/themes/listify-child/functions.php
on line 77
Please advise me as I’ve been stuck on this issue for really long… Thanks!!!
WordPress setups have a constant
ABSPATH
defined (look at the bottom lines ofwp_config.php
) which points to the full and absolute path of the WordPress setup, so in your caseecho ABSPATH;
would return/home/content/p3pnexwpnas05_data02/78/2394078/html/
.For most installations, appending
wp-content/plugins/
to that string would point you to your plugins directory.However, in a WordPress configuration one can also customize the wp-content and or plugins directory to their own preference, so building plugins on
ABSPATH.'wp-content/plugins/
is not recommended. Unfortunately WordPress simply doesn’t have aget_absolute_pluginspath()
function or something available. A trick would be to fetch the plugins-URL, and remove the site-URL from it, so the remaining data is wp-content/plugins/ (or whatever the user has made of it). In code:Which in your case would return:
/home/content/p3pnexwpnas05_data02/78/2394078/html/wp-content/plugins/
You probably mean:
That gives you the directory path to the file that statement is in. So what that returns depends on where you run it. If you use this statement
in the main plugin file for wp_job_manager (probably wp_job_manager.php), then
plugin_dir_path(__FILE__)
give the path of the directory that file is in (the plugin directory).If you use it in some other file, you will need to adjust the rest of the path string accordingly.