1

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?

  • best place to ask this question is in the AFC support forums. – Mark Kaplun Oct 13 '14 at 13:53
  • @MarkKaplun It is not directly ACF-related. I'm calling for dirname(__FILE__) inside a very simple plugin (plugins/simple/simple.php). If I echo it out right there in the plugin it is still the incorrect directory - it isn't that ACF is doing something weird to it. – Mark Rummel Oct 13 '14 at 13:58
  • What directory path do you get? Also, be aware that both __FILE__ and dirname() are pure PHP so there is a good chance the question is off-topic. – s_ha_dum Oct 13 '14 at 15:29
  • @MarkRummel, from your description your problems is with URLs not directories. In addition it is unlikely that dirname(__FILE__) is returning wrong value, it is much more likely you use it in the wrong place. If you need to find out the right place you need to understand how ACF works, and I am willing to put money that you don't use the ACF filters correctly. – Mark Kaplun Oct 13 '14 at 16:32
  • Looking closer it appears the directories are working correctly, but it has an issue when creating the URLs for the scripts and directories. Similar questions have been asked on the ACF forum, but have no solutions yet. I modified this question a bit and moved it over to Stackoverflow. – Mark Rummel Oct 13 '14 at 17:58
1

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; 
}
-1
echo plugins_url('Path_to_the_file_you_want_inside_plugin', __FILE__);
  • 1
    Please explain how your solution can solve the problem. A single line of code is not considered a good answer. – Jack Johansson May 28 '18 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.