Last active
October 10, 2025 01:03
-
-
Save ironprogrammer/6b41408d0fea6ff352280851c0326ae2 to your computer and use it in GitHub Desktop.
macOS command line functions and aliases for contributing to `wordpress-develop`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # `wordpress-develop` contributor command line scripts for macOS | |
| # Requires WP-CLI: https://wp-cli.org | |
| # use local project's PHPunit | |
| alias phpunit='vendor/bin/phpunit' | |
| # PHPunit aliases, e.g. `puf name_of_test` | |
| alias pu=phpunit | |
| alias puf='phpunit --testdox --filter' | |
| alias pug='phpunit --testdox --group' | |
| alias pul='phpunit --list-groups' | |
| alias pum='phpunit --testdox -c tests/phpunit/multisite.xml' | |
| # Enable Xdebug to drop into tests | |
| alias xpu='XDEBUG_TRIGGER=yes pu' | |
| alias xpuf='XDEBUG_TRIGGER=yes puf' | |
| alias xpug='XDEBUG_TRIGGER=yes pug' | |
| alias xpul='XDEBUG_TRIGGER=yes pul' | |
| alias xpum='XDEBUG_TRIGGER=yes pum' | |
| # Run e2e tests using local wp-src env (rather than wp-env). | |
| # See https://github.com/WordPress/wordpress-develop/tree/trunk/tests/e2e. | |
| alias e2e='WP_BASE_URL="http://wp-src.test" WP_USERNAME=admin WP_PASSWORD=password npm run test:e2e' | |
| alias admin='wp admin' | |
| # Pull repos from upstream, push to origin, and rebuild -- depends on .nvmrc with version info | |
| # `fe` param optionally rebuilds frontend scripts in `wordpress-develop` | |
| # Assumes upstream is the main project, and origin is your personal fork | |
| wp-update() { | |
| local repo=$(basename "$(git rev-parse --show-toplevel)") | |
| local branch=$(git branch --show-current) # alt: $(git rev-parse --abbrev-ref HEAD) | |
| # Prune unused remote tracking branches | |
| git remote prune upstream | |
| git remote prune origin | |
| # Prune local merged branches (except the current one) that begin with * (current), the default branch, or that match ${branch} | |
| #git branch --merged | grep -vE "^\*|trunk|main|master|${branch}" | xargs -r git branch -d | |
| # Restore lock files just in case they were modified | |
| git restore package-lock.json 2>/dev/null | |
| git restore composer.lock 2>/dev/null | |
| # Pull latest upstream, but bail if anything fails to merge | |
| git pull upstream "${branch}" | |
| if [ "$?" -ne 0 ]; then return 1; fi | |
| # Sync up with personal fork | |
| git push origin "${branch}" | |
| composer update -W | |
| nvm use | |
| if [ ${repo} = 'gutenberg' ]; then | |
| npm install && npm run build | |
| else | |
| npm install \ | |
| && if [ "$1" = "fe" ]; then | |
| npm run build:dev | |
| fi | |
| fi | |
| } | |
| # Apply .diff patch to `wordpress-develop` by URL | |
| # To unapply, run `git restore .` | |
| wp-patch() { | |
| if [ "$1" != "" ] | |
| then | |
| local cmd="patch:$1" | |
| npm run grunt ${cmd} | |
| else | |
| echo Make sure to pass in the URL of a .diff file. | |
| fi | |
| } | |
| # Toggles a symlink to arbitrary plugin folder, e.g. if repo is outside `wordpress-develop` | |
| # Run from WordPress root where you want plugin "installed" (e.g. in `wordpress-develop/src/`) | |
| # Important: Assumes plugin root is under ~/Sites; update `src` var as necessary | |
| wp-ln() { | |
| local plugin=$1 | |
| local src="/Users/$(whoami)/Sites/${plugin}" | |
| local dest="$PWD/wp-content/plugins/${plugin}" | |
| if [ -L ${dest} ]; then | |
| wp plugin deactivate ${plugin} \ | |
| && rm ${dest} \ | |
| && echo Unlinked \"${plugin}\". | |
| else | |
| if [ -e ${dest} ]; then | |
| echo Plugin \"${plugin}\" is installed locally. Remove with `wp plugin uninstall ${plugin} --deactivate` and rerun this command. | |
| else | |
| ln -s ${src} ${dest} \ | |
| && wp plugin activate ${plugin} \ | |
| && echo Symlinked plugin \"${plugin}\". | |
| fi | |
| fi | |
| } | |
| # Get version info to copy/paste into test report -- geared toward macOS, depends on WP-CLI | |
| wp-test() { | |
| wp core is-installed 2>/dev/null | |
| local wp_installed=`echo $?` | |
| local wp_path='' | |
| if [ ${wp_installed} = 1 ]; then wp_path='--path=src'; fi | |
| echo - - Hardware: $( system_profiler SPHardwareDataType | sed -nr 's/(Model Name|Chip):[[:space:]](.*)/\2/p' | tr -d '\n' ) | |
| echo - - OS: macOS $( sw_vers -productVersion ) | |
| echo - - Browser: Safari $( /usr/libexec/PlistBuddy -c "print :CFBundleShortVersionString" /Applications/Safari.app/Contents/Info.plist ) \ | |
| / $( /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version ) \ | |
| / $( /Applications/Firefox.app/Contents/MacOS/firefox -v ) | |
| echo - - $( curl -sSL -D - $( wp option get siteurl ${wp_path} ) -o /dev/null | grep '^Server: *' ) | |
| echo - - PHP: $( php -r "echo phpversion().PHP_EOL;" ) \($( php -m | grep -E "gd|imagick" | paste -sd ',' - )\) | |
| # Check if there's a wp-db.sqlite file to return the appropriate DB info. | |
| if [ -f "wp-db.sqlite" ]; then | |
| echo - - SQLite: $( sqlite3 --version 2>/dev/null | sed -n 's/\([^ ]*\).*/\1/p' ) | |
| else | |
| echo - - MySQL: $( wp db check --version ${wp_path} 2>/dev/null | sed -n 's/.*Ver \([^ ]*\).*/\1/p' ) | |
| fi | |
| echo - - WordPress: $( wp core version ${wp_path} 2>/dev/null ) / $( wp cli version ${wp_path} 2>/dev/null ) | |
| echo - - Theme: $( wp theme status ${wp_path} | grep " A " | sed 's/.* A //' ) | |
| echo - - Active Plugins: $( wp plugin status ${wp_path} | grep " A " | sed 's/.* A //' | tr '\n' ',' | sed 's/,/, /g; s/, $//' ) | |
| echo - - Must Use Plugins: $( wp plugin status ${wp_path} | grep " M " | sed 's/.* M //' | tr '\n' ',' | sed 's/,/, /g; s/, $//' ) | |
| } | |
| # Get current project's WordPress version, NOT dependent on WP-CLI (i.e. `wp core version`) | |
| wp-version() { | |
| if [ -d "wp-includes" ]; then | |
| grep '^$wp_version' wp-includes/version.php | |
| else | |
| grep '^$wp_version' src/wp-includes/version.php | |
| fi | |
| } | |
| # Get current project's Gutenberg version, NOT dependent on WP-CLI | |
| gb-version() { | |
| if [ -d "wp-content" ]; then | |
| grep '"version"' wp-content/plugins/gutenberg/package.json | |
| else | |
| # Assume we're in the gutenberg repo | |
| grep '"version"' package.json | |
| fi | |
| } | |
| # Jumps to root of current WP site | |
| wp-root() { | |
| local root=`wp eval 'echo ABSPATH;'` | |
| if [ -d "${root}" ]; then | |
| cd ${root}; | |
| fi | |
| } | |
| # Kill untracked files that cause issue with $_old_files array, e.g. when running `npm run build` | |
| wp-old() { | |
| for file in `git ls-files -o src/wp-admin`; do; rm $file; done | |
| for file in `git ls-files -o src/wp-includes`; do; rm $file; done | |
| } | |
| # Set Xdebug variables for CLI debugging, e.g. for PHPUnit (https://getgrav.org/blog/macos-monterey-apache-mysql-vhost-apc) | |
| xdebug-cli() { | |
| export XDEBUG_MODE=debug | |
| export PHP_IDE_CONFIG=serverName=localhost | |
| export XDEBUG_CONFIG=idekey=PHPSTORM remote_port=9000 remote_host=localhost remote_enable=1 remote_handler=dbgp | |
| } |
Author
Author
2022-09-23
- Added
phpunitmultisite alias and trigger to enable Xdebug when performing tests.
Author
2023-08-30
- Update
wp-updateto latest local iteration. - Add
*-versioncommands that function without WP-CLI. - Misc tweaks.
2023-09-28
- Fix typo.
Author
2025-10-09
- Add
e2etesting alias. - Tweaks to param handling in
wp-update. - Add
wp-lnutility for symlinking any plugin outside your dev site. - Update
wp-testfor single-line browser info, DB information, and mu plugins. - Add
wp-rootfor...going to the root. - Add
wp-oldto clear out files that cause issues with$_old_fileswhen switching between PRs and multiple builds.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2022-09-13
Hardwareoutput forwp-testfunction. IncludesModel NameandChipfromsystem_profiler.