Skip to content

Conversation

@marcus-downing
Copy link

As suggested in this thread, I've added a number of action and filter hooks throughout the Attachments code that should make it easier to customise and integrate it with other aspects of a site.

I note with approval that most of the visible strings are already internationalised, meaning they can be changed for a specific site (if for example a client wanted to call them "Documents" rather than "Attachments".

I've been quite generous with the actions, since people might want to put their modifications in different places depending on their unique needs.

Actions

  • attachments_init - after initialising the plugin
  • attachments_edit_post_types_before - at the start of the settings page (but after the heading)
  • attachments_edit_post_types_after - at the end of the settings page (but before the Save button)
  • attachments_meta_before - at the start of the meta box
  • attachments_list_before - at the start of the list in the meta box (but after the Attach button, and only if there are attachments to display)
  • attachments_list_item_before - at the start of a single attachment's entry in the meta box (but after the title)
  • attachments_list_item_after - at the end of a single attachment's entry in the meta box
  • attachments_list_after - at the end of the list in the meta box (but only if there are attachments to display)
  • attachments_meta_after - at the end of the meta box
  • attachments_save - after saving attachments

Filters

  • attachments_post_types - the post type options to display on the settings page

    [ id => { labels: { name }, name } ]

  • attachments_save_attachment_ids - the ids of attachments to save for a given post (also passes $post_id)

    [ id ]

  • attachments_save_attachment_details - the attachment data to be serialised (also passes $attachment_id and $post_id)

    [ id, title, caption, order ]

  • attachments_get_filesize_formatted - the formatted file size for a given attachment (also passes $path)

    string

  • attachments_get_attachments - the list of attachments for the given post

    [ [ id, name, mime, title, caption, filesize, location, order ] ]

@jchristopher
Copy link
Owner

Fantastic, this is great! I've got some time blocked out in June to spend on all of my plugins, this will be near the top of my to-do list. In the meantime anybody can feel free to pull and test on their end as well. Thanks again!

@jchristopher
Copy link
Owner

Hey Marcus, this is so great but I must admit I forgot to merge this pull request when I updated Attachments to version 3.0. I'm going to put these back in by hand, but unfortunately won't be able to get to it for a couple weeks. I've got a task on the roadmap for version 3 to add in actions/filters as well.

@jchristopher
Copy link
Owner

Hi Marcus. I'm actually going to close this since its for the deprecated version, but I'm working on adding all of your work to the 3.0 branch and will be sure to give you props. Thanks again!

stevensjn pushed a commit to stevensjn/attachments that referenced this pull request Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants