• Resolved drewibt

    (@drewibt)


    Hi, I would like to make you aware of an error I encountered while attempting to use the plugin on PHP 8+. When attempting to load the assets listed on the backend for each page dynamically, there would be a 500 admin ajax error in the console. WP Debug enabled didn’t reveal the source of the problem. However my PHP log indicated a problem at the following location:

    PHP Warning: Undefined array key “script_src_or_inline_and_noscript_inline_tags” in /chroot/home/ae3909cd/bcda6510ff.nxcli.io/html/wp-content/plugins/wp-asset-clean-up/templates/meta-box-loaded-assets/_assets-hardcoded-list.php on line 46
    [27-Feb-2023 18:05:47 UTC] PHP Fatal error: Uncaught TypeError: array_unique(): Argument #1 ($array) must be of type array, null given in /chroot/home/ae3909cd/bcda6510ff.nxcli.io/html/wp-content/plugins/wp-asset-clean-up/templates/meta-box-loaded-assets/_assets-hardcoded-list.php:46

    After investigating, it appeared that on line 46 of that particular file the array key needed addressing to check if an array key exists. I applied an isset conditional statement here and now the ajax error no longer appears, and assets can now finally load again on the edit mode of each page for PHP version 8+. The problem doesn’t exist on PHP 7.4 and below, likely because of strictness being increased in newer versions of PHP for existing objects/arrays.

    I would appreciate if this change could be implemented in future versions, so that I don’t have to go into the core plugin files to make the update each time the plugin has a new version release.

    Many Thanks

    Drew

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Gabe Livan

    (@gabelivan)

    @drewibt many thanks for letting me know about it. I have to admit that this suggests no SCRIPTS of any kind are loaded on the pages for which you are trying to load the assets list (correct me if I’m wrong). This would happen very rarely and indeed, array_unique() is applied incorrectly in this instance.

    I’ve updated the development version that shouldn’t have this problem. The bug will be added to the next tag release. Meanwhile, can you download the development version and let me know how it works. Here’s how to do it: https://www.assetcleanup.com/docs/how-to-get-the-development-version-of-asset-cleanup/

    Thread Starter drewibt

    (@drewibt)

    Thank you for updating this so soon, the development version works great! I have been noticing more often with the newer versions of PHP recently that instances like this where specific checks for data or data type existing like arrays are causing fatal errors and preventing further scripts from performing. As mentioned 7.4 works great, but newer versions of WP are prompting PHP updates and do help with site speed, so thought I’d flag it as we do find this plugin very useful ??

    Thanks again.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP 8+ – admin ajax 500 error’ is closed to new replies.