How do i locate wordpress plugin directory?

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:

Read More
 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!!!

Related posts

Leave a Reply

2 comments

  1. WordPress setups have a constant ABSPATH defined (look at the bottom lines of wp_config.php) which points to the full and absolute path of the WordPress setup, so in your case echo 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 a get_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:

    $plugins_directory = ABSPATH.str_replace(site_url()."/","",plugins_url())."/";
    

    Which in your case would return:
    /home/content/p3pnexwpnas05_data02/78/2394078/html/wp-content/plugins/

  2. You probably mean:

    plugin_dir_path(__FILE__)
    

    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

    include( plugin_dir_path(__FILE__) . 'wp-job-manager/includes/class-wp-job-manager-applications.php');
    

    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.