yoast-acf-analysis icon indicating copy to clipboard operation
yoast-acf-analysis copied to clipboard

PHP Notices when editing posts that have an ACF Image field

Open Pixelrobin opened this issue 3 years ago • 1 comments

  • [x] I've read and understood the contribution guidelines.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Please give us a description of what happened.

When editing a post that has an Image ACF field, the following PHP notices are thrown in the debug log:

[27-Jul-2021 18:42:16 UTC] PHP Notice:  Undefined index: posts_per_page in .../wp-admin/includes/ajax-actions.php on line 3006
[27-Jul-2021 18:42:16 UTC] PHP Warning:  Division by zero in .../wp-admin/includes/ajax-actions.php on line 3006

Please describe what you expected to happen and why.

No PHP notices to be thrown.

How can we reproduce this behavior?

  1. I set up logging in my wp-config.php with:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );
  1. Create an ACF field group that contains an Image field and set it to show on a post type (any post type)
  2. Create or edit a post that should have that ACF field
  3. PHP notices are logged to the debug.log

Technical info

  • WordPress version: 5.8
  • ACF Content Analysis for Yoast SEO version: 3.0.1
  • Yoast SEO version: 16.8
  • ACF type: pro
  • ACF version: 5.9.9
  • Relevant plugins in case of a bug:

Pixelrobin avatar Jul 27 '21 19:07 Pixelrobin

Came across this issue recently flooding my debug log when editing posts across our sites using this plugin. As a temporary solution, I have updated the yoast-acf-analysis.js refresh function to include the missing query parameter:

var refresh = function( attachment_ids ) {
	var uncached = cache.getUncached( attachment_ids, "attachment" );

	if ( uncached.length === 0 ) {
		return;
	}

	window.wp.ajax.post( "query-attachments", {
		query: {
			post__in: uncached,
			posts_per_page: 1
		},
	} ).done( function( attachments ) {
		_.each( attachments, function( attachment ) {
			cache.set( attachment.id, attachment, "attachment" );
			window.YoastACFAnalysis.maybeRefresh();
		} );
	} );
};

i.e. posts_per_page: 1 in the post query around line ~122.

wp-content\plugins\acf-content-analysis-for-yoast-seo\js\yoast-acf-analysis.js

Hope this helps.

jpumfrey avatar Sep 14 '21 03:09 jpumfrey