[wp-trac] [WordPress Trac] #40969: RFE: get_template_part() to return something or warn when nothing found

WordPress Trac noreply at wordpress.org
Wed Jan 22 02:03:05 UTC 2020


#40969: RFE: get_template_part() to return something or warn when nothing found
-------------------------------------------------+-------------------------
 Reporter:  sphakka                              |       Owner:
                                                 |  johnbillion
     Type:  enhancement                          |      Status:  reviewing
 Priority:  normal                               |   Milestone:  5.4
Component:  Themes                               |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch dev-feedback needs-unit-   |     Focuses:  template
  tests needs-dev-note early                     |
-------------------------------------------------+-------------------------

Comment (by SergeyBiryukov):

 `has_template_part()` seems like a good addition. However, I would also
 like to reconsider the original approach of adding a return value to
 `get_template_part()`.

 The concerns in comment:15 were about themes outputting the return value
 via `echo get_template_part( ... )`:

 * Unexpected content being sent to the browser.
 * A path disclosure security issue.

 These can both be addressed by returning `void` (`null`) on success (same
 as now) and `false` on failure, which would not result in any unexpected
 output, but would still allow for debugging.

 This is more or less consistent with some template functions returning
 `void|string` on success (`void` if `$echo` argument is true, which is the
 case by default, `string` otherwise):

 * `wp_list_authors()`
 * `wp_list_bookmarks()`
 * `wp_list_categories()`
 * `wp_tag_cloud()`
 * `comment_class()`
 * `trackback_url()`
 * `wp_list_comments()`
 * `get_search_form()`
 * `wp_loginout()`
 * `wp_login_form()`
 * `wp_register()`
 * `wp_get_archives()`
 * `get_calendar()`

 and some other functions returning `void|false` (`void` on success,
 `false` on failure):

 * `the_terms()`
 * `wpdb::print_error()`
 * `wpdb::bail()`

 and also some admin functions returning `void|false` (`void` on success,
 `false` on failure):

 * `parent_dropdown()`
 * `update_nag()`
 * `maintentance_nag()`
 * `wp_plugin_update_row()`
 * `wp_theme_update_row()`

 See [attachment:"40969.7.diff"]. Any feedback welcome :)

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


More information about the wp-trac mailing list