From 180a56e59dd30a06ed4a2bb9e838b8109c2add4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Kr=C3=A4ftner?= Date: Fri, 25 Aug 2017 13:36:46 +0200 Subject: [PATCH 1/3] only enqueue js for post edit when Yoast SEO Metabox is active --- inc/class-yoast-acf-analysis-assets.php | 47 +++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/inc/class-yoast-acf-analysis-assets.php b/inc/class-yoast-acf-analysis-assets.php index 6b5c4aa2..2ffb37db 100755 --- a/inc/class-yoast-acf-analysis-assets.php +++ b/inc/class-yoast-acf-analysis-assets.php @@ -28,12 +28,13 @@ public function enqueue_scripts() { $config = Yoast_ACF_Analysis_Facade::get_registry()->get( 'config' ); // Post page enqueue. - if ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) { + if ( $this->is_metabox_active() ) { wp_enqueue_script( 'yoast-acf-analysis-post', plugins_url( '/js/yoast-acf-analysis.js', AC_SEO_ACF_ANALYSIS_PLUGIN_FILE ), array( 'jquery', 'yoast-seo-post-scraper', 'underscore' ), - $this->plugin_data['Version'] + $this->plugin_data['Version'], + true ); wp_localize_script( 'yoast-acf-analysis-post', 'YoastACFAnalysisConfig', $config->to_array() ); @@ -45,10 +46,50 @@ public function enqueue_scripts() { 'yoast-acf-analysis-term', plugins_url( '/js/yoast-acf-analysis.js', AC_SEO_ACF_ANALYSIS_PLUGIN_FILE ), array( 'jquery', 'yoast-seo-term-scraper' ), - $this->plugin_data['Version'] + $this->plugin_data['Version'], + true ); wp_localize_script( 'yoast-acf-analysis-term', 'YoastACFAnalysisConfig', $config->to_array() ); } } + + /** + * Test if the Metabox is actually active for the edit screen we are at. + * + * Adapted from Yoast SEO. + * + * @see WPSEO_Metabox::enqueue() + */ + public function is_metabox_active() { + + global $pagenow; + + // This is just an additional security net to ensure the global var is present. + if ( empty( $GLOBALS['wpseo_metabox'] ) || ! ( $GLOBALS['wpseo_metabox'] instanceof WPSEO_Metabox ) ) { + return false; + } + + /* @var $wpseo_metabox WPSEO_Metabox */ + $wpseo_metabox = $GLOBALS['wpseo_metabox']; + + $is_editor = WPSEO_Metabox::is_post_edit( $pagenow ); + + if ( + ( + ! $is_editor + && + /* Filter 'wpseo_always_register_metaboxes_on_admin' documented in wpseo-main.php */ + apply_filters( 'wpseo_always_register_metaboxes_on_admin', false ) === false + ) + || + $wpseo_metabox->is_metabox_hidden() === true + ) { + return false; + } + + return true; + + } + } From fddebb346c830206d52f8e32bf9caf4106366119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Kr=C3=A4ftner?= Date: Tue, 12 Sep 2017 15:23:51 +0200 Subject: [PATCH 2/3] directly use jQuery ready (as this is all acf.add_action('ready') does anyway) and this also fires in case document.ready has already been fired which is likely now that this is running from the footer --- js/src/app.js | 2 +- js/yoast-acf-analysis.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/js/src/app.js b/js/src/app.js index 7a6c7747..01b6f678 100644 --- a/js/src/app.js +++ b/js/src/app.js @@ -19,7 +19,7 @@ App.prototype.bindListeners = function(){ if(helper.acf_version >= 5){ var _self = this; - acf.add_action('ready', function () { + jQuery(function(){ _self.replaceVars = replaceVars.createReplaceVars(collect); acf.add_action('change remove append sortstop', _self.maybeRefresh); acf.add_action('change remove append sortstop', replaceVars.updateReplaceVars.bind(_self, collect, _self.replaceVars)); diff --git a/js/yoast-acf-analysis.js b/js/yoast-acf-analysis.js index 42c06a60..3321ea3b 100644 --- a/js/yoast-acf-analysis.js +++ b/js/yoast-acf-analysis.js @@ -20,7 +20,7 @@ App.prototype.bindListeners = function(){ if(helper.acf_version >= 5){ var _self = this; - acf.add_action('ready', function () { + jQuery(function(){ _self.replaceVars = replaceVars.createReplaceVars(collect); acf.add_action('change remove append sortstop', _self.maybeRefresh); acf.add_action('change remove append sortstop', replaceVars.updateReplaceVars.bind(_self, collect, _self.replaceVars)); @@ -235,8 +235,10 @@ Collect.prototype.getFieldData = function () { var used_types = _.uniq(_.pluck(field_data, 'type')); if(config.debug) { + console.log('Used types:') console.log(used_types); + } _.each(used_types, function(type){ @@ -838,5 +840,4 @@ var isTinyMCEAvailable = function(editorID) { }; module.exports = Scraper; -},{"./../scraper-store.js":11}]},{},[9]) -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9icm93c2VyLXBhY2svX3ByZWx1ZGUuanMiLCJqcy9zcmMvYXBwLmpzIiwianMvc3JjL2NhY2hlL2NhY2hlLmF0dGFjaG1lbnRzLmpzIiwianMvc3JjL2NhY2hlL2NhY2hlLmpzIiwianMvc3JjL2NvbGxlY3QvY29sbGVjdC12NC5qcyIsImpzL3NyYy9jb2xsZWN0L2NvbGxlY3QtdjUuanMiLCJqcy9zcmMvY29sbGVjdC9jb2xsZWN0LmpzIiwianMvc3JjL2NvbmZpZy9jb25maWcuanMiLCJqcy9zcmMvaGVscGVyLmpzIiwianMvc3JjL21haW4uanMiLCJqcy9zcmMvcmVwbGFjZXZhcnMuanMiLCJqcy9zcmMvc2NyYXBlci1zdG9yZS5qcyIsImpzL3NyYy9zY3JhcGVyL3NjcmFwZXIuZW1haWwuanMiLCJqcy9zcmMvc2NyYXBlci9zY3JhcGVyLmdhbGxlcnkuanMiLCJqcy9zcmMvc2NyYXBlci9zY3JhcGVyLmltYWdlLmpzIiwianMvc3JjL3NjcmFwZXIvc2NyYXBlci50YXhvbm9teS5qcyIsImpzL3NyYy9zY3JhcGVyL3NjcmFwZXIudGV4dC5qcyIsImpzL3NyYy9zY3JhcGVyL3NjcmFwZXIudGV4dGFyZWEuanMiLCJqcy9zcmMvc2NyYXBlci9zY3JhcGVyLnVybC5qcyIsImpzL3NyYy9zY3JhcGVyL3NjcmFwZXIud3lzaXd5Zy5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTtBQ0FBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7Q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Z2h0IGhhdmUgY2hhbmdlZFxuICAgICAgICAgICAgd3AubWVkaWEuZnJhbWUub24oJ2Nsb3NlJywgX3NlbGYubWF5YmVSZWZyZXNoLmJpbmQoX3NlbGYpICk7XG4gICAgICAgIH0pO1xuICAgIH1cblxufVxuXG5BcHAucHJvdG90eXBlLm1heWJlUmVmcmVzaCA9IGZ1bmN0aW9uKCl7XG5cbiAgICBpZiAoIGFuYWx5c2lzVGltZW91dCApIHtcbiAgICAgICAgd2luZG93LmNsZWFyVGltZW91dChhbmFseXNpc1RpbWVvdXQpO1xuICAgIH1cblxuICAgIGFuYWx5c2lzVGltZW91dCA9IHdpbmRvdy5zZXRUaW1lb3V0KCBmdW5jdGlvbigpIHtcblxuICAgICAgICBpZihjb25maWcuZGVidWcpe1xuICAgICAgICAgICAgY29uc29sZS5sb2coJ1JlY2FsY3VsYXRlLi4uJyArIG5ldyBEYXRlKCkgKyAnKEludGVybmFsKScpO1xuICAgICAgICB9XG5cbiAgICAgICAgWW9hc3RTRU8uYXBwLnBsdWdpblJlbG9hZGVkKGNvbmZpZy5wbHVnaW5OYW1lKTtcbiAgICB9LCBjb25maWcucmVmcmVzaFJhdGUgKTtcblxufTtcblxubW9kdWxlLmV4cG9ydHMgPSBBcHA7XG4iLCIvKiBnbG9iYWwgXyAqL1xudmFyIGNhY2hlID0gcmVxdWlyZSggXCIuL2NhY2hlLmpzXCIgKTtcblxudmFyIHJlZnJlc2ggPSBmdW5jdGlvbihhdHRhY2htZW50X2lkcyl7XG5cbiAgICB2YXIgdW5jYWNoZWQgPSBjYWNoZS5nZXRVbmNhY2hlZChhdHRhY2htZW50X2lkcywgJ2F0dGFjaG1lbnQnKTtcblxuICAgIGlmICh1bmNhY2hlZC5sZW5ndGggPT09IDApe1xuICAgICAgICByZXR1cm47XG4gICAgfVxuXG4gICAgd2luZG93LndwLmFqYXgucG9zdCgncXVlcnktYXR0YWNobWVudHMnLCB7XG4gICAgICAgICdxdWVyeSc6IHtcbiAgICAgICA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YXBlci1zdG9yZS5qc1wiICk7XG5cbnZhciBTY3JhcGVyID0gZnVuY3Rpb24oKSB7fTtcblxuU2NyYXBlci5wcm90b3R5cGUuc2NyYXBlID0gZnVuY3Rpb24oZmllbGRzKXtcblxuICAgIHZhciB0aGF0ID0gdGhpcztcblxuICAgIHZhciBhdHRhY2htZW50X2lkcyA9IFtdO1xuXG4gICAgZmllbGRzID0gXy5tYXAoZmllbGRzLCBmdW5jdGlvbihmaWVsZCl7XG5cbiAgICAgICAgaWYoZmllbGQudHlwZSAhPT0gJ2ltYWdlJyl7XG4gICAgICAgICAgICByZXR1cm4gZmllbGQ7XG4gICAgICAgIH1cblxuICAgICAgICBmaWVsZC5jb250ZW50ID0gJyc7XG5cbiAgICAgICAgdmFyIGF0dGFjaG1lbnRfaWQgPSBmaWVsZC4kZWwuZmluZCgnaW5wdXRbdHlwZT1oaWRkZW5dJykudmFsKCk7XG5cbiAgICAgICAgYXR0YWNobWVudF9pZHMucHVzaChhdHRhY2htZW50X2lkKTtcblxuICAgICAgICBpZihhdHRhY2htZW50Q2FjaGUuZ2V0KGF0dGFjaG1lbnRfaWQsICdhdHRhY2htZW50Jykpe1xuXG4gICAgICAgICAgICB2YXIgYXR0YWNobWVudCA9IGF0dGFjaG1lbnRDYWNoZS5nZXQoYXR0YWNobWVudF9pZCwgJ2F0dGFjaG1lbnQnKTtcblxuICAgICAgICAgICAgZmllbGQuY29udGVudCArPSAnPGltZyBzcmM9XCInICsgYXR0YWNobWVudC51cmwgKyAnXCIgYWx0PVwiJyArIGF0dGFjaG1lbnQuYWx0ICsgJ1wiIHRpdGxlPVwiJyArIGF0dGFjaG1lbnQudGl0bGUgKyAnXCI+JztcblxuICAgICAgICB9XG5cblxuICAgICAgICByZXR1cm4gZmllbGQ7XG4gICAgfSk7XG5cbiAgICBhdHRhY2htZW50Q2FjaGUucmVmcmVzaChhdHRhY2htZW50X2lkcyk7XG5cbiAgICByZXR1cm4gZmllbGRzO1xuXG59O1xuXG5tb2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RbdHlwZT1cImNoZWNrYm94XCJdOmNoZWNrZWQnKVxuICAgICAgICAgICAgICAgICAgICAubmV4dCgpLFxuICAgICAgICAgICAgICAgICd0ZXh0Q29udGVudCdcbiAgICAgICAgICAgICk7XG5cbiAgICAgICAgfWVsc2UgaWYoIGZpZWxkLiRlbC5maW5kKCdpbnB1dFt0eXBlPWNoZWNrYm94XTpjaGVja2VkJykubGVuZ3RoID4gMCApe1xuXG4gICAgICAgICAgICB0ZXJtcyA9IF8ucGx1Y2soXG4gICAgICAgICAgICAgICAgZmllbGQuJGVsLmZpbmQoJ2lucHV0W3R5cGU9Y2hlY2tib3hdOmNoZWNrZWQnKVxuICAgICAgICAgICAgICAgICAgICAucGFyZW50KCksXG4gICAgICAgICAgICAgICAgJ3RleHRDb250ZW50J1xuICAgICAgICAgICAgKTtcblxuICAgICAgICB9ZWxzZSBpZiggZmllbGQuJGVsLmZpbmQoJ3NlbGVjdCBvcHRpb246Y2hlY2tlZCcpLmxlbmd0aCA+IDAgKXtcblxuICAgICAgICAgICAgdGVybXMgPSBfLnBsdWNrKFxuICAgICAgICAgICAgICAgIGZpZWxkLiRlbC5maW5kKCdzZWxlY3Qgb3B0aW9uOmNoZWNrZWQnKSxcbiAgICAgICAgICAgICAgICAndGV4dENvbnRlbnQnXG4gICAgICAgICAgICApO1xuXG4gICAgICAgIH1cblxuICAgICAgICB0ZXJtcyA9IF8ubWFwKCB0ZXJtcywgZnVuY3Rpb24odGVybSl7IHJldHVybiB0ZXJtLnRyaW0oKTsgfSApO1xuXG4gICAgICAgIGlmKHRlcm1zLmxlbmd0aD4wKXtcbiAgICAgICAgICAgIGZpZWxkLmNvbnRlbnQgPSAnPHVsPlxcbjxsaT4nICsgdGVybXMuam9pbignPC9saT5cXG48bGk+JykgKyAnPC9saT5cXG48L3VsPic7XG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4gZmllbGQ7XG4gICAgfSk7XG5cbiAgICByZXR1cm4gZmllbGRzO1xuXG59O1xuXG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0b3JJRCApLmlzSGlkZGVuKCkgKSB7XG4gICAgICAgIHJldHVybiBmYWxzZTtcbiAgICB9XG5cbiAgICByZXR1cm4gdHJ1ZTtcbn07XG5cbm1vZHVsZS5leHBvcnRzID0gU2NyYXBlcjsiXX0= +},{"./../scraper-store.js":11}]},{},[9]); From 16d6b8807e292cb1feacf1ecc36303943a3e4656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Kr=C3=A4ftner?= Date: Tue, 12 Sep 2017 15:44:39 +0200 Subject: [PATCH 3/3] simplify checks by just checking if the scraper JS is enqueued --- inc/class-yoast-acf-analysis-assets.php | 48 +++---------------------- 1 file changed, 5 insertions(+), 43 deletions(-) diff --git a/inc/class-yoast-acf-analysis-assets.php b/inc/class-yoast-acf-analysis-assets.php index 2ffb37db..975c6881 100755 --- a/inc/class-yoast-acf-analysis-assets.php +++ b/inc/class-yoast-acf-analysis-assets.php @@ -15,7 +15,7 @@ class Yoast_ACF_Analysis_Assets { public function init() { $this->plugin_data = get_plugin_data( dirname( AC_SEO_ACF_ANALYSIS_PLUGIN_FILE ) ); - add_filter( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); + add_filter( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); } /** @@ -28,11 +28,11 @@ public function enqueue_scripts() { $config = Yoast_ACF_Analysis_Facade::get_registry()->get( 'config' ); // Post page enqueue. - if ( $this->is_metabox_active() ) { + if ( wp_script_is( WPSEO_Admin_Asset_Manager::PREFIX . 'post-scraper' ) ) { wp_enqueue_script( 'yoast-acf-analysis-post', plugins_url( '/js/yoast-acf-analysis.js', AC_SEO_ACF_ANALYSIS_PLUGIN_FILE ), - array( 'jquery', 'yoast-seo-post-scraper', 'underscore' ), + array( 'jquery', WPSEO_Admin_Asset_Manager::PREFIX . 'post-scraper', 'underscore' ), $this->plugin_data['Version'], true ); @@ -41,11 +41,11 @@ public function enqueue_scripts() { } // Term page enqueue. - if ( 'term.php' === $pagenow ) { + if ( wp_script_is( WPSEO_Admin_Asset_Manager::PREFIX . 'term-scraper' ) ) { wp_enqueue_script( 'yoast-acf-analysis-term', plugins_url( '/js/yoast-acf-analysis.js', AC_SEO_ACF_ANALYSIS_PLUGIN_FILE ), - array( 'jquery', 'yoast-seo-term-scraper' ), + array( 'jquery', WPSEO_Admin_Asset_Manager::PREFIX . 'term-scraper' ), $this->plugin_data['Version'], true ); @@ -54,42 +54,4 @@ public function enqueue_scripts() { } } - /** - * Test if the Metabox is actually active for the edit screen we are at. - * - * Adapted from Yoast SEO. - * - * @see WPSEO_Metabox::enqueue() - */ - public function is_metabox_active() { - - global $pagenow; - - // This is just an additional security net to ensure the global var is present. - if ( empty( $GLOBALS['wpseo_metabox'] ) || ! ( $GLOBALS['wpseo_metabox'] instanceof WPSEO_Metabox ) ) { - return false; - } - - /* @var $wpseo_metabox WPSEO_Metabox */ - $wpseo_metabox = $GLOBALS['wpseo_metabox']; - - $is_editor = WPSEO_Metabox::is_post_edit( $pagenow ); - - if ( - ( - ! $is_editor - && - /* Filter 'wpseo_always_register_metaboxes_on_admin' documented in wpseo-main.php */ - apply_filters( 'wpseo_always_register_metaboxes_on_admin', false ) === false - ) - || - $wpseo_metabox->is_metabox_hidden() === true - ) { - return false; - } - - return true; - - } - }