Skip to content

Commit

Permalink
Merge pull request #276 from Yoast/P3-167-remove-acf4-code
Browse files Browse the repository at this point in the history
Remove ACF4 code
  • Loading branch information
JesserH committed Sep 16, 2020
2 parents d244224 + fa638dd commit d4746a7
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 204 deletions.
3 changes: 1 addition & 2 deletions inc/ac-yoast-seo-acf-content-analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ protected function get_blacklist_type() {
/**
* Disable Pro fields for anything but ACF 5 pro.
*
* - It is not worth supporting the Pro Addons to v4, as Pro users can just switch to v5.
* - ACF v5 FREE on the other hand does not support these fields either.
* - ACF v5 FREE does not support these fields.
*/
if ( ! defined( 'ACF_PRO' ) || ! ACF_PRO ) {

Expand Down
40 changes: 1 addition & 39 deletions js/src/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global YoastSEO, acf, _, jQuery, wp */
/* global YoastSEO, acf, jQuery, */
var config = require( "./config/config.js" );
var helper = require( "./helper.js" );
var collect = require( "./collect/collect.js" );
Expand All @@ -14,36 +14,6 @@ var App = function() {
this.bindListeners();
};

/**
* ACF 4 Listener.
*
* @param {Array} fieldSelectors List of field selectors.
* @param {string} wysiwygSelector Element selector for WYSIWYG fields.
* @param {Array} fieldSelectorsWithoutWysiwyg List of fields.
*
* @returns {void}
*/
App.prototype.acf4Listener = function( fieldSelectors, wysiwygSelector, fieldSelectorsWithoutWysiwyg ) {
replaceVars.updateReplaceVars( collect );

var fieldsWithoutWysiwyg = jQuery( "#post-body, #edittag" ).find( fieldSelectorsWithoutWysiwyg.join( "," ) );
var fields = jQuery( "#post-body, #edittag" ).find( fieldSelectors.join( "," ) );

fieldsWithoutWysiwyg.on( "change", this.maybeRefresh.bind( this ) );
// Do not ignore Wysiwyg fields for the purpose of Replace Vars.
fields.on( "change", replaceVars.updateReplaceVars.bind( this, collect ) );

if ( YoastSEO.wp._tinyMCEHelper ) {
jQuery( wysiwygSelector ).each( function() {
YoastSEO.wp._tinyMCEHelper.addEventHandler( this.id, [ "input", "change", "cut", "paste" ],
replaceVars.updateReplaceVars.bind( this, collect ) );
} );
}

// Also refresh on media close as attachment data might have changed
wp.media.frame.on( "close", this.maybeRefresh );
};

/**
* ACF 5 Listener.
*
Expand Down Expand Up @@ -104,14 +74,6 @@ App.prototype.refreshAnalysisAndReplaceVars = function() {
App.prototype.bindListeners = function() {
if ( helper.acf_version >= 5 ) {
jQuery( this.acf5Listener.bind( this ) );
} else {
var fieldSelectors = config.fieldSelectors.slice( 0 );
var wysiwygSelector = "textarea[id^=wysiwyg-acf]";

// Ignore Wysiwyg fields because they trigger a refresh in Yoast SEO itself
var fieldSelectorsWithoutWysiwyg = _.without( fieldSelectors, wysiwygSelector );

jQuery( document ).on( "acf/setup_fields", this.acf4Listener.bind( this, fieldSelectors, wysiwygSelector, fieldSelectorsWithoutWysiwyg ) );
}
};

Expand Down
22 changes: 0 additions & 22 deletions js/src/collect/collect-v4.js

This file was deleted.

1 change: 0 additions & 1 deletion js/src/collect/collect.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ Collect.prototype.getData = function() {
if ( helper.acf_version >= 5 ) {
return require( "./collect-v5.js" )();
}
return require( "./collect-v4.js" );
};

Collect.prototype.filterBlacklistType = function( field_data ) {
Expand Down
99 changes: 18 additions & 81 deletions js/yoast-acf-analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,6 @@ var App = function() {
this.bindListeners();
};

/**
* ACF 4 Listener.
*
* @param {Array} fieldSelectors List of field selectors.
* @param {string} wysiwygSelector Element selector for WYSIWYG fields.
* @param {Array} fieldSelectorsWithoutWysiwyg List of fields.
*
* @returns {void}
*/
App.prototype.acf4Listener = function( fieldSelectors, wysiwygSelector, fieldSelectorsWithoutWysiwyg ) {
replaceVars.updateReplaceVars( collect );

var fieldsWithoutWysiwyg = jQuery( "#post-body, #edittag" ).find( fieldSelectorsWithoutWysiwyg.join( "," ) );
var fields = jQuery( "#post-body, #edittag" ).find( fieldSelectors.join( "," ) );

fieldsWithoutWysiwyg.on( "change", this.maybeRefresh.bind( this ) );
// Do not ignore Wysiwyg fields for the purpose of Replace Vars.
fields.on( "change", replaceVars.updateReplaceVars.bind( this, collect ) );

if ( YoastSEO.wp._tinyMCEHelper ) {
jQuery( wysiwygSelector ).each( function() {
YoastSEO.wp._tinyMCEHelper.addEventHandler( this.id, [ "input", "change", "cut", "paste" ],
replaceVars.updateReplaceVars.bind( this, collect ) );
} );
}

// Also refresh on media close as attachment data might have changed
wp.media.frame.on( "close", this.maybeRefresh );
};

/**
* ACF 5 Listener.
*
Expand Down Expand Up @@ -105,14 +75,6 @@ App.prototype.refreshAnalysisAndReplaceVars = function() {
App.prototype.bindListeners = function() {
if ( helper.acf_version >= 5 ) {
jQuery( this.acf5Listener.bind( this ) );
} else {
var fieldSelectors = config.fieldSelectors.slice( 0 );
var wysiwygSelector = "textarea[id^=wysiwyg-acf]";

// Ignore Wysiwyg fields because they trigger a refresh in Yoast SEO itself
var fieldSelectorsWithoutWysiwyg = _.without( fieldSelectors, wysiwygSelector );

jQuery( document ).on( "acf/setup_fields", this.acf4Listener.bind( this, fieldSelectors, wysiwygSelector, fieldSelectorsWithoutWysiwyg ) );
}
};

Expand All @@ -134,7 +96,7 @@ App.prototype.maybeRefresh = function() {

module.exports = App;

},{"./collect/collect.js":6,"./config/config.js":7,"./helper.js":8,"./replacevars.js":10}],2:[function(require,module,exports){
},{"./collect/collect.js":5,"./config/config.js":6,"./helper.js":7,"./replacevars.js":9}],2:[function(require,module,exports){
/* global _ */
var cache = require( "./cache.js" );

Expand Down Expand Up @@ -237,30 +199,6 @@ Cache.prototype.clear = function( store ) {
module.exports = new Cache();

},{}],4:[function(require,module,exports){
/* global jQuery */

var config = require( "./../config/config.js" );
var fieldSelectors = config.fieldSelectors;

var field_data = [];

var fields = jQuery( "#post-body, #edittag" ).find( fieldSelectors.join( "," ) );

fields.each( function() {
var $el = jQuery( this ).parents( ".field" ).last();

field_data.push( {
$el: $el,
key: $el.data( "field_key" ),
name: $el.data( "field_name" ),
type: $el.data( "field_type" ),
post_meta_key: $el.data( "field_name" ),
} );
} );

module.exports = field_data;

},{"./../config/config.js":7}],5:[function(require,module,exports){
/* global _, acf, jQuery, wp */
module.exports = function() {
var outerFieldsName = [
Expand Down Expand Up @@ -349,7 +287,7 @@ module.exports = function() {
return fields;
};

},{}],6:[function(require,module,exports){
},{}],5:[function(require,module,exports){
/* global _ */

var config = require( "./../config/config.js" );
Expand Down Expand Up @@ -409,7 +347,6 @@ Collect.prototype.getData = function() {
if ( helper.acf_version >= 5 ) {
return require( "./collect-v5.js" )();
}
return require( "./collect-v4.js" );
};

Collect.prototype.filterBlacklistType = function( field_data ) {
Expand Down Expand Up @@ -446,18 +383,18 @@ Collect.prototype.sort = function( field_data ) {

module.exports = new Collect();

},{"./../config/config.js":7,"./../helper.js":8,"./../scraper-store.js":11,"./collect-v4.js":4,"./collect-v5.js":5}],7:[function(require,module,exports){
},{"./../config/config.js":6,"./../helper.js":7,"./../scraper-store.js":10,"./collect-v5.js":4}],6:[function(require,module,exports){
/* globals YoastACFAnalysisConfig */
module.exports = YoastACFAnalysisConfig;

},{}],8:[function(require,module,exports){
},{}],7:[function(require,module,exports){
var config = require( "./config/config.js" );

module.exports = {
acf_version: parseFloat( config.acfVersion, 10 ),
};

},{"./config/config.js":7}],9:[function(require,module,exports){
},{"./config/config.js":6}],8:[function(require,module,exports){
/* global jQuery, YoastSEO, wp, YoastACFAnalysis: true */
/* exported YoastACFAnalysis */

Expand All @@ -469,7 +406,7 @@ wp.domReady( function() {
}
} );

},{"./app.js":1}],10:[function(require,module,exports){
},{"./app.js":1}],9:[function(require,module,exports){
/* global _, jQuery, YoastSEO, YoastReplaceVarPlugin */

var config = require( "./config/config.js" );
Expand Down Expand Up @@ -526,7 +463,7 @@ module.exports = {
updateReplaceVars: updateReplaceVars,
};

},{"./config/config.js":7}],11:[function(require,module,exports){
},{"./config/config.js":6}],10:[function(require,module,exports){
var config = require( "./config/config.js" );

var scraperObjects = {
Expand Down Expand Up @@ -624,7 +561,7 @@ module.exports = {
getScraper: getScraper,
};

},{"./config/config.js":7,"./scraper/scraper.block_preview.js":12,"./scraper/scraper.email.js":13,"./scraper/scraper.gallery.js":14,"./scraper/scraper.image.js":15,"./scraper/scraper.link.js":16,"./scraper/scraper.taxonomy.js":17,"./scraper/scraper.text.js":18,"./scraper/scraper.textarea.js":19,"./scraper/scraper.url.js":20,"./scraper/scraper.wysiwyg.js":21}],12:[function(require,module,exports){
},{"./config/config.js":6,"./scraper/scraper.block_preview.js":11,"./scraper/scraper.email.js":12,"./scraper/scraper.gallery.js":13,"./scraper/scraper.image.js":14,"./scraper/scraper.link.js":15,"./scraper/scraper.taxonomy.js":16,"./scraper/scraper.text.js":17,"./scraper/scraper.textarea.js":18,"./scraper/scraper.url.js":19,"./scraper/scraper.wysiwyg.js":20}],11:[function(require,module,exports){
/* global _ */

var Scraper = function() {};
Expand All @@ -645,7 +582,7 @@ Scraper.prototype.scrape = function( fields ) {

module.exports = Scraper;

},{}],13:[function(require,module,exports){
},{}],12:[function(require,module,exports){
/* global _ */

var Scraper = function() {};
Expand All @@ -666,7 +603,7 @@ Scraper.prototype.scrape = function( fields ) {

module.exports = Scraper;

},{}],14:[function(require,module,exports){
},{}],13:[function(require,module,exports){
/* global _, jQuery */

var attachmentCache = require( "./../cache/cache.attachments.js" );
Expand Down Expand Up @@ -708,7 +645,7 @@ Scraper.prototype.scrape = function( fields ) {

module.exports = Scraper;

},{"./../cache/cache.attachments.js":2}],15:[function(require,module,exports){
},{"./../cache/cache.attachments.js":2}],14:[function(require,module,exports){
/* global _ */

var attachmentCache = require( "./../cache/cache.attachments.js" );
Expand Down Expand Up @@ -746,7 +683,7 @@ Scraper.prototype.scrape = function( fields ) {

module.exports = Scraper;

},{"./../cache/cache.attachments.js":2}],16:[function(require,module,exports){
},{"./../cache/cache.attachments.js":2}],15:[function(require,module,exports){
/* global _ */
require( "./../scraper-store.js" );

Expand Down Expand Up @@ -781,7 +718,7 @@ Scraper.prototype.scrape = function( fields ) {

module.exports = Scraper;

},{"./../scraper-store.js":11}],17:[function(require,module,exports){
},{"./../scraper-store.js":10}],16:[function(require,module,exports){
/* global _, acf */

var Scraper = function() {};
Expand Down Expand Up @@ -837,7 +774,7 @@ Scraper.prototype.scrape = function( fields ) {

module.exports = Scraper;

},{}],18:[function(require,module,exports){
},{}],17:[function(require,module,exports){
/* global _ */

var config = require( "./../config/config.js" );
Expand Down Expand Up @@ -892,7 +829,7 @@ Scraper.prototype.isHeadline = function( field ) {

module.exports = Scraper;

},{"./../config/config.js":7}],19:[function(require,module,exports){
},{"./../config/config.js":6}],18:[function(require,module,exports){
/* global _ */

var Scraper = function() {};
Expand All @@ -913,7 +850,7 @@ Scraper.prototype.scrape = function( fields ) {

module.exports = Scraper;

},{}],20:[function(require,module,exports){
},{}],19:[function(require,module,exports){
/* global _ */

var Scraper = function() {};
Expand All @@ -936,7 +873,7 @@ Scraper.prototype.scrape = function( fields ) {

module.exports = Scraper;

},{}],21:[function(require,module,exports){
},{}],20:[function(require,module,exports){
/* global tinyMCE, _ */

var Scraper = function() {};
Expand Down Expand Up @@ -995,4 +932,4 @@ Scraper.prototype.scrape = function( fields ) {

module.exports = Scraper;

},{}]},{},[9]);
},{}]},{},[8]);
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"build": "browserify js/src/main.js -o js/yoast-acf-analysis.js",
"watch": "watchify js/src/main.js -o js/yoast-acf-analysis.js --poll --verbose --debug",
"test": "(cd tests/js/system/ && exec ../../../node_modules/.bin/nightwatch)",
"test-acf4": "(cd tests/js/system/ && exec ../../../node_modules/.bin/nightwatch --group general --group acf4)",
"test-acf5": "(cd tests/js/system/ && exec ../../../node_modules/.bin/nightwatch --group general --group acf5 --skiptags pro)",
"test-acf5pro": "(cd tests/js/system/ && exec ../../../node_modules/.bin/nightwatch --group general --group acf5)"
},
Expand Down
Loading

0 comments on commit d4746a7

Please sign in to comment.