Make WordPress Core

Opened 13 years ago

Last modified 5 years ago

#18791 new enhancement

Add custom post type support for Author Template functions

Reported by: sirzooro's profile sirzooro Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2.1
Component: Users Keywords: needs-unit-tests needs-patch
Focuses: template Cc:

Description

Functions defined in wp-includes/author-template.php assumes that post type == post. It will be good to enhance them so they will be able to work with specified post type.

At first sight following functions will need update:

get_the_author_link()
the_author_link()
get_the_author_posts()
the_author_posts()
the_author_posts_link()
get_author_posts_url()
wp_list_authors()

I suspect there will be other updates needed, to support new post_type argument added to author's url.

Attachments (3)

18791.patch (2.9 KB) - added by mordauk 10 years ago.
18791-2.patch (3.9 KB) - added by mordauk 10 years ago.
18791.2.patch (5.4 KB) - added by DrewAPicture 10 years ago.
docs + single post type only

Download all attachments as: .zip

Change History (18)

#1 @mikeschinkel
13 years ago

  • Cc mikeschinkel@… added

+1.

Would it not make sense to consider creating a WP_Author class too?

#2 @sirzooro
13 years ago

  • Keywords dev-feedback added

WordPress already has WP_User class - probably it would be better to add new methods to it instead of creating a WP_Author class.

I wonder if it is possible to create posts without assigning any user as author (anonymous posting) - if yes, WP_Author class would be better solution.

#3 @nacin
11 years ago

  • Component changed from Template to Users
  • Focuses template added
  • Keywords dev-feedback removed

#4 @mordauk
10 years ago

Looks like get_the_author_posts(), the_author_posts(), and wp_list_authors() are the only ones that are still limited to just posts.

#5 @mordauk
10 years ago

Nevermind, is_multi_author() is also limited to just posts.

@mordauk
10 years ago

#6 follow-up: @mordauk
10 years ago

I think 18791.patch takes care of it.

#7 in reply to: ↑ 6 ; follow-up: @norcross
10 years ago

Replying to mordauk:

I think 18791.patch takes care of it.

I may be misreading this one, but it looks like the patch only supports one post type being passed.

@mordauk
10 years ago

#8 in reply to: ↑ 7 @mordauk
10 years ago

Replying to norcross:

Replying to mordauk:

I think 18791.patch takes care of it.

I may be misreading this one, but it looks like the patch only supports one post type being passed.

Updated patch attached to address this.

@DrewAPicture
10 years ago

docs + single post type only

#9 @DrewAPicture
10 years ago

  • Keywords has-patch added; needs-patch removed
  • Milestone changed from Awaiting Review to 4.0

While I like the idea of someday being able to add multi support for post types here, I think it would be best to tackle that separately. Switching to multiple post types would just send us down a rabbit hole in several spots, not limited to the cap checks in get_posts_by_author_sql().

In 18791.2.patch, I've removed the multiple post types support, cleaned up the logic and added the requisite inline docs updates.

I left in the change to is_multi_author() where the post_type condition was removed, though I'm a little dubious of the effect of that, especially since we don't currently have any kind of content definition for what does or doesn't have "authors".

#10 follow-up: @nacin
10 years ago

I think is_multi_author() should be left alone entirely.

Not sure I see why get_posts_by_author_sql() needs to change at all, either. The sanitization/preparation in get_posts_by_author_sql() looks wrong. A unit test would catch this. (Needs unit tests.) The other instance of $post_type_where has similar issues.

#11 in reply to: ↑ 10 @mordauk
10 years ago

Replying to nacin:

I think is_multi_author() should be left alone entirely.

Not sure I see why get_posts_by_author_sql() needs to change at all, either. The sanitization/preparation in get_posts_by_author_sql() looks wrong. A unit test would catch this. (Needs unit tests.) The other instance of $post_type_where has similar issues.

If not adding support for multiple post types, I think you're right in that get_posts_by_author_sql() doesn't need changed at all.

I'd disagree about is_multi_author() though. For sites that use multiple public post types, it would be expected for is_multi_author() to properly detect when there are multiple authors on the site.

#12 @helen
10 years ago

  • Keywords needs-unit-tests added
  • Milestone changed from 4.0 to Future Release

No consensus on approach, needs unit tests, punting.

#13 @mordauk
10 years ago

Could we milestone for 4.1 to help encourage further discussion / attention?

#14 @SergeyBiryukov
10 years ago

  • Keywords 4.1-early added

#15 @chriscct7
9 years ago

  • Keywords needs-patch added; has-patch 4.1-early removed
Note: See TracTickets for help on using tickets.