Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#12306 closed enhancement (invalid)

Custom attachment types

Reported by: jfarthing84's profile jfarthing84 Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Media Keywords: developer-feedback has-patch
Focuses: Cc:

Description

I am testing using custom post types as custom attachment types and it seems that the only blockade is the function wp_get_attachment_url(). Here is why:

if ( 'attachment' != $post->post_type || empty($url) )
	return false;

So, my proposal is to either allow a filter to supply valid attachment types instead of checking against 'attachment' or (the better method) use the 'inherit_type' argument from within the register_post_type function and check for an 'inherit_type' of 'attachment'.

I will attach my implementation of both methods, and the developers can choose which one to use.

The only other problem is that many parts of the query have 'attachment' hardcoded in, but, you can get around this with filters. However, my proposal introduces a simple solution to have this fully built-in (check for inherit_type of 'attachment').

Attachments (2)

post.php.diff (638 bytes) - added by jfarthing84 15 years ago.
This is the first method of using a filter on the 'attachment_types'
post.php.2.diff (677 bytes) - added by jfarthing84 15 years ago.
This one is the second method of checking for an inherit_type of 'attachment'

Download all attachments as: .zip

Change History (14)

@jfarthing84
15 years ago

This is the first method of using a filter on the 'attachment_types'

@jfarthing84
15 years ago

This one is the second method of checking for an inherit_type of 'attachment'

#1 @scribu
15 years ago

  • Keywords changed from developer-feedback, has-patch to developer-feedback has-patch
  • Milestone changed from Unassigned to 3.0

As of r13254, inherit_type is not mentioned anywhere, except docs. So, I'm not sure what exactly it's supposed to do.

It should probably default to 'attachment'.

#2 @jfarthing84
15 years ago

It should be used to determine how to handle custom post types within built-in functions just as I am proposing to use it.

For instance, setting the inherit type to 'attachment' tells the core that this is an attachment, otherwise the core would not know if a custom post type of "doohickey" is supposed to be a post, page, attachment or what.

So, I set "doohickey" to post and the core will display this with posts and use the post edit screen to edit it, etc.

If I set "doohickey" to attachment, the core should display it with attachments and use the edit attachment screen to edit it, etc.

So on and so forth. It makes perfect sense. Make me a commiter and I'll help implement it! ;-)

#3 @jfarthing84
15 years ago

If nothing else just implementing either one of my patches would be great. I could them make a "Term Taxonomy Attachment" plugin.

#4 @scribu
15 years ago

Why would you need more than one type of attachment again?

You could assign multiple taxonomies to the same 'attachment' post type.

#5 @jfarthing84
15 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Because I wasn't thinking right! LOL! Wow, I wasted a lot of development time on this today and I wasn't thinking about assigning a taxonomy to the attachment as if it was a post. I guess because there is no way to do it in the UI, I didn't conceive it. I don't know why not, when I am in the code more than the UI!

#6 @jfarthing84
15 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

Sorry, but I realize why I was confused. My idea was wanting to "attach" an attachment to a taxonomy. However, the only option out-of-the-box is to attach to a post or page. As you stated, we can assign taxonomies to the attachment (it is a "post", in essence), but it will still show as unattached in the UI and will not show that it is "attached" to a taxonomy without some plugin modification.

#7 @voyagerfan5761
15 years ago

  • Cc WordPress@… added

#8 @scribu
15 years ago

Same idea here: #12290

#9 @scribu
15 years ago

I don't really see the use for 'inherit_type': you can deduce that by looking at the post_type of the parent and of the child.

Replying to jfarthing84:

As you stated, we can assign taxonomies to the attachment (it is a "post", in essence), but it will still show as unattached in the UI and will not show that it is "attached" to a taxonomy without some plugin modification.

I don't get what you mean by "plugin modification". You'll need a plugin anyway, to create the new attachment type.

By the way, have you seen the Category Icons plugin, for example? It seems to be doing it's job, without any patches, even with WP 2.8.

#10 @jfarthing84
15 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

After more testing, I am able to achieve what I want to by using taxonomies. Thanks for pointing that out... I wasn't even thinking!

#11 @scribu
15 years ago

  • Milestone 3.0 deleted

#12 @scribu
15 years ago

Found another plugin:

Taxonomy Images

Note: See TracTickets for help on using tickets.