[wp-trac] [WordPress Trac] #43644: Revert multiline calls to actions and filters
WordPress Trac
noreply at wordpress.org
Wed Jul 18 07:50:29 UTC 2018
#43644: Revert multiline calls to actions and filters
-------------------------------------+-------------------------------------
Reporter: johnbillion | Owner: johnbillion
Type: task (blessed) | Status: accepted
Priority: normal | Milestone: 5.0
Component: General | Version: trunk
Severity: normal | Resolution:
Keywords: needs-patch 2nd-opinion | Focuses: docs, coding-standards
-------------------------------------+-------------------------------------
Comment (by azaozz):
I'm actually thinking we should *ban* multi-line function parameters:
- There is no good, practical reason to have them. They only make some
piece of coding harder to read.
- In core most were introduced "by mistake" last time the source code was
reformatted to match the supposedly "core's own" coding standards. I see
that as a bug that needs fixing.
I agree that the cute little example by @ocean90
[https://core.trac.wordpress.org/ticket/43644#comment:4 above] doesn't
look that bad. But that's just an example. In reality allowing multi-line
stuff inside of function calls would mean that we "agree" to this type of
coding:
{{{
<?php
$content = apply_filters(
'wp_comment_no_reply', // First arg.
'', // Second arg.
array( // Third arg.
'position' => $position,
'checkbox' => $checkbox,
'mode' => $mode,
),
esc_html(
sprintf(
__( 'This is a long piece of text that should
never be inside of a function call. Even worse: it might end up in a
nested multi-line function call. %s, %s.' ),
add_query_arg(
array(
'bah_where_am_i' =>
'undefined',
'how_did_i_get_here' => 'who-
knows',
),
remove_query_arg(
array(
'_wp_http_referer',
'_wpnonce',
'error',
'message',
'paged',
),
wp_unslash(
$_SERVER['REQUEST_URI'] )
)
),
'<p>' . __( 'This is another long piece of text
that should never be inside of a function call...' ) . '</p>'
)
)
);
}}}
Frankly, this code stinks. There is no practical reason to be written that
way. It's hard to read, has a lot of pointless indentation, and is by no
means "Poetry". Don't see why the coding standards should allow that.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43644#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list