[wp-trac] [WordPress Trac] #21673: Passing scoped variables and doing partial page caching with get_template_part
WordPress Trac
wp-trac at lists.automattic.com
Sat Aug 25 19:55:56 UTC 2012
#21673: Passing scoped variables and doing partial page caching with
get_template_part
-----------------------------+----------------------
Reporter: sc0ttkclark | Owner:
Type: feature request | Status: closed
Priority: normal | Milestone:
Component: Template | Version: 3.4.1
Severity: normal | Resolution: invalid
Keywords: |
-----------------------------+----------------------
Comment (by mikeschinkel):
Replying to [comment:1 sc0ttkclark]:
Just a general comment about function parameter architecture. Rather
than added 3 more parameters to make it 5 total parameters, like so:
{{{
function get_template_part ( $slug, $name = null, $data = null, $expires =
null, $cache_mode = null ) {
...
}
}}}
I'd highly recommend just adding one'' (what I call an)'' `$args`
parameter and then allow the other two to be passed in via the `$args`
array
{{{
function get_template_part ( $slug, $name = null, $data = array() ) {
$args = wp_parse_args( $args, array(
'expires' => null,
'cache_mode' => null,
));
...
}
}}}
This is a pattern I've found to work extremely well and is very resilient
to evolutionary changes in code over time. It also make it easier to:
- Remember function signatures include parameter order, and
- Be also to pass the `$args` array to functions the called function wants
to delegate to, and
- It's also easier to read without having to scroll horizontally. :-)
Just something to consider maybe?
--
Ticket URL: <http://core.trac.wordpress.org/ticket/21673#comment:4>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list