[wp-trac] [WordPress Trac] #17134: Add support for the_slug() in template tags
WordPress Trac
noreply at wordpress.org
Fri Feb 1 05:01:24 UTC 2013
#17134: Add support for the_slug() in template tags
-----------------------------------+------------------------------
Reporter: tomauger | Owner:
Type: feature request | Status: reopened
Priority: normal | Milestone: Awaiting Review
Component: Template | Version:
Severity: normal | Resolution:
Keywords: 2nd-opinion has-patch |
-----------------------------------+------------------------------
Comment (by nacin):
I think only bad things can come from using this function.
1. Filters don't make sense here. Title, content, excerpt, etc. have
filters because raw content is stored in the database and we clearly need
to process it before displaying it. With a sanitized post slug, that is
not the case. There is no processing that should occur. The filter just
doesn't make sense — if you are going to have a function that returns the
slug, it would be best unfiltered as it is raw data.
2. It may be used, improperly, to construct a URL. Never underestimate
the ingenuity of fools. Someone, somewhere, will do `<a href="/<?php
the_slug(); ?>/">`. Why? Because there isn't another obvious use case for
such a function.
3. For hierarchical post types, I don't know if this is the expected
return value.
4. It may be used, improperly, as an HTML ID or class name, or a more
restrictive field. There is no guarantee that an unprocessed slug meets
the standards of one of these attributes. It could potentially have
uppercase characters, spaces, periods, international characters, and other
special characters, because the sanitization is flexible and may be
modified by plugins. (Example: api.jquery.com allows periods and uppercase
characters.) A class name should really go through sanitize_html_class(),
which makes me wonder what an echo-based `the_slug()` could ever be used
for.
And if there is no good use of `the_slug()`, do we even need the
associated getter? As stated, A) there is no common use case for this,
which basically means no template tag is necessary, and B) this is raw
data, which further limits the reason for having a template tag. At that
point, one should use `get_post( optional $id )->post_name`.
I have yet to do a Google search for the_slug but I think I would be hard-
pressed to find valid and common use cases among the results.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/17134#comment:14>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list