fb-instant-articles icon indicating copy to clipboard operation
fb-instant-articles copied to clipboard

PHP Fatal error: Cannot redeclare admin_notice__scrape_invalidation_failed()

Open abdusfauzi opened this issue 7 years ago • 3 comments

Steps required to reproduce the problem

  1. Install plugin
  2. Setup plugin
  3. Select and Edit multiple post, press save.

Expected Result

Nothing. Success message.

Actual Result

PHP Fatal error: Cannot redeclare admin_notice__scrape_invalidation_failed() (previously declared in /home/vocket/thevocket.com/web/app/plugins/fb-instant-articles/facebook-instant-articles.php:525)

Version Info

Please state exact versions, not latest or new.

  • Plugin version: 4.1.1
  • WordPress version: 4.9.8
  • PHP version: 7.2

Without the above information we are not able to debug the issue and will close it.

abdusfauzi avatar Oct 02 '18 03:10 abdusfauzi

I also meet this error or this cause happen from version of php 7.3

PHP message: PHP Fatal error: Cannot redeclare admin_notice__scrape_invalidation_failed() (previously declared in fb-instant-articles/facebook-instant-articles.php:492) in wp-content/plugins/fb-instant-articles/facebook-instant-articles.php on line 490" while reading response header from upstream, client: 141.101.107.148, server: camboland.com, request: "POST /wp-admin/post.php?post=6396&action=edit&meta-box-loader=1&meta-box-loader-nonce=988d218e86&_locale=user HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.3-fpm.sock:", host: "www.camboland.com", referrer: "post.php?post=6396&action=edit"

hengsoheak avatar Sep 08 '19 06:09 hengsoheak

Same here:

2021/10/15 16:18:52 [error] 3457144#3457144: *25365571 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Cannot redeclare admin_notice__scrape_invalidation_failed() (previously declared in /var/www/prod/wp-content/plugins/fb-instant-articles/facebook-instant-articles.php:492) in /var/www/prod/wp-content/plugins/fb-instant-articles/facebook-instant-articles.php on line 490"

Did any of you find workarounds?

rayrutjes avatar Oct 16 '21 07:10 rayrutjes

The admin_notice__scrape_invalidation_failed() function (and others) are nested inside other functions, which is a bad idea for exactly this reason. The parent function is hooked to post_updated, so if that hook runs twice (perhaps for different posts), then the inner functions are attempted to be defined twice.

GaryJones avatar Sep 23 '22 10:09 GaryJones

For what it's worth... bulk-updating posts is all it takes to trigger this error.

if (!function_exists('admin_notice__scrape_invalidation_failed')) {}

Wrapped that function with that and the next (success) as well. Un-nesting those functions is definitely the long-term solution, but this at least keeps the plugin from breaking until the code is refactored.

Plugin version: 4.2.1 - 5 PHP version: 7.4 WP version: 6.0.1 - 6.0.3

brysont avatar Oct 18 '22 17:10 brysont