Skip to content

Commit 7e3df0c

Browse files
authored
Merge pull request #67 from Yoast/stories/fix-asset-loading
Improve conditional Asset loading
2 parents 623a206 + a69694c commit 7e3df0c

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

inc/class-yoast-acf-analysis-assets.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Yoast_ACF_Analysis_Assets {
1515
public function init() {
1616
$this->plugin_data = get_plugin_data( AC_SEO_ACF_ANALYSIS_PLUGIN_FILE );
1717

18-
add_filter( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
18+
add_filter( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
1919
}
2020

2121
/**
@@ -28,27 +28,30 @@ public function enqueue_scripts() {
2828
$config = Yoast_ACF_Analysis_Facade::get_registry()->get( 'config' );
2929

3030
// Post page enqueue.
31-
if ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) {
31+
if ( wp_script_is( WPSEO_Admin_Asset_Manager::PREFIX . 'post-scraper' ) ) {
3232
wp_enqueue_script(
3333
'yoast-acf-analysis-post',
3434
plugins_url( '/js/yoast-acf-analysis.js', AC_SEO_ACF_ANALYSIS_PLUGIN_FILE ),
35-
array( 'jquery', 'yoast-seo-post-scraper', 'underscore' ),
36-
$this->plugin_data['Version']
35+
array( 'jquery', WPSEO_Admin_Asset_Manager::PREFIX . 'post-scraper', 'underscore' ),
36+
$this->plugin_data['Version'],
37+
true
3738
);
3839

3940
wp_localize_script( 'yoast-acf-analysis-post', 'YoastACFAnalysisConfig', $config->to_array() );
4041
}
4142

4243
// Term page enqueue.
43-
if ( 'term.php' === $pagenow ) {
44+
if ( wp_script_is( WPSEO_Admin_Asset_Manager::PREFIX . 'term-scraper' ) ) {
4445
wp_enqueue_script(
4546
'yoast-acf-analysis-term',
4647
plugins_url( '/js/yoast-acf-analysis.js', AC_SEO_ACF_ANALYSIS_PLUGIN_FILE ),
47-
array( 'jquery', 'yoast-seo-term-scraper' ),
48-
$this->plugin_data['Version']
48+
array( 'jquery', WPSEO_Admin_Asset_Manager::PREFIX . 'term-scraper' ),
49+
$this->plugin_data['Version'],
50+
true
4951
);
5052

5153
wp_localize_script( 'yoast-acf-analysis-term', 'YoastACFAnalysisConfig', $config->to_array() );
5254
}
5355
}
56+
5457
}

js/src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ App.prototype.bindListeners = function(){
2222

2323
if(helper.acf_version >= 5){
2424

25-
acf.add_action('ready', function () {
25+
jQuery(function(){
2626

2727
replaceVars.updateReplaceVars(collect);
2828

js/yoast-acf-analysis.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ App.prototype.bindListeners = function(){
2323

2424
if(helper.acf_version >= 5){
2525

26-
acf.add_action('ready', function () {
26+
jQuery(function(){
2727

2828
replaceVars.updateReplaceVars(collect);
2929

0 commit comments

Comments
 (0)