[buddypress-trac] [BuddyPress Trac] #6278: Attachment Library

buddypress-trac noreply at wordpress.org
Wed Mar 4 15:23:51 UTC 2015


#6278: Attachment Library
------------------------------------+------------------
 Reporter:  imath                   |       Owner:
     Type:  enhancement             |      Status:  new
 Priority:  normal                  |   Milestone:  2.3
Component:  API                     |     Version:
 Severity:  normal                  |  Resolution:
 Keywords:  has-patch dev-feedback  |
------------------------------------+------------------

Comment (by boonebgorges):

 imath - Thank you for your continued work on this. I think we're getting
 closer to a solid foundation for an API that will be usable by all
 components. I love the implementation details of the upload handling - the
 way you're setting upload directories, filtering `'upload_dir'`, wrapping
 WP's upload functions, etc are all great.

 The syntax doesn't seem quite right to me. I have two broad thoughts about
 it.

 1. It seems to me that `BP_Attachment` should be a base class (maybe even
 `abstract`), with `BP_Attachment_Member_Avatar` and
 `BP_Attachment_Group_Avatar` as extending classes. Extending classes would
 be responsible for (a) setting the attachment subdirectory path, (b)
 managing the connection between attachment and object (in the case of
 avatars, this just means putting it in the correct directory with the
 proper filename, but in the future it might mean things like post-to-post
 relationships or taxonomies or postmeta or whatever), (c) attachment-
 specific validation (eg, avatars must be image files), and other stuff
 like that. In other words - extending classes would do a lot of the work
 that you're currently doing with the arguments that you are passing to
 `BP_Attachment::__construct()`. This would allow `BP_Attachment` to be
 free of any internal reference to avatars.

 2. What is the advantage of `buddypress()->avatar` being a `BP_Attachment`
 object? Is it for backward compatibility? It seems to me that attachments
 are objects in the proper sense, and do not need to be forced into the
 singleton pattern. As a developer using the API, I would expect a syntax
 closer to this:

 {{{
 $avatar = new BP_Attachment( $args ); // or BP_Attachment_Member_Avatar or
 whatever
 $success = $avatar->upload( $uploaded_file );
 }}}

 or maybe, for future implementations of attachments:

 {{{
 $avatar = new BP_Attachment_Foo();
 $success = $avatar->upload( $uploaded_file );
 if ( $success ) {
     $avatar->associate_with_group( $group_id );
     $avatar->associate_with_user( $user_id );
     // etc etc etc
 }
 }}}

 Obviously, this is very rough. But it seems more intuitive to me, as a
 potential user of the API. What do others think?

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/6278#comment:3>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list