Make WordPress Core

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's profile mfields Owned by: markjaquith's profile 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)

15899.patch (656 bytes) - added by mfields 14 years ago.
15899-2.patch (1.9 KB) - added by mfields 14 years ago.
15899-3.patch (2.2 KB) - added by mfields 14 years ago.
15899-4.patch (2.2 KB) - added by mfields 14 years ago.
15899-5.diff (2.3 KB) - added by markjaquith 14 years ago.

Download all attachments as: .zip

Change History (22)

@mfields
14 years ago

#1 @mfields
14 years ago

  • Cc michael@… added

#2 @nacin
14 years ago

  • Milestone changed from Awaiting Review to 3.1

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.

#3 @mfields
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.

#4 @markjaquith
14 years ago

mfields — I think we'll have to filter on both get_post_format and get_terms

#5 follow-up: @mfields
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 @nacin
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 @mfields
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 @nacin
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 @nacin
14 years ago

  • Keywords needs-patch added; dev-feedback has-patch removed
  • Owner set to mfields
  • Status changed from new to assigned

@mfields
14 years ago

#10 @mfields
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!

#11 @mfields
14 years ago

  • Keywords has-patch dev-feedback added; needs-patch removed

#12 @nacin
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.

@mfields
14 years ago

#13 @mfields
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 @nacin
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.

@mfields
14 years ago

#15 @mfields
14 years ago

The fourth version corrects these two errors.

@markjaquith
14 years ago

#16 @markjaquith
14 years ago

  • Owner changed from mfields to markjaquith
  • Status changed from assigned to reviewing

get_post_format() had to be tweaked to use the post-format--stripped version of the slug. NOT the translated name.

#17 @markjaquith
14 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

(In [17092]) Translate post format term names on the fly. props mfields. fixes #15899

Note: See TracTickets for help on using tickets.