I'm using Wp-env to develop a plugin as it's a pretty robust wrapper for Docker that includes phpunit and xdebug.
However, I have been struggling to get xDebug working.
- From my_plugin directory run
wp-env start
... await build - set .vscode/launch.json as per docs:
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html/wp-content/plugins/my_plugin": "${workspaceFolder}/"
}
}
- run
wp-env start --xdebug
- open main plugin file and add breakpoint in VS Code and try to Run and Debug
- Result: "PHP Fatal error: Uncaught Error: Call to undefined function plugin_dir_path"
(and if I add
!defined( 'ABSPATH' ) die()
, it is tripped.)
I'm new to this tool so expecting it's a newbie error. Seems like xDebug should be starting at the Wordpress entrypoint, but isn't.
There is one more item of note, though. In wp-env logs
:
Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port) :-(, referer: http://localhost:8888