Yoast / yoast-acf-analysis

WordPress plugin that adds the content of all ACF fields to the Yoast SEO score analysis.
https://wordpress.org/plugins/acf-content-analysis-for-yoast-seo/
GNU General Public License v3.0
61 stars 20 forks source link

PHP Notices when editing posts that have an ACF Image field #292

Open Pixelrobin opened 3 years ago

Pixelrobin commented 3 years ago

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

jpumfrey commented 3 years ago

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.