Opened 14 years ago
Closed 14 years ago
#15899 closed defect (bug) (fixed)
Allow wp_title() to display cleaner titles for post_format archives.
Reported by: | mfields | Owned by: | markjaquith |
---|---|---|---|
Milestone: | 3.1 | Priority: | normal |
Severity: | normal | Version: | 3.1 |
Component: | Taxonomy | Keywords: | has-patch dev-feedback |
Focuses: | Cc: |
Description
wp_title() will print the following string for the status format: » post-format-status
IMO it would be better to have a more readable representation of the format.
Attachments (5)
Change History (22)
#3
@
14 years ago
If I understand correctly, it would be better to filter get_terms() instead. If so, would it make sense to use one of the following hooks?
$_term = apply_filters('get_term', $_term, $taxonomy); $_term = apply_filters("get_$taxonomy", $_term, $taxonomy); $_term = sanitize_term($_term, $taxonomy, $filter);
If so, I can whip up another patch.
#5
follow-up:
↓ 6
@
14 years ago
markjaquith - get_post_format() calls get_the_terms() and then filters the value of name:
str_replace('post-format-', '', $format->name )
I think it might be a good idea to remove this filter from get_post_format() and apply it directly to the "name" property of the term object in get_term(), get_terms() and get_the_terms(). What do you think?
#6
in reply to:
↑ 5
@
14 years ago
Replying to mfields:
I think it might be a good idea to remove this filter from get_post_format() and apply it directly to the "name" property of the term object in get_term(), get_terms() and get_the_terms(). What do you think?
Agreed. This should be filtered as low in the stack as possible. We should skip get_the_terms() and go straight to wp_get_object_terms() I think. So there and also get_term() and get_terms().
#7
@
14 years ago
Cool. My last question. Each function ( get_term(), get_terms() and wp_get_object_terms() ) allow for it's return value to be filtered via external function. Since post_formats are a higher-level abstraction of the taxonomy system it seems appropriate to use the built-in filters instead of mucking up the function with code specific to post_formats. If this is the correct route to take, where should the new functions go? /includes/post.php is where most of the post_format specific functions are located.
#8
@
14 years ago
Correct - use the built-in filters. The function(s) can go at the bottom of wp-includes/post.php, following the two private functions at the end of the file that are already used to filter post formats elsewhere. They should be private and start with an underscore.
#9
@
14 years ago
- Keywords needs-patch added; dev-feedback has-patch removed
- Owner set to mfields
- Status changed from new to assigned
#10
@
14 years ago
Here's a new patch (15899-2.patch) that I believe fixes the bug by including everything discussed here. I've tested with my local installation. The patch does not seem to cause any unexpected errors as far as I can tell. I've tested the following functions within the loop on multiple views:
var_dump( get_term( 140, 'post_format' ) ); var_dump( get_terms( 'post_format' ) ); var_dump( get_terms( array( 'post_format' ) ) ); var_dump( wp_get_object_terms( $post->ID, 'post_format' ) ); var_dump( get_the_terms( $post->ID, 'post_format' ) ); var_dump( get_post_format( $post ) );
All seem to be working. Please let me know if there need to be any changes made to the patch. I'm hear to learn. Thanks!
#12
@
14 years ago
This is a good start. Things I notice:
- Instead of using the get_term filter, use the get_$taxonomy filter. The filter will run only when necessary and prevents post_format checks.
- Minor thing. Generally we only use
===
when it's actually necessary. Otherwise, stick to==
.
- No need to establish the
$order
key if we're not using it.
- No need to specify 10 as a priority if we're only passing one argument.
- We need to do more than just str_replace. You're very close though. Just call get_post_format_string( $slug ) on the result (result, as in, once you've done the str_replace). That'll then provide the translated term name.
- I'm not at all worried about this, but I just wanted to point out that the get_terms() filter won't work if fields = names. I don't see other issues (with legitimate use cases) elsewhere.
Mark may have something else.
#13
@
14 years ago
Just uploaded a new patch. it contains the following suggested modifications:
- Identical operator swapped for equality operator.
- Priority of 10 removed where appropriate.
- The 'get_post_format' hook is now being used to filter get_terms() and the post_format check has been removed.
- get_terms() will now return appropriate results for if $argsfields? is passed with a value of 'names'.
- get_post_format_string() has been added to each string name.
#14
@
14 years ago
Haven't tested myself yet, but this looks solid.
Two small notes: else
should be on the same line as }
. Also, you no longer need the second argument for _post_format_get_term.
I thought we addressed this, damn. What we need to do is modify the term name. Unfortunately that isn't portable if we store it in the db. I wonder if we can filter on term fetch and pull from the string helpers.