Skip to content

Instantly share code, notes, and snippets.

@joemcgill
Last active September 13, 2024 19:28
Show Gist options
  • Save joemcgill/c0b9cf8a094c8620c5c77c9293495269 to your computer and use it in GitHub Desktop.
Save joemcgill/c0b9cf8a094c8620c5c77c9293495269 to your computer and use it in GitHub Desktop.
WP Dev: Custom Bash Functions

WP Helpers

These are a few small utility functions that I use when working on WordPress.

Installation

These can be copied directly into your ~/.bashrc or ~/.zshrc file (whichever is applicable) or put them in a file that is added to your path. I use Oh My Zsh on my sytem, and have this file saved to ~/.oh-my-zsh/custom/plugins/wp-dev/wp-dev.plugin.zsh and have added wp-dev to the list of plugins in my .zshrc file.

What's included

gh-patch

Quickly apply a PR from https://github.com/WordPress/wordpress-develop as a patch to an SVN checkout of WordPress. This is a huge time saver when I'm committing changes to WordPress.

Example – Apply the PR from WordPress/wordpress-develop#7253:

gh-patch 7253

xdb

Toggle the LOCAL_PHP_XDEBUG value used by the wordpress-develop docker environment to enable/disable XDebug. Note: the environment has to be restarted for the changes to take effect.

Examples:

Passing no arguments turns XDebug on

xdb

Passsing either on or off to turn XDebug on/off

# Turn XDebug on
xdb on


# Turn XDebug off
xdb on

memcached

Toggle the LOCAL_PHP_MEMCACHED value used by the wordpress-develop docker environment to enable/disable Memcached to test persistant object caches. Note: the environment has to be restarted for the changes to take effect.

Examples:

Passing no arguments turns Memcached on

memcached

Passsing either on or off to turn Memcached on/off

# Turn Memcached on
memcached on


# Turn Memcached off
memcached on
# Apply a GH PR to SVN.
# Example: `gh-patch 7253` applies the PR from https://github.com/WordPress/wordpress-develop/pull/7253.
gh-patch() {
gh pr diff $1 --repo=WordPress/wordpress-develop | patch -p1
}
# Turn on/off xdebug for local WP.
# Example: `xdb on` or `xdb false`.
xdb() {
[[ $1 = "false" || $1 = "off" ]] && DEBUG="false" || DEBUG="true"
export LOCAL_PHP_XDEBUG=$DEBUG
echo "Local PHP xdebug is now $LOCAL_PHP_XDEBUG"
}
# Turn on/off MEMCACHED for local WP.
# Example: `memcached on` or `memcached false`.
memcached() {
[[ $1 = "false" || $1 = "off" ]] && DEBUG="false" || DEBUG="true"
export LOCAL_PHP_MEMCACHED=$DEBUG
echo "Local MEMCACHED is now $LOCAL_PHP_MEMCACHED"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment