Make WordPress Core

Opened 8 years ago

Closed 7 years ago

#8657 closed enhancement (wontfix)

add filter to get_post_status() to allow overriding the status of objects

Reported by: DD32 Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.7
Component: General Keywords: has-patch
Focuses: Cc:


At present, For an attachment to be visible on the front end, The attachment needs to be either attached to a published post, or the user needs to be logged in and be able to edit the attachment.

Sometimes this'll cause problems with those designing websites focused around attachment items (A Unique Photo-orientated site for example, focused around Images rather than Posts)

While there are a lot of issues (in my mind) of separate interlinked issues with having attachments published on the front end, They can all be worked around, Aside from get_post_status() returning false for attachments, This ends up causing a 404 for non-attachment-editors/non-logged-in-users; Attaching a filter to this will allow for being able to set a attachment as 'publish'ed while not modifying the way the rest of the wordpress media management works, Eg:

add_filter('post_status-attachment', 'theme_attachment_publish');
function theme_attachment_publish($status) {
	return is_admin() ? $status : 'publish';

Attachments (2)

8657.diff (934 bytes) - added by DD32 8 years ago.
8657.2.diff (909 bytes) - added by Denis-de-Bernardy 8 years ago.

Download all attachments as: .zip

Change History (15)

8 years ago

#1 @DD32
8 years ago

The modification to get_post_type() was made to allow passing of a $post object to the function, It seems the (int) check was preventing the $post object being passed as originally intended.

#2 @DD32
8 years ago

  • Keywords has-patch added; hsa-patch removed

#3 @Denis-de-Bernardy
8 years ago

  • Keywords tested added

works fine in today's trunk

#4 @Denis-de-Bernardy
8 years ago

  • Keywords commit added

#5 @filosofo
8 years ago

  • Keywords tested commit removed

You shouldn't do an is_integer check on the post id for get_post_type(). Because PHP is loosely typed, WordPress ends up passing around as strings a lot of things that look and act like integers. So checking that the id is actually an integer is going to produce some perplexing bugs somewhere.

#6 follow-up: @filosofo
8 years ago

Also, aren't there better, existing ways to solve the main problem?

It seems like you're changing the business logic to solve a presentation logic problem.

#7 @Denis-de-Bernardy
8 years ago

true. we could use is_numeric instead.

var_dump(is_numeric("1.0")); true

#8 in reply to: ↑ 6 @Denis-de-Bernardy
8 years ago

  • Keywords dev-feedback added

Replying to filosofo:

Also, aren't there better, existing ways to solve the main problem?

It seems like you're changing the business logic to solve a presentation logic problem.

isn't there a workflow issue underneath that is causing issues?

#9 @westi
8 years ago

  • Milestone changed from 2.8 to 2.9

Move to 2.9 for now.

#10 @Denis-de-Bernardy
7 years ago

  • Keywords dev-feedback removed

#11 @ryan
7 years ago

  • Milestone changed from 2.9 to 3.0

#12 @Denis-de-Bernardy
7 years ago

do we want this into 3.0, or shall we punt?

#13 @dd32
7 years ago

  • Milestone 3.0 deleted
  • Resolution set to wontfix
  • Status changed from new to closed

I'm closing as wontfix instead.

A filter would be handy in some cases, especially in the outlined case. However, There are better ways to achieve that hack than this.

I'm only closing this in the hope that 3.1 will bring a change to media that allows them to be treated as first class citizens rather than the Tag-alongs that they are now.

Note: See TracTickets for help on using tickets.