{"id":308,"date":"2012-11-14T16:15:39","date_gmt":"2012-11-14T15:15:39","guid":{"rendered":"https:\/\/wprealm.com\/?p=308"},"modified":"2017-11-22T19:20:16","modified_gmt":"2017-11-22T18:20:16","slug":"using-php-closures-in-wordpress","status":"publish","type":"tutorial","link":"http:\/\/wprealm.local\/tutorial\/using-php-closures-in-wordpress\/","title":{"rendered":"Using PHP Closures in WordPress"},"content":{"rendered":"

There has been little discussion on the use of PHP Closures with WordPress code, hopefully we will be able to spark some here! Before getting into the nitty-gritty, to make sure everyone is on the same page a quick explanation of a PHP Closure.<\/p>\n

Anonymous functions, also known as\u00a0closures<\/em>, allow the creation of functions which have no specified name. They are most useful as the value of\u00a0callback\u00a0parameters<\/strong>, but they have many other uses.<\/p>\n

php.net<\/p><\/blockquote>\n

Why Use Closures?<\/h4>\n

The ability to create single-use callback functions can be very useful when developing in WordPress land, as it’s very often one needs to run code via hooks and filters. At its simplest consider the following code:<\/p>\n\n

\n
\n
\n
\n
\n \n
\n\n \n
\n\n