Home › Forums › Backend Issues (wp-admin) › ReferenceError: acf is not defined
Greetings from Belgium! First of all: love your plugin!
I have some trouble with a project due to an upgrade from ACF 3.x to 4.2.2. This is a project on WordPress 3.6.1 with a custom plugin.
In this custom plugin I show the acf fields on the edit page. Everything works fine except for the wysiwyg editors – they don’t appear due to a javascript error:
ReferenceError: acf is not defined
acf.post_id = 0;
admin....did=382 (regel 220)
It seems as though input.min.js (and fields.min.js?) doesn’t get included. With ACF version 3.x I had a acf_form_wp_head() that dealt with the correct includes – it seems as though this doesn’t work anymore in ACF version 4.x.
Do I have to use an other function to include the right javascript files?
Hi @annelyze
I can’t remember when that function was fazed out, but you should be using the acf/input/admin_head
action instead.
Am I right in assuming that you are running the acf_form_wp_head
function in the admin_head action?
If so, all you need to do is change to this:
do_action('acf/input/admin_head');
Thanks
E
Hello Elliot
Thx for the quick reply. This however didn’t fix the problem.
If I take a look at the acf_form_wp_head
function I see the following:
function acf_form_wp_head()
{
do_action('acf/input/admin_head');
}
So in fact I already did the do_action part, only from within a function (which I called in my custom code).
I’ve tried some other placements for the do_action in my code but this didn’t work either. I’m not a frequent WordPress user so I’m not sure what to try next.
This is the current situation:
I’ve added a hook to a custom function:
add_action('admin_head', 'cjobs_admin_head');
In that function I’ve put the do_action:
function cjobs_admin_head()
{
do_action('acf/input/admin_head');
}
This is already something different than the code I used in version 3.x. In that version all I had to do was call the acf_form_wp_head
function just before parsing the acf fields.
This is the acf_form_wp_head
function in version 3.x:
function acf_form_wp_head()
{
// global vars
global $post, $acf;
// Style
echo '<link rel="stylesheet" type="text/css" href="'.$acf->dir.'/css/global.css?ver=' . $acf->version . '" />';
echo '<link rel="stylesheet" type="text/css" href="'.$acf->dir.'/css/input.css?ver=' . $acf->version . '" />';
// Javascript
echo '<script type="text/javascript" src="'.$acf->dir.'/js/input-actions.js?ver=' . $acf->version . '" ></script>';
// add user js + css
do_action('acf_head-input');
}
Hi @annelyze
Perhaps you should take a look at the /core/controllers/input.php file. This will give you examples of how to use the actions and where to use them for ACF to render the necessary scripts.
Thanks
E
Hi Elliot
Still no luck on getting the right scripts to load at the right moment 🙁
I must be overlooking something but I just don’t see what.
I’ve solved the problem for now by loading them manually.
Thanks for your time!
annelyze
I just fixed the issue on ACF 4.4.1 version
acf not defined…
The problem was in loading the scripts in the correct order.
What I’ve done is:
open “wp-content/plugins/advanced-custom-fields/acf.php” and go and comment the lines from 524 to 528 the init of the input.min.js then open “wp-admin/admin-header.php” and right after the <title></title>
include these 2 scripts:
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script type='text/javascript' src='http://yourdomain.com/wp-content/plugins/advanced-custom-fields/js/js/input.min.js'></script>
*move the input.min.js into new js folder into js to not get conflicts:)
save all the changes and you will see you wouldn’t encounter this issue just reload the CPT add new/edit page and there you go.
Hope this will solve everybody’s issue, it’s only temporary once we get an update from @elliot 🙂 hope the 4.4.2 will fix this issue.
Cheers mates.
The topic ‘ReferenceError: acf is not defined’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.