Make WordPress Core

Opened 11 months ago

Last modified 6 weeks ago

#60038 reviewing enhancement

Pass original array of arguments to hooks that fire within `wp_insert_post()`

Reported by: johnbillion's profile johnbillion Owned by: johnbillion's profile johnbillion
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: good-first-bug has-patch changes-requested
Focuses: Cc:

Description

The $postarr value passed to the wp_insert_post() function contains context that can be useful to callbacks attached to the actions that fire within this function, but this value isn't passed to any of them. Strangely enough it is passed to most of the filters there.

As an example, a plugin of mine needs to perform logic within a callback on the wp_insert_post action based on a mixture of the tax_input argument and a custom argument. The wp_insert_post_data filter needs to be used to access these values.

The $postarr value gets copied to $unsanitized_postarr. This is the value that should be passed to the actions because it contains the original input array, rather than $postarr which includes defaults and sanitised values. Or both should be passed, as per the filters in the function.

This affects the following actions:

  • pre_post_update
  • edit_attachment
  • attachment_updated
  • add_attachment
  • edit_post_{$post->post_type}
  • edit_post
  • post_updated
  • save_post_{$post->post_type}
  • save_post
  • wp_insert_post

And the following filters:

  • add_trashed_suffix_to_trashed_posts

Attachments (4)

60038.diff (5.9 KB) - added by rizwan_47 11 months ago.
Added $postarr arg to the missing hooks and filter
60038.1.diff (17.6 KB) - added by sukhendu2002 10 months ago.
60038.2.diff (10.0 KB) - added by sukhendu2002 10 months ago.
Patch refreshed
60038.2.2.diff (4.9 KB) - added by marukou1976 9 months ago.
convert to utf-8

Download all attachments as: .zip

Change History (16)

@rizwan_47
11 months ago

Added $postarr arg to the missing hooks and filter

This ticket was mentioned in PR #5747 on WordPress/wordpress-develop by mrhatia.


11 months ago
#1

  • Keywords has-patch added; needs-patch removed

There are some missing arguments in the core i added it and resolve following ticket

Trac ticket: https://core.trac.wordpress.org/ticket/60038

#2 @johnbillion
10 months ago

  • Keywords needs-patch added; has-patch removed
  • Milestone changed from Awaiting Review to Future Release

Thanks for the patch @rizwan_47! But, it doesn't do what I mentioned in the description. The $unsanitized_postarr array needs to be passed, either on its own or along with $postarr. Would you like to take another look?

@sukhendu2002
10 months ago

Patch refreshed

@marukou1976
9 months ago

convert to utf-8

#4 @marukou1976
9 months ago

  • Keywords has-patch added; needs-patch removed

I'm re-uploading [60038.2.diff](https://core.trac.wordpress.org/attachment/ticket/60038/60038.2.2.diff) as it was corrupted. Specifically, it was in UTF-16LE, so I have converted it to UTF-8.

The content itself includes $unsanitized_postarr as an argument, which I believe meets the requirements. I'm also developing a plugin, and I find this to be more convenient.

I've changed the status to has-patch.

Version 0, edited 9 months ago by marukou1976 (next)

#5 @johnbillion
6 months ago

  • Milestone changed from Future Release to 6.6
  • Owner set to johnbillion
  • Status changed from new to reviewing

#6 @oglekler
6 months ago

@johnbillion, we have 1 week before Beta 1. Can you review the patch, please? It looks simple enought, but I am wondering if actions inside wp_publish_post() function should have the same properties for consistency.

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


5 months ago

#8 @oglekler
5 months ago

@johnbillion we have just a few days before Beta 1, so, place move this forward or to the next milestone. Thank you!

#9 @oglekler
5 months ago

  • Keywords dev-feedback added
  • Milestone changed from 6.6 to 6.7

We have 2 days before Beta 1, so I am moving it into the next milestone. 

And I hope to get an opinion about if actions inside wp_publish_post() function should have the same properties for consistency.

#10 @johnbillion
5 months ago

  • Keywords changes-requested added; dev-feedback removed

This patch needs more work because the affected filters and actions also fire in other places in core, not just within the wp_insert_post() function.

This ticket was mentioned in Slack in #core-test by ankit-k-gupta. View the logs.


8 weeks ago

@khoipro commented on PR #5747:


8 weeks ago
#12

Could you @mrhatia finish a coding standard before reviewing this issue again?

#13 @davidbaumwald
6 weeks ago

  • Milestone changed from 6.7 to Future Release

With 6.7 Beta 1 releasing in a few hours, this is being moved to Future Release given a lack of recent momentum towards a resolution.

@johnbillion If you or any other committer feels the remaining work can be resolved in time for Beta 1 or any other specific milestone and wishes to assume ownership during that cycle, feel free to update the milestone accordingly.

Note: See TracTickets for help on using tickets.