Well I just asking myself this, there are two ways I could implement this. What would be a better fit to coding standards?
Or is this just a a matter of personal like?
And what about php and memory, assuming this would be way more complicated and executed very often. Would it cost more memory to create a function or a variable?
Solution 1:
function stuff(){
[...]
$fluid = ( current_theme_supports('greatness') ) ? '-greatness' : '';
$output = '<div class="box' . $fluid . '">';
[...]
}
Solution 2:
function stuff_alternative(){
[...]
$output = '<div class="box' . bootgen_is_great() . '">';
[...]
}
function bootgen_is_great(){
if ( current_theme_supports( 'greatness' ) )
return '-greatness';
}
Memory is not the issue here. There are no complex operations, and the difference will be almost unmeasurable.
What matters is readability: If your
stuff
function is rather short (less than eight functional steps) and you use the check just once â keep the check in it.But if you need the support check in different functions separate it.
I’d rather optimize the names:
greatness
is not very descriptive, and while I like fluid layouts â they are not a synonym for great layouts. 🙂Also, it is a custom name, so prefix it to avoid collisions with plugins and to tell the uninformed reader (you, one year later) that it is something custom.
Suggestion for a theme named wpse51275: