dirname( __FILE__) returning wrong directory inside plugin

Inside my plugin I'm adding the Advanced Custom Fields files. Part of including it in the plugin is changing the default directories using dirname(__FILE__).

In step 3, include_once works fine. So, ACF works, but without stylesheets or scripts, because in steps 1 and 2, I get the following for the stylesheets and scripts that ACF enques:

http://example.com/templates/wp-starter/nfs/c05/h03/mnt/70376/domains/example.com/html/templates/wp-starter/wp-content/plugins/simple/acf/css/global.css?ver=5.0.0

This is what I would like to get:

http://markrummel.com/templates/wp-starter/wp-content/plugins/simple/acf/css/global.css?ver=5.0.0.

I am using Media Temple's grid server (shared hosting).

Here is the relevent code from my plugin:

// 1. Customize ACF path
add_filter('acf/settings/path', 'my_acf_settings_path');

function my_acf_settings_path( $path ) {
    // update path
    $path = dirname( __FILE__ ) . '/acf/';

    // return
    return $path;  
}

// 2. Customize ACF dir
add_filter('acf/settings/dir', 'my_acf_settings_dir');

function my_acf_settings_dir( $dir ) {
    // update path
    $dir = dirname( __FILE__ ) . '/acf/';

    // return
    return $dir;  
}

// 3. Include ACF
include_once( dirname( __FILE__ ) . '/acf/acf.php' );

How can I get the correct directory?

Topic advanced-custom-fields shared-hosting plugins Wordpress

Category Web


echo plugins_url('Path_to_the_file_you_want_inside_plugin', __FILE__);

I resolved the issue by using $dir = plugins_url() . '/simple/acf/'; in step 2. I kept everything else the same.

// 2. Customize ACF dir
add_filter('acf/settings/dir', 'my_acf_settings_dir');

function my_acf_settings_dir( $dir ) { 
  // update path
  $dir = plugins_url() . '/simple/acf/';

  // return
  return $dir; 
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.