Skip to content

Instantly share code, notes, and snippets.

@evansolomon
Created August 26, 2012 16:47
Show Gist options
  • Save evansolomon/3481592 to your computer and use it in GitHub Desktop.
Save evansolomon/3481592 to your computer and use it in GitHub Desktop.
Bash functions to find WordPress hooks
# Alias ST2's command line tool for a shorter (easier-to-remember) name
alias st="/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl"
# Search for and open WordPress hooks
function action() {
ack "do_action\(\s*('|\")$1('|\")" | awk {'print $1'} | sed 's/:$//g' | xargs st
}
function filter() {
ack "apply_filters\(\s*('|\")$1('|\")" | awk {'print $1'} | sed 's/:$//g' | xargs st
}
# Example usage from the root of a WordPress repository
# action init
# Automatically opens wp-settings.php to line 305 in Sublime Text 2
# If the hook is fired multiple times (e.g. the_content) it will open all of the files
# ...but only the last one will be on the correct line
# filter map_meta_cap
# Automatically opens wp-includes/capabilities.php to line 1247 in Sublime Text 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment