Troubleshooting xdebug setup on VVV with VS Code

Some tips for troubleshooting setting up xdebug on VVV while using VSCode and Felix Becker’s PHP Debug extension and BrianGilbert_‘s Xdebug Helper for Firefox add-on.

Ensure xdebug is turned on within vvv

You may check xdebug status by taking a peak at your servers http://vvv.test/phpinfo/ page. If not on, via https://github.com/Varying-Vagrant-Vagrants/VVV/wiki/Code-Debugging we can toggle it on by accessing the virtual machine via ssh, then running a command that will turn xdebug on and restart PHP:

$ cd ~/your/location/for/vvv/
$ vagrant ssh
$ /vagrant/config/homebin/xdebug_on

The xdebug_on command is supposed to work without the full path, but I haven’t much luck with that. As a second saver, I store this full path in my text expanded since every time the machine is restarted xdebug being on does not persist and it will need to be manually turned on. A bash_alias entry could be made as well.

Ensure the browser extension is turned on

Yes, simple, but often forgotten.

Ensure you’ve started debugging in VS Code

Again, yes, simple, but often forgotten.

Ensure VVV is up to date

Older versions of vvv have compatibility issues with xdebug and php. Ensure you’re running the latest version of vvv, that vagrant itself is up to date, and that you’re using the latest version of php.

Turn off “Everything” breaks

Sometimes xdebug works while setting it up, VSCode pops up, but it stops on a breakpoint that isn’t the one you specified, it’s a random file from your app. This is an error that was picked up and xdebug stoped on because the default VSCode extension has it specified to break on “everything”. Unselect this in the Debug sidebar:

Check the xdebug profile is correct

Via the debug sidebar (shift+cmd+d), we’ll view our xdebug configuration file. Here’s an example of a WordPress plugin delete-thumbnails and the path I used

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "pathMappings": {
                "/srv/www/vvv-vip/public_html/wp-content/plugins/delete-thumbnails": "${workspaceFolder}"
            },
        }
    ]
}

Two important notes:

  • VVV has two initial paths to get to your sites, /srv/and /vagrant/, the latter is a symbolic link which xdebug does not understand, you must use /srv/
  • Other tutorials may say to use ${workspaceRoot}, this variable is deprecated in favor of ${workspaceFolder}

Try a breakpoint outside of your current script

We usually want our breakpoints on what we’re working on, and we’re frustrated when xdebug doesn’t pick up on the breakpoint, so we dig around our config to check what’s wrong. Let’s first make sure that our desired code is actually running and capable of breakpointing, after all, the code not running might be why we’re firing up xdebug!

Add a breakpoint at the root of your application, somewhere you know runs 100% for sure. In WordPress, this will often be in either WordPress’ /index.php file, or the primary file in your current theme or plugin. For this plugin I’m working on, I checked that the plugin is activated, and I’ve placed a breakpoints on a fake var on the main fire which I know for sure loads:

Is your VSCode the nightly build?

I’ve heard of users being unable to run xdebug while using their beta releases. Best to always use the stable releases.

Tabbing Through Links in FireFox

I migrated from Chrome to Firefox in a support of Open Source software and because all other browsers have caught up to Chrome in terms of quality, performance, tools, and integrations.

Nothing much has been different except by default you cannot tab through links on a webpage! I’m a huge proponent of using my mouse/trackpad as little as possible, so this was a deal breaker for me.

Luckily, there’s a hidden setting in Firefox, visit about:config in the address bar, right click to “Add New » Integer”, create a key of accessibility.tabfocus and set the value to 7.

You should now be able to tab through all your links, which saves so much time on Google and other straight forward sites.


While reviewing this, you can also adjust how the TAB key behaves in dialog boxes. Checkout System Preferences » Keyboard » Shortcuts » Full Keyboard Access.

WordPress Pass PHP Variable and Values to JS Theme or Plugin

The beautiful function wp_localize_script() was built for l11n, however its found as a method for carrying over server-side values into client-side JS.

Your values are now available in your .js file:

console.dir(my_theme_data);

Currently using this in a React theme I’m building for WordPress.

This can also be done with something like:

Sticky Buttons Within A Section

Common practices for sticking elements weren’t working for me: position: sticky and stickybits. I didn’t want to use jQuery either, normally I’d reach to use waypoints.inview. So I wrote my own in vanilla Javascript.

The nice part is it was much easier to do a sticky bottom. Scroll to element, bottom of viewport hits bottom of to-be-stuck element, and carries it down until the end of its parent element.

https://codepen.io/davidsword/pen/OEZMay

This is a great feature for section-specific call to actions.

Every Image URL Filter For WordPress, Front & Back End

I had a project where every single media library image URL needed to be filtered, backend and front end. As far as I’ve found these were the filters for every area:

The myplugin_filter_html_image_urls() function peals out images with regex from areas where it’s not just the URL being sent. This function may require verification of the current domain incase bad practices of using external images is being done.