[theme-reviewers] PHP 5.3 In Themes

Peter Baylies pbaylies at semperfiwebdesign.com
Wed Mar 6 14:52:27 UTC 2013


Then you can do whatever you like with the reference, and not clutter up
the global namespace; but closures in PHP have other handy uses as well:

function make_me_a_callback( $msg ) {
    return function() use ( $msg ) { return $msg; };
}

$foo = make_me_a_callback( "Hello!" );
add_action( 'the_content', $foo );
remove_action( 'the_content', $foo );


On Tue, Mar 5, 2013 at 6:15 PM, Chip Bennett <chip at chipbennett.net> wrote:

> But that's not the usual use-case for anonymous functions, is it? Normally
> it's more like:
>
> add_action( 'init', function() { /* some stuff here */ } );
>
>
> And if you're going to use:
>
> $foo = function() { /* some stuff here */ }
> add_action( 'init', $foo );
>
>
> ...then what's the point of using an anonymous function?
>
>
> On Tue, Mar 5, 2013 at 6:06 PM, Peter Baylies <
> pbaylies at semperfiwebdesign.com> wrote:
>
>>
>> Chip,
>>
>> Actually, you can remove an anonymous function; you just need a reference
>> to it, just as you would with any instance of an object:
>>
>> $foo = function() { return "Hello!"; };
>> add_action( 'the_content', $foo );
>> remove_action( 'the_content', $foo );
>>
>> Cheers,
>>
>>  -- Peter
>>
>>
>> On Tue, Mar 5, 2013 at 4:28 PM, Chip Bennett <chip at chipbennett.net>wrote:
>>
>>> Also: I would argue against the use of anonymous functions. They are
>>> inherently Child-Theme unfriendly when used for callbacks, because they
>>> cannot be overridden with corresponding remove_action() or remove_filter()
>>> calls.
>>>
>>>
>>> On Tue, Mar 5, 2013 at 4:27 PM, Chip Bennett <chip at chipbennett.net>wrote:
>>>
>>>> My initial reaction here is that Themes should support the current core
>>>> WordPress minimum requirements, which would mean that Themes that implement
>>>> features beyond the minimum requirements would, at a minimum, need to
>>>> ensure graceful degradation.
>>>>
>>>>
>>>> On Tue, Mar 5, 2013 at 4:23 PM, Ryan Van Etten <ryanve at gmail.com>wrote:
>>>>
>>>>> PHP 5.3 supports closures<http://php.net/manual/en/functions.anonymous.php> and
>>>>> other features <http://php.net/manual/en/migration53.new-features.php>
>>>>> . I want to propose a mechanism for safely allowing PHP 5.3+ themes:
>>>>>
>>>>> /**
>>>>>  * Theme Name: example
>>>>>  * Minimum PHP version: 5.3.0
>>>>>  * ...
>>>>>  */
>>>>>
>>>>> With this info, the theme installation page could prevent users from
>>>>> installing 5.3 themes on 5.2 servers. The "Activate" link could be replaced
>>>>> with an alert that tells the user that the theme needs a higher PHP
>>>>> version. If unspecified, it'd default to the WP requirement<http://wordpress.org/about/requirements/>
>>>>> .
>>>>>
>>>>> I'd like to see WP be proactive about encouraging users to use 5.3+.
>>>>> The sooner we get the majority<http://stackoverflow.com/questions/8372114/php-version-adoption-stats>on 5.3, the better it will be for the core too. The same technique could be
>>>>> used for plugins, and it is future-proof to 5.4 etc.
>>>>>
>>>>> @ryanve <http://twitter.com/ryanve>
>>>>>
>>>>> _______________________________________________
>>>>> theme-reviewers mailing list
>>>>> theme-reviewers at lists.wordpress.org
>>>>> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>>>>
>>>>>
>>>>
>>>
>>> _______________________________________________
>>> theme-reviewers mailing list
>>> theme-reviewers at lists.wordpress.org
>>> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>>
>>>
>>
>> _______________________________________________
>> theme-reviewers mailing list
>> theme-reviewers at lists.wordpress.org
>> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>
>>
>
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20130306/d3278494/attachment.htm>


More information about the theme-reviewers mailing list