I'm adding Advanced Custom Fields Pro (v5) to a simple plugin I'm creating.
I'm using the tutorial on the ACF website: Distributing ACF in a plugin/theme. The tutorial calls for using get_stylesheet_directory()
, but that is for a theme. I replaced that with dirname(__FILE__)
.
In step 3, include_once
works fine with dirname(__FILE__)
. Steps 1 and 2 also work for including files, but I run into an issue when Javascript and CSS files are included by ACF. It returns URLs like the following:
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://example.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 relevant code from plugins/simple/simple.php
:
// 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 URL for the scripts and stylesheets?
I tried using the following in config.php
, but it didn't work either:
define('WP_CONTENT_DIR', 'http://example.com/templates/wp-starter/wp-content');
define('WP_PLUGIN_DIR', 'http://example.com/templates/wp-starter/wp-content/plugins');
I could enqueue
these scripts and stylesheets separately, but it would be nice if I didn't have to do that.