{"id":2385,"date":"2013-12-20T00:31:54","date_gmt":"2013-12-19T19:01:54","guid":{"rendered":"http:\/\/jesin.tk\/?p=2385"},"modified":"2015-03-17T01:24:26","modified_gmt":"2015-03-16T19:54:26","slug":"wordpress-hooks-search-tool","status":"publish","type":"post","link":"https:\/\/websistent.com\/wordpress-hooks-search-tool\/","title":{"rendered":"WordPress Hooks (Actions and Filters) Search Tool"},"content":{"rendered":"<p>This started out as a PHP regex experiment. I wanted to find the WordPress &#8220;<a href=\"http:\/\/codex.wordpress.org\/Glossary#Action\" target=\"_blank\">action<\/a>&#8221; hooks in a particular theme so that I can <a href=\"http:\/\/codex.wordpress.org\/Function_Reference\/add_action\" target=\"_blank\">add my own action<\/a> function to it.<\/p>\n<p>So instead of searching through the whole lot of files for <a href=\"http:\/\/codex.wordpress.org\/Function_Reference\/do_action\" target=\"_blank\">do_action<\/a>s I sat down writing a <a title=\"Javascript Validation with Regular Expressions\" href=\"https:\/\/websistent.com\/javascript-validation-with-regular-expressions\/\">regular expression<\/a> to do this. I was very satisfied with the results which made me think about creating a tool to do this.<\/p>\n<p>So here you go a standalone PHP script which seeps through the PHP code of the WordPress core, plugins, themes or anything you specify and gets you a list of actions and filters.<\/p>\n<p>I use the word &#8220;standalone&#8221; because this isn&#8217;t a WordPress plugin or anything which requires WordPress functions. This is a script which uses a regex in <a href=\"http:\/\/php.net\/preg_match_all\" target=\"_blank\">preg_match_all()<\/a> to find all &#8220;tag&#8221; names in the do_action() and <a href=\"http:\/\/codex.wordpress.org\/Function_Reference\/apply_filters\" target=\"_blank\">apply_filters()<\/a> function. This does not even require WordPress, if you want to find the hooks in a plugin just download the plugin, unzip it to a directory readable by this tool.<\/p>\n<p><span style=\"font-size: 22px;\"><a href=\"https:\/\/github.com\/jesinwp\/wp-hooks-search-tool\/archive\/master.zip\">Download WordPress Hooks Search Tool<\/a> | <a target=\"_blank\" href=\"https:\/\/github.com\/jesinwp\/wp-hooks-search-tool\">GitHub<\/a><\/span><!--more--><\/p>\n<h2>Usage<\/h2>\n<p>Upload the code to your document root (or anywhere else) and access it from the browser.<\/p>\n<pre class=\"brush: plain; auto-links: false; light: true; title: ; notranslate\" title=\"\">http:\/\/&lt;yourdomain&gt;\/wp-hooks-search.php<\/pre>\n<p>Enter the directory or file to search for hooks. It can be either relative or absolute. If a directory is entered all subdirectories are also scanned. If you wish to scan the current directory enter a dot (.) in the text box.<\/p>\n<p>Note: On Windows (WAMP and XAMPP users) you must use forward slash in the path instead of the usual backslash like this<\/p>\n<pre class=\"brush: plain; light: true; title: ; notranslate\" title=\"\">wordpress\/wp-content\/themes\/customizr<\/pre>\n<p>The second textbox is optional. If you are searching for a particular name in the hook you can enter it there.<\/p>\n<h2>Screenshots<\/h2>\n<figure id=\"attachment_2390\" aria-describedby=\"caption-attachment-2390\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/websistent.com\/wp-content\/uploads\/2013\/12\/wp-hooks-search-in-twentyfourteen.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-2390\" alt=\"wordpress hooks search in twentyfourteen\" src=\"https:\/\/websistent.com\/wp-content\/uploads\/2013\/12\/wp-hooks-search-in-twentyfourteen-658x1024.png\" width=\"500\" height=\"778\" srcset=\"https:\/\/websistent.com\/wp-content\/uploads\/2013\/12\/wp-hooks-search-in-twentyfourteen-658x1024.png 658w, https:\/\/websistent.com\/wp-content\/uploads\/2013\/12\/wp-hooks-search-in-twentyfourteen-192x300.png 192w, https:\/\/websistent.com\/wp-content\/uploads\/2013\/12\/wp-hooks-search-in-twentyfourteen.png 900w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2390\" class=\"wp-caption-text\">Listing out actions and filters in the Twenty Fourteen Theme<\/figcaption><\/figure>\n<figure id=\"attachment_2391\" aria-describedby=\"caption-attachment-2391\" style=\"width: 500px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/websistent.com\/wp-content\/uploads\/2013\/12\/wp-hooks-search-keyword-search.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-large wp-image-2391\" alt=\"wordpress hooks search keyword search\" src=\"https:\/\/websistent.com\/wp-content\/uploads\/2013\/12\/wp-hooks-search-keyword-search-663x1024.png\" width=\"500\" height=\"772\" srcset=\"https:\/\/websistent.com\/wp-content\/uploads\/2013\/12\/wp-hooks-search-keyword-search-663x1024.png 663w, https:\/\/websistent.com\/wp-content\/uploads\/2013\/12\/wp-hooks-search-keyword-search-194x300.png 194w, https:\/\/websistent.com\/wp-content\/uploads\/2013\/12\/wp-hooks-search-keyword-search.png 900w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption id=\"caption-attachment-2391\" class=\"wp-caption-text\">Searching for a hook by entering its name. Notice the dot in the first text box. It makes the tool search from the current directory<\/figcaption><\/figure>\n<h2>Regular Expression<\/h2>\n<p>Even if this tool has 250+ lines of code the hero of this script is the regular expression which hooks out the hooks \ud83d\ude00<\/p>\n<pre class=\"brush: plain; light: true; title: ; notranslate\" title=\"\">\/(apply_filters|do_action)\\s*\\(\\s*&#x5B;\\'\\&quot;](.+?)\\s*&#x5B;,\\)]\/<\/pre>\n<p>A <em>do_action<\/em> or an <em>apply_filters<\/em> function can look like any of the following.<\/p>\n<pre class=\"brush: php; light: true; title: ; notranslate\" title=\"\">do_action('wp_my_action',$variable);\r\ndo_action  ( &quot;wp_head&quot;  );\r\napply_filters('filter_name',  $value);\r\napply_filters('filter_' . $variable,  $value);<\/pre>\n<p>Here is the anatomy of the regular expression.<\/p>\n<p><strong>(apply_filters|do_action)<\/strong> &#8211; Match the word &#8220;apply_filters&#8221; OR &#8220;do_action&#8221;<\/p>\n<p><strong>\\s*<\/strong> &#8211; The <strong>\\s<\/strong> matches a whitespace character and putting an asterisk (<strong>*<\/strong>) in front of it matches zero or more of whitespaces. This match has been placed in several places because the function could be anything like these.<\/p>\n<pre class=\"brush: php; light: true; title: ; notranslate\" title=\"\">do_action('wp_my_action',$variable);\r\ndo_action( 'wp_my_action', $variable );\r\ndo_action  ('wp_my_action',$variable  );<\/pre>\n<p><strong>\\(<\/strong> &#8211; Matches the opening brackets of the function.<\/p>\n<p><strong>[\\&#8217;\\&#8221;]<\/strong> &#8211; Match single quotes OR double quotes. Functions may use single or double quotes around their parameters so this matches any.<\/p>\n<p><strong>(.+?)<\/strong> &#8211; This is the portion that matches the first parameter of the function i.e. the hook, <strong>.+<\/strong> matches one or more characters while the question mark <strong>?<\/strong> does a non greedy match. Read more about regex greediness <a href=\"http:\/\/www.rexegg.com\/regex-greed.html\" target=\"_blank\">here<\/a>.<\/p>\n<p><strong>[,\\)]<\/strong> &#8211; This matches a comma OR the closing brackets. The second argument is optional in the <em>do_action()<\/em> function is optional so a comma matches if there is a second parameter like this.<\/p>\n<pre class=\"brush: php; light: true; title: ; notranslate\" title=\"\">do_action( 'wp_my_action', $variable );<\/pre>\n<p>If there is only one parameter the brackets match.<\/p>\n<pre class=\"brush: php; light: true; title: ; notranslate\" title=\"\">do_action( 'wp_head' );<\/pre>\n<p>So the comment form is all yours send me your bouquets and brickbats on this script<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This started out as a PHP regex experiment. I wanted to find the WordPress &#8220;action&#8221; hooks in a particular theme so that I can add my own action function to it. So instead of searching through the whole lot of files for do_actions I sat down writing a regular expression to do this. I was [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2400,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[39],"tags":[103,81,80],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>WordPress Hooks (Actions and Filters) Search Tool - Jesin&#039;s Blog<\/title>\n<meta name=\"description\" content=\"A PHP script to search the WordPress core, plugin and theme files for hooks - actions and filters. Very useful to find out hooks placed in complex themes and plugins\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/websistent.com\/wordpress-hooks-search-tool\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WordPress Hooks (Actions and Filters) Search Tool - Jesin&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"A PHP script to search the WordPress core, plugin and theme files for hooks - actions and filters. Very useful to find out hooks placed in complex themes and plugins\" \/>\n<meta property=\"og:url\" content=\"https:\/\/websistent.com\/wordpress-hooks-search-tool\/\" \/>\n<meta property=\"og:site_name\" content=\"Jesin&#039;s Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/JesinsBlog\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/a.jesin\" \/>\n<meta property=\"article:published_time\" content=\"2013-12-19T19:01:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-03-16T19:54:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/websistent.com\/wp-content\/uploads\/2013\/12\/wordpress-hooks-search-tool-thumbnail.png\" \/>\n\t<meta property=\"og:image:width\" content=\"256\" \/>\n\t<meta property=\"og:image:height\" content=\"215\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Jesin A\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@jesin_a\" \/>\n<meta name=\"twitter:site\" content=\"@jesin_a\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jesin A\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/websistent.com\/wordpress-hooks-search-tool\/\",\"url\":\"https:\/\/websistent.com\/wordpress-hooks-search-tool\/\",\"name\":\"WordPress Hooks (Actions and Filters) Search Tool - Jesin&#039;s Blog\",\"isPartOf\":{\"@id\":\"https:\/\/websistent.com\/#website\"},\"datePublished\":\"2013-12-19T19:01:54+00:00\",\"dateModified\":\"2015-03-16T19:54:26+00:00\",\"author\":{\"@id\":\"https:\/\/websistent.com\/#\/schema\/person\/357101749ddf15997318112dc2560fc0\"},\"description\":\"A PHP script to search the WordPress core, plugin and theme files for hooks - actions and filters. Very useful to find out hooks placed in complex themes and plugins\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/websistent.com\/wordpress-hooks-search-tool\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/websistent.com\/#website\",\"url\":\"https:\/\/websistent.com\/\",\"name\":\"Jesin&#039;s Blog\",\"description\":\"Welcome to the Portal of Technology\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/websistent.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/websistent.com\/#\/schema\/person\/357101749ddf15997318112dc2560fc0\",\"name\":\"Jesin A\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/websistent.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/048e2c3bc97fe47194f9b43595fec029?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/048e2c3bc97fe47194f9b43595fec029?s=96&d=mm&r=g\",\"caption\":\"Jesin A\"},\"sameAs\":[\"https:\/\/websistent.com\/\",\"https:\/\/www.facebook.com\/a.jesin\",\"https:\/\/twitter.com\/jesin_a\"],\"url\":\"https:\/\/websistent.com\/author\/a-jesin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WordPress Hooks (Actions and Filters) Search Tool - Jesin&#039;s Blog","description":"A PHP script to search the WordPress core, plugin and theme files for hooks - actions and filters. Very useful to find out hooks placed in complex themes and plugins","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/websistent.com\/wordpress-hooks-search-tool\/","og_locale":"en_US","og_type":"article","og_title":"WordPress Hooks (Actions and Filters) Search Tool - Jesin&#039;s Blog","og_description":"A PHP script to search the WordPress core, plugin and theme files for hooks - actions and filters. Very useful to find out hooks placed in complex themes and plugins","og_url":"https:\/\/websistent.com\/wordpress-hooks-search-tool\/","og_site_name":"Jesin&#039;s Blog","article_publisher":"https:\/\/www.facebook.com\/JesinsBlog","article_author":"https:\/\/www.facebook.com\/a.jesin","article_published_time":"2013-12-19T19:01:54+00:00","article_modified_time":"2015-03-16T19:54:26+00:00","og_image":[{"width":256,"height":215,"url":"https:\/\/websistent.com\/wp-content\/uploads\/2013\/12\/wordpress-hooks-search-tool-thumbnail.png","type":"image\/png"}],"author":"Jesin A","twitter_card":"summary_large_image","twitter_creator":"@jesin_a","twitter_site":"@jesin_a","twitter_misc":{"Written by":"Jesin A","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/websistent.com\/wordpress-hooks-search-tool\/","url":"https:\/\/websistent.com\/wordpress-hooks-search-tool\/","name":"WordPress Hooks (Actions and Filters) Search Tool - Jesin&#039;s Blog","isPartOf":{"@id":"https:\/\/websistent.com\/#website"},"datePublished":"2013-12-19T19:01:54+00:00","dateModified":"2015-03-16T19:54:26+00:00","author":{"@id":"https:\/\/websistent.com\/#\/schema\/person\/357101749ddf15997318112dc2560fc0"},"description":"A PHP script to search the WordPress core, plugin and theme files for hooks - actions and filters. Very useful to find out hooks placed in complex themes and plugins","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/websistent.com\/wordpress-hooks-search-tool\/"]}]},{"@type":"WebSite","@id":"https:\/\/websistent.com\/#website","url":"https:\/\/websistent.com\/","name":"Jesin&#039;s Blog","description":"Welcome to the Portal of Technology","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/websistent.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/websistent.com\/#\/schema\/person\/357101749ddf15997318112dc2560fc0","name":"Jesin A","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/websistent.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/048e2c3bc97fe47194f9b43595fec029?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/048e2c3bc97fe47194f9b43595fec029?s=96&d=mm&r=g","caption":"Jesin A"},"sameAs":["https:\/\/websistent.com\/","https:\/\/www.facebook.com\/a.jesin","https:\/\/twitter.com\/jesin_a"],"url":"https:\/\/websistent.com\/author\/a-jesin\/"}]}},"_links":{"self":[{"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/posts\/2385"}],"collection":[{"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/comments?post=2385"}],"version-history":[{"count":5,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/posts\/2385\/revisions"}],"predecessor-version":[{"id":2401,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/posts\/2385\/revisions\/2401"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/media\/2400"}],"wp:attachment":[{"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/media?parent=2385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/categories?post=2385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/websistent.com\/wp-json\/wp\/v2\/tags?post=2385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}