WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 3 years ago

#27056 closed enhancement (fixed)

Add hook for custom post.php actions

Reported by: jfarthing84 Owned by: brianvan
Milestone: 4.6 Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: good-first-bug has-patch
Focuses: Cc:

Description

I find myself in a situation where I'd like to use the post.php page to handle some custom actions. It seems pretty trivial and harmless to add an action hook to the default case of the switch statement.

Attachments (7)

27056.patch (325 bytes) - added by jfarthing84 6 years ago.
27056.2.patch (344 bytes) - added by Mte90 4 years ago.
updated patch with new name for the filter
27056.3.diff (328 bytes) - added by brianvan 4 years ago.
updated patch with @sudar's suggestion
27056.3.2.diff (328 bytes) - added by brianvan 4 years ago.
updated patch with @sudar's suggestion
27056.4.diff (511 bytes) - added by brianvan 4 years ago.
Adding docs to patch
27056.3.patch (524 bytes) - added by sudar 4 years ago.
27056.4.patch (583 bytes) - added by DrewAPicture 3 years ago.
Docs tweaks

Download all attachments as: .zip

Change History (25)

@jfarthing84
6 years ago

#2 @channeleaton
5 years ago

  • Keywords close added

Rather than use post.php, try using admin-post.php. Should do exactly what you're trying to do.

#3 @jfarthing84
5 years ago

Using admin-post.php is not an option because you cannot modify where edit-form-advanced.php posts to.

#4 @wonderboymusic
4 years ago

  • Keywords good-first-bug needs-docs needs-patch added; close removed
  • Milestone changed from Awaiting Review to Future Release

perhaps a different name for the filter + docs

@Mte90
4 years ago

updated patch with new name for the filter

#5 @sudar
4 years ago

The current patch by @Mte90 uses the name post_action_undefined. I think instead we can create the action name dynamically like post_action_{$action}.

@wonderboymusic Would you prefer that or do you have a different name in mind?

@brianvan
4 years ago

updated patch with @sudar's suggestion

@brianvan
4 years ago

updated patch with @sudar's suggestion

#6 @brianvan
4 years ago

  • Keywords has-patch added; needs-patch removed

This is how I tested the patch I submitted:
Used a clean copy of WP (code, database) & tested the patch + the below action hook to successfully trigger the new action using
the site url + /wp-admin/post.php?post=1&action=asdflkjadsflkjasdf
(on clean installs this is the edit screen for the "Hello World" post)

The result was a page with just the words "Theme test", as expected.

<?php
function second_theme_test(){
        echo "Theme test";
        die();
}
add_action( 'post_action_asdflkjadsflkjasdf' , "second_theme_test" );

@brianvan
4 years ago

Adding docs to patch

#7 @brianvan
4 years ago

  • Keywords needs-docs removed

#8 @DrewAPicture
4 years ago

  • Milestone changed from Future Release to 4.5
  • Owner set to brianvan
  • Status changed from new to assigned

Assigning to mark the good-first-bug ticket "claimed".

This ticket was mentioned in Slack in #core by chriscct7. View the logs.


4 years ago

#10 @sudar
4 years ago

I have added a period to the @param in phpdoc to @brianvan's patch so that it follows the WordPress Documentation standards.

@sudar
4 years ago

This ticket was mentioned in Slack in #core by mte90. View the logs.


4 years ago

This ticket was mentioned in Slack in #core by jorbin. View the logs.


3 years ago

#13 follow-up: @jorbin
3 years ago

  • Keywords early added
  • Milestone changed from 4.5 to Future Release

Sadly this has missed the 4.5 beta deadline for enhancements, let's take a look at it early in 4.6.

#14 in reply to: ↑ 13 @brianvan
3 years ago

Replying to jorbin:

Just a heads up that we should take a look at this before it slips again past 4.6. (Sorry if this is bad Trac etiquette; I don't otherwise know how I'd call this to the team's attention.)

This is low priority but also a really basic code addition.

@DrewAPicture
3 years ago

Docs tweaks

#15 @DrewAPicture
3 years ago

  • Milestone changed from Future Release to 4.6

In 27056.4.patch I've adjusted the hook doc summary a bit and added a description for the dynamic portion of the hook name.

Moving to 4.6 for consideration.

#16 @ocean90
3 years ago

  • Keywords early removed

This ticket was mentioned in Slack in #core by brianvan. View the logs.


3 years ago

#18 @ocean90
3 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 37424:

Posts: Fire a post_action_{$action} action for a custom post action request.

Props jfarthing84, Mte90, brianvan, sudar, DrewAPicture.
Fixes #27056.

Note: See TracTickets for help on using tickets.