Ecommerce Shopify WordPress Discussion

How to debug a php file in a WordPress plugin via VS Code & Xdebug?

In my WordPress plugin, there is a PHP file called app_setup.php. I want to debug it in Visual Studio Code. So I do as follows: Install WAMP Server on my Windows Server. Create a virtual host at and install a WordPress site on The plugin will be invoked via a shortcode. So I create a new post in WordPress and add a shortcode in it. The URL of the post is In VS Code, I follow the instructions to install PHP Debug Adapter for Visual Studio Code. Then in VS Code, under the folder of the plugin, I choose "Add configuration" and create 3 configurations. I open app_setup.php and set a breakpoint in it. Then I choose "Launch Built-in web server" configuration and click the arrow to the start the debug. VS Code will launch Chrome and visit a URL http://localhost:50334/, where 50334 is a random port. Since there is no page at http://localhost:50334/, it shows a 404 error. I try to create a new tab in Chrome and visit my post and execute the plugin code, but the breakpoint in VS Code will never be triggered. If I start debugging app_setup.php in VS Code use the configuration "Launch currently open script", then the breakpoint will be triggered in VS, but all WordPress functions are not recognized since it is not executed in a WordPress environment, it will report error like below: Fatal error: Uncaught Error: Call to undefined function plugin_dir_path() in C:\wamp64\www\blogs\wp-content\plugins\myplugin\app_setup.php on line 10 So, what is the proper way to debug a PHP file in WordPress plugin?
TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.