[wp-trac] [WordPress Trac] #60038: Pass original array of arguments to hooks that fire within `wp_insert_post()`

WordPress Trac noreply at wordpress.org
Tue Feb 13 11:50:27 UTC 2024


#60038: Pass original array of arguments to hooks that fire within
`wp_insert_post()`
----------------------------------------+-----------------------------
 Reporter:  johnbillion                 |       Owner:  (none)
     Type:  enhancement                 |      Status:  new
 Priority:  normal                      |   Milestone:  Future Release
Component:  Posts, Post Types           |     Version:
 Severity:  normal                      |  Resolution:
 Keywords:  good-first-bug needs-patch  |     Focuses:
----------------------------------------+-----------------------------

Comment (by orufovyjosoq1976):

 To address the issue where the original array of arguments is not passed
 to hooks that fire within `wp_insert_post()`, you can modify the core
 WordPress functionality to ensure that the original `$postarr` array is
 passed to these hooks.

 Here's how you can do it:

 1. **Identify Affected Hooks**: Review the actions and filters listed
 where the original `$postarr` array should be passed.

 2. **Modify Core WordPress Functionality**: You'll need to locate the
 `wp_insert_post()` function in WordPress core (usually found in `wp-
 includes/post.php`). Within this function, find the hooks mentioned and
 modify them to pass the original `$postarr` array or both `$postarr` and
 `$unsanitized_postarr`.

 3. **Update Documentation**: Make sure to update the documentation
 comments for these hooks to reflect the changes made, explaining that the
 original `$postarr` array is now passed.

 Here's an example of how you might modify one of the hooks
 (`wp_insert_post`):

 ```php
 /**
  * Inserts or updates a post.
  *
  * @since 2.5.0
  *
  * @param int|WP_Error $post_id The post ID on success. WP_Error on
 failure.
  * @param WP_Post      $post    WP_Post object for the post.
  * @param bool         $update  Whether this is an existing post being
 updated.
  * @param array        $postarr Array of sanitized (and unsanitized) post
 data.
  */
 do_action( 'wp_insert_post', $post_id, $post, $update, $postarr );
 ```

 Modify it to include `$postarr`:

 ```php
 do_action( 'wp_insert_post', $post_id, $post, $update, $postarr,
 $unsanitized_postarr );
 ```

 By making these modifications, you ensure that hooks within
 `wp_insert_post()` have access to the original `$postarr` array, providing
 valuable context for plugin or theme developers to perform custom logic
 based on the original input data.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60038#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list