In software development it’s generally considered good practice (and sometimes necessary) to add a blank line at the end of a code file. In VS Code we can configure the IDE to force a newline at the end of a file every time we save. There are several ways to set this up, as discussed …
Category Archives: Dev Tips
Async Functions in React useEffect
When using React’s useEffect hook we may want to write an asynchronous function, perhaps to fetch some data. There are some important considerations when combining async with useEffect, discussed further below. Don’t Do This The wrong way to write an async function with useEffect looks something like this: The main problem with the code above …
Filtering User Capabilities in WordPress
WordPress multisite user permissions are much more restrictive than on WordPress single site. One such change is that on multisite only super-admin users have the ‘unfiltered_html’ capability. It is possible however to restore our desired user permissions on multisite using a filter on the ‘map_meta_cap’hook. map_meta_cap The map_meta_cap hook can be used to provide additional …
Only Commit Changes to Tracked Files in Git
I recently started using the command git add -u when preparing my code for commit via the command line. This helps me to only commit changes to tracked files. Not long ago I would occasionally make accidental commits of untracked file changes when using the command git add . If you’re new to git, the …
Continue reading “Only Commit Changes to Tracked Files in Git”
How To Write A Good Pull Request
I’ve found that the more informative I make my pull request descriptions, the more quickly they get reviewed and the less bugs they generate in the future. To this end and to avoid annoying my colleagues, I follow a few guidelines on how to write a good pull request. Provide Context What is the nature …
Remove Whitespace From Code Changes
I can’t tell you how many times I’ve committed and pushed some code changes only to realize or have a colleague point out that my changes introduced trailing whitespace. This happened all too frequently until I recently adopted some tools and practices to keep my whitespace in check. Turns out it’s pretty easy to remove …
PHP Null Coalescing Operator
Until recently, I often found myself using conditional logic with isset() in cases like the following: or perhaps using a ternary: The above examples work just fine, and if you’re using an older version of PHP, these might be some of your best options. However, users of PHP 7.0 and newer can take advantage of …