[wp-trac] [WordPress Trac] #32008: Wrapper method for esc_attr

WordPress Trac noreply at wordpress.org
Fri May 1 05:33:44 UTC 2015


#32008: Wrapper method for esc_attr
------------------------------------------------+------------------
 Reporter:  welcher                             |       Owner:
     Type:  enhancement                         |      Status:  new
 Priority:  normal                              |   Milestone:  4.3
Component:  General                             |     Version:  4.2
 Severity:  normal                              |  Resolution:
 Keywords:  has-patch dev-feedback 2nd-opinion  |     Focuses:
------------------------------------------------+------------------

Comment (by welcher):

 Thanks for your comments @dd32!

 I agree with leaving `esc` in the function name and about `esc_{type}` and
 `echo_{type}` being easily confused in code reviews - I'll update the
 patch accordingly and remove the unit tests as per @jorbin

 However, I would argue that prepending `e_` is less confusing than it
 seems for a couple of reasons:

 1. The functions make complete sense when read left to right. They `echo`
 the output of `esc_{type}()`.
 2. Translations functions have `_e` at the end of the method name and can
 be read as if they are mashing `esc_{type}()` and  `_e()` together -
 clearly this is not the case but the effect is similar.
 3. There are paradigms in place in core now where prepending a function
 changes the result/output. i.e `the_title()` and `get_the_title()`


 Replying to [comment:5 dd32]:
 > Personally I'm leaning away from adding it.
 > * `esc_{type}_e()` is shorter than `echo esc_{type}( __() )` which is
 why it exists
 > * `echo_esc_{type}()` isn't any shorter than `echo esc_{type}()` and the
 extra brackets from above are not needed
 > * `e_esc_{type}()` or `esc_{type}_echo` is too much like
 `esc_{type}_e()`, and seems like it'll cause confusion even further
 > * I don't really like dropping the esc prefix in cases like
 `echo_attr()`, as it's less obvious what the function does, and easy to
 confuse with `echo attr()` in code review
 >
 > Is auto-complete by an IDE really worth it here? it's the difference
 between `echo_` and `echo esc` having to be typed for triggering the auto
 complete..

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32008#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list