WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#25279 closed enhancement (duplicate)

Use action hooks to add default post publishing actions to post edit screen instead of hardcoding them

Reported by: ragulka Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Administration Keywords:
Focuses: Cc:
PR Number:

Description

Quite often plugin and theme developers need to remove some of the publishing actions from the post edit screen. It is more often a real use case with custom post types of course.

I have written a simple plugin that adds a custom post type, but I do not need the schedule feature. I also do not need private/public publishing action.

I could simply remove the default submitdiv meta box and just re-create the functionality what I need, or hide the actions using CSS or JS, but that always feels like a hack to me. WordPress usually provides an elegant way to customize the UI and I think this is one of the areas where it lags behind...

Re-creating the meta-box code feels just wrong when I simply need to remove 1 or 2 actions. CSS and JS are not good solutions from usability perspective.

My suggestion is that the default publishing actions should be added using hooks instead, because that would allow plugin and theme developers to simply remove them when not needed.

Namely, we should move all hardcoded minor, misc and major publishing actions to separate functions that make use of the already existing post_submitbox_misc_actions and post_submitbox_start action hooks.
Since there is no action hook for minor publishing actions, we could create a new action hook for that as well.

If we want to take this one step further, we could rename the actions so that they follow a similar convetion. For example: post_submitbox_minor_actions, post_submitbox_misc_actions and post_submitbox_major_actions

Consider the following code:

Somewhere in core:

function publish_date_publishing_action() {
  // code here...
}
add_action('post_submitbox_misc_actions', 'publish_date_publishing_action');

Somewhere in a plugin:

function remove_book_publishing_date_action() {
  if ( is_admin() && $typenow == 'book' ) {
    remove_action('post_submitbox_misc_actions', 'publish_date_publishing_action');
  }
}
add_action('init', 'remove_book_publishing_date_action');

This is clearly a better approach than replacing the meta box or using CSS or JS to hide certain parts of it.

I would be happy to provide the code as a patch as well.

Attachments (1)

post-submit-hooks.25279.diff (24.9 KB) - added by ragulka 6 years ago.

Download all attachments as: .zip

Change History (2)

#1 @helen
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #12567.

Note: See TracTickets for help on using tickets.