I have a class that uses 5.3 feature anonymous function (https://github.com/JeffreyWay/Easy-WordPress-Custom-Post-Types/blob/master/jw_custom_posts.php), but there is a problem, on the server I can not upgrade to 5.3. Is there any simple workaround to get rid of anonymous functions or do I need to rewrite whole class?
4
-
1Hopefully you'll find a workaround in this case, but nevertheless it is essential to determine dependencies/requirements of external libraries before committing to using them :-)halfer– halfer2012-03-04 13:52:22 +00:00Commented Mar 4, 2012 at 13:52
-
Yes, didn't knew that server can't handle it. Rewrote the code with core wordpress.Raimonds– Raimonds2012-03-10 08:39:32 +00:00Commented Mar 10, 2012 at 8:39
-
I don't understand, what's the problem with just naming the function and calling it?Benjamin Gruenbaum– Benjamin Gruenbaum2012-07-04 20:48:01 +00:00Commented Jul 4, 2012 at 20:48
-
@BenjaminGruenbaum: most of the anonymous functions in that linked file are closures, so that won't worknewacct– newacct2013-03-09 08:28:16 +00:00Commented Mar 9, 2013 at 8:28
Add a comment
|
2 Answers
A workaround for pre PHP 5.3 is to use create_function().
It is ugly as hell and akin to eval(), but it's closest to functionality without defining another function and passing a pointer to it.
1 Comment
Guillaume Poussel
With such a big anonymous function (github.com/JeffreyWay/Easy-WordPress-Custom-Post-Types/blob/…) it will be hard to use create_function, enclosing all the PHP code in a string... You should create your own function and passing its name to
admin_init.