Title: Admin Javascript Error
Last modified: September 11, 2020

---

# Admin Javascript Error

 *  Resolved [David Goring](https://wordpress.org/support/users/dg12345/)
 * (@dg12345)
 * [5 years, 9 months ago](https://wordpress.org/support/topic/admin-javascript-error-2/)
 * I’ve noticed that your plugin enqueues its javascript across the whole admin.
 * However it requires the acf scripts to run first so on many of the pages it causes
   an error.
 * Instead of enqueueing everywhere could you only enqueue with ACF
 * I believe you could achieve this by changing the follow
 * classes/main.php line 9 – 10
 *     ```
       		add_action( 'admin_footer', [ $this, 'register_assets' ], 1 );
       		add_action( 'admin_footer', [ $this, 'enqueue_assets' ] );
       ```
   
 * to
 *     ```
       		add_action( 'acf/enqueue_scripts', [ $this, 'register_assets' ], 1 );
       		add_action( 'acf/enqueue_scripts', [ $this, 'enqueue_assets' ] );
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [keepyourreceipt](https://wordpress.org/support/users/keepyourreceipt/)
 * (@keepyourreceipt)
 * [5 years, 6 months ago](https://wordpress.org/support/topic/admin-javascript-error-2/#post-13730961)
 * I’m seeing the same issue. It doesn’t appear to be causing the admin to fail,
   but it would definitely be a good idea to only require this with ACF (as mentioned
   by Dave above).
 * Any movement on this?
 *  [keepyourreceipt](https://wordpress.org/support/users/keepyourreceipt/)
 * (@keepyourreceipt)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/admin-javascript-error-2/#post-14117727)
 * Wanted to follow up on this.
 * I tried updating the classes/main.php file with the patch mentioned by [@dg12345](https://wordpress.org/support/users/dg12345/).
   This did resolve the admin console error, but when I went to the page edit screen,
   the preview images didn’t load.
 * I added a check to the /assets/js/acf-flexible-content-preview.js file to make
   sure `acf` is defined before trying to access it’s methods:
 * `if ( typeof acf != 'undefined' && typeof acf.getField == 'function' ) {`
    `...``}`
 * This isn’t the best fix, as the plugin is still enqueueing assets when they’re
   not needed, but it appears to fix the issue.
 * Just wanted to share incase anyone else is looking for a temp fix for this before
   the plugin core is updated.
    -  This reply was modified 5 years, 3 months ago by [keepyourreceipt](https://wordpress.org/support/users/keepyourreceipt/).
 *  Plugin Author [Jameel Moses](https://wordpress.org/support/users/jameelmoses/)
 * (@jameelmoses)
 * [5 years ago](https://wordpress.org/support/topic/admin-javascript-error-2/#post-14486820)
 * This has been fixed in 1.0.5

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Admin Javascript Error’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/acf-flexible-content-preview_dcddec.
   svg)
 * [Flexible Content Preview for Advanced Custom Fields](https://wordpress.org/plugins/acf-flexible-content-preview/)
 * [Support Threads](https://wordpress.org/support/plugin/acf-flexible-content-preview/)
 * [Active Topics](https://wordpress.org/support/plugin/acf-flexible-content-preview/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/acf-flexible-content-preview/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/acf-flexible-content-preview/reviews/)

## Tags

 * [script error](https://wordpress.org/support/topic-tag/script-error/)

 * 3 replies
 * 3 participants
 * Last reply from: [Jameel Moses](https://wordpress.org/support/users/jameelmoses/)
 * Last activity: [5 years ago](https://wordpress.org/support/topic/admin-javascript-error-2/#post-14486820)
 * Status: resolved