phpsword / sword-bundle

Modern WordPress development with Symfony
https://getsword.com
MIT License
124 stars 4 forks source link

Undefined variable in dev environment #13

Closed loicrey closed 1 year ago

loicrey commented 1 year ago

Hi. On a fresh Docker one-liner installation, I have an error that is thrown by Symfony when visiting some of Wordpress admin pages

ErrorException:
Warning: Undefined variable $action

  at wp/core/wp-admin/site-health.php:58
  at require_once('/var/www/html/wp/core/wp-admin/site-health.php')
     (vendor/phpsword/sword-bundle/src/Loader/WordpressLoader.php:86)
  at Sword\SwordBundle\Loader\WordpressLoader->createWordpressResponse()
     (vendor/phpsword/sword-bundle/src/Controller/WordpressController.php:17)
  at Sword\SwordBundle\Controller\WordpressController->index()
     (vendor/symfony/http-kernel/HttpKernel.php:163)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw()
     (vendor/symfony/http-kernel/HttpKernel.php:74)
  at Symfony\Component\HttpKernel\HttpKernel->handle()
     (vendor/symfony/http-kernel/Kernel.php:184)
  at Symfony\Component\HttpKernel\Kernel->handle()
     (vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35)
  at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
     (vendor/autoload_runtime.php:29)
  at require_once('/var/www/html/vendor/autoload_runtime.php')
     (public/index.php:5)         

In the wp core, it seems that this variable is not always defined

image

If I change my APP_ENV env variable to prod instead of dev, page loads fine.

williarin commented 1 year ago

The fix is to add this line at the end of wp-config.php right after requring wp-settings.php:

global $action;

It's being unset in wp-includes/default-filters.php. I'll fix it for new installs but for now only manual fix is possible for existing installs.

loicrey commented 1 year ago

Fixed for me, thanks for the quick reply and fix !