WordPress: Deprecated Hooks Script

I was reviewing a plugin and I came across a hook I knew to be deprecated. I went to verify this from within the Log Deprecated Notices plugin from Andrew Nacin but I couldn’t see anything about it.

I took a dive into the code and noticed that hook deprecations have yet to be added. This bothered me as I was using this plugin to gauge such things from the get go. Guess I should have checked that earlier! :-\

So I wrote a ruby script that pulls from Adam Brown’s site which is a list of all deprecated hooks.

#!/usr/bin/ruby

require 'rubygems'
require 'nokogiri'
require 'open-uri'

url = 'http://adambrown.info/p/wp_hooks/hook?old=1'
doc = Nokogiri::HTML(open(url))
doc.search(".wp_hooks .hideLink").each do |item|
  text = item.text
  puts "#{text}"
end

I then saved this to get_deprecated_hooks.rb and made it executable.

Now I need to parse this:

#!/usr/bin/ruby

f = ARGF.read
f.each_line { |line|
  hook = line.strip!.gsub( /\{.*\}(_\{)?/ixm , '' )
  if hook.empty? == false then
    puts "\nSearching for #{hook}"
    system "grep -rin '#{hook}' 'PATHTOMYPLUGIN'"
  end
}
puts "\nAll done!"

I saved this one to search_for_deprecated_hooks.rb and made it executable as well.

Now I can run:

./get_deprecated_hooks.rb | ./search_for_deprecated_hooks.rb

Basically it gets a list of all the deprecated hooks from the Adam Brown site and then goes through each one and if need be it cuts out the variable section so it can search for the beginning of the dynamic hooks.

This isn’t as clean as I normally like to do things. It’s quick and dirty. It gets the job done and lets me know if there’s a potential for a deprecated hook.

If anyone has found a cleaner way to do this, please let me know.

I’m hosting it on GitHub.