WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 7 months ago

#28112 assigned enhancement

bulk_edit_posts() function needs an action hook

Reported by: helgatheviking Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.9
Component: Quick/Bulk Edit Keywords: dev-feedback has-patch
Focuses: Cc:
PR Number:

Description

Currently, the only method that I can find to save additional data in via bulk edit requires using an .ajax() call.

This could be avoided if bulk_edit_posts() had a simple action hook at the end before it returns it's results.

do_action( 'bulk_edit_posts', $post_data );

return array( 'updated' => $updated, 'skipped' => $skipped, 'locked' => $locked );

Attachments (3)

28112.diff (663 bytes) - added by Mte90 3 years ago.
28112.2.diff (533 bytes) - added by mrasharirfan 12 months ago.
I have applied WordPress coding standards to the patch.
28112.3.diff (576 bytes) - added by itowhid06 10 months ago.
Updated @since to reflect actual version the hook is introduce

Download all attachments as: .zip

Change History (22)

#1 @helgatheviking
5 years ago

Some JS triggers in inline-edit-posts.js wouldn't go astray either. For example:

t.trigger( "setBulk-inlineedit" );

#2 @helen
5 years ago

I'm enjoying your bulk/quick edit tickets very much - just want to note (as I probably have elsewhere) that this is one of those times where we'd be better off with a revamp and that any additions to what exists need to be considered ever-more carefully in that light. A Backbone-ified bulk/quick edit has been tossed around as an idea a couple times, if you want to look into that.

#3 @helgatheviking
5 years ago

I'm flattered! Even if I didn't ever think that tickets could be 'enjoyed'. I've been revamping one of my plugins that relies heavily on quick/bulk edit and have come to realize that those areas need some love... particularly more hooks/filters for developers. Unfortunately, I don't know the first thing about backbone so I don't know that I'd be much use there.

Pertaining to this issue... so are you saying that admin hooks/triggers will not be added in favor of a possible, eventual overhaul? It seems a shame to lose out on some hooks while that maybe happens.

All that said, my digging did eventually bring me to the revelation that bulk edit is processed by a loop that hits wp_insert_post() so actually the ability to save bulk edit details doesn't require ajax at all and can run on the exact same save_post routine that quick edit and meta boxes already use.

#4 @chriscct7
4 years ago

  • Keywords needs-patch added

@Mte90
3 years ago

#5 @Mte90
3 years ago

  • Keywords dev-feedback needs-docs added; needs-patch removed

The patch is very simple, contain the hook with a little bit of documentation (that require a feedback) in the bulk_edit_posts() function.

#6 @Mte90
3 years ago

  • Keywords has-patch added

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


20 months ago

#8 @afercia
20 months ago

  • Keywords needs-patch needs-refresh added; has-patch removed

28112.diff the docblock needs some coding standards.

#9 @SergeyBiryukov
20 months ago

  • Milestone changed from Awaiting Review to 5.0

#10 @afercia
20 months ago

  • Keywords has-patch added; needs-patch removed

@mrasharirfan
12 months ago

I have applied WordPress coding standards to the patch.

#11 @SergeyBiryukov
12 months ago

  • Milestone changed from 5.0 to 5.0.1

#12 @desrosj
11 months ago

  • Keywords needs-docs needs-refresh removed
  • Milestone changed from 5.0.1 to 5.0.2

With the plan for 5.0.1 to be a 2-week quick release in mind, I am going to punt this to 5.0.2.

28112.2.diff is still applying cleanly for me to trunk, but a new patch will be needed if this will be committed directly to the 5.0 branch.

#13 @pento
10 months ago

  • Milestone changed from 5.0.2 to 5.0.3

@itowhid06
10 months ago

Updated @since to reflect actual version the hook is introduce

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


10 months ago

#15 @desrosj
10 months ago

  • Milestone changed from 5.0.3 to 5.1

Going to punt this to 5.1. It is outside of the scope for 5.0.3 (block
editor bugs, regressions, and major bugs).

#16 @pento
10 months ago

  • Owner set to pento
  • Status changed from new to assigned

#17 follow-up: @pento
10 months ago

  • Milestone changed from 5.1 to Future Release
  • Owner pento deleted

I'm not entirely sure what the bulk_edit_posts action is supposed to do. It's passed $post_data, which changes for each post, but it happens outside of the post loop, so it's only called once with the data from the last post edited.

#18 in reply to: ↑ 17 ; follow-up: @mensmaximus
7 months ago

Replying to pento:

I'm not entirely sure what the bulk_edit_posts action is supposed to do. It's passed $post_data, which changes for each post, but it happens outside of the post loop, so it's only called once with the data from the last post edited.

As far as I understand @helgatheviking wants to save additional data added to the bulk edit meta box by avoiding an ajax call. Assuming this to be the case the patch provided won't work for that purpose as @pento already mentioned.

Imho such a hook is not necessary at all because there are three action hooks available to further manipulate a post after it got updated: edit_post_{$post->post_type}, edit_post and post_updated

#19 in reply to: ↑ 18 @mensmaximus
7 months ago

Replying to mensmaximus:

Imho such a hook is not necessary at all because there are three action hooks available to further manipulate a post after it got updated: edit_post_{$post->post_type}, edit_post and post_updated

I did some testing and found none of these action hooks can be utilized to save custom data from bulk edit because $_POST is empty if wp_insert_post() gets invoked by bulk_edit_posts().

To save custom data from bulk edit you can use the filter hook wp_insert_post_data. It passes $postarr as second argument containing all values from $_POST.

Last edited 7 months ago by mensmaximus (previous) (diff)
Note: See TracTickets for help on using tickets.