<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[56043] trunk: Posts, Post Types: Add a `$previous_status` parameter to `wp_trash_post()` related hooks.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/56043">56043</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/56043","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>audrasjb</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2023-06-26 20:55:04 +0000 (Mon, 26 Jun 2023)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Posts, Post Types: Add a `$previous_status` parameter to `wp_trash_post()` related hooks.
This adds a `$previous_status` parameter to the `pre_trash_post`, `wp_trash_post`, and `trashed_post` hooks.
Props mujuonly, mukesh27, nihar007, dhruvishah2203, SergeyBiryukov, costdev, hugod, audrasjb, oglekler.
Fixes <a href="https://core.trac.wordpress.org/ticket/58392">#58392</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludespostphp">trunk/src/wp-includes/post.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunktestsphpunittestspostwpTrashPostphp">trunk/tests/phpunit/tests/post/wpTrashPost.php</a></li>
<li><a href="#trunktestsphpunittestspostwpUntrashPostphp">trunk/tests/phpunit/tests/post/wpUntrashPost.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludespostphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/post.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/post.php 2023-06-26 19:55:28 UTC (rev 56042)
+++ trunk/src/wp-includes/post.php 2023-06-26 20:55:04 UTC (rev 56043)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3576,15 +3576,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $previous_status = $post->post_status;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters whether a post trashing should take place.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.9.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.3.0 Added the `$previous_status` parameter.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param bool|null $trash Whether to go forward with trashing.
- * @param WP_Post $post Post object.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param bool|null $trash Whether to go forward with trashing.
+ * @param WP_Post $post Post object.
+ * @param string $previous_status The status of the post about to be trashed.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $check = apply_filters( 'pre_trash_post', null, $post );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $check = apply_filters( 'pre_trash_post', null, $post, $previous_status );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( null !== $check ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $check;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3594,12 +3598,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Fires before a post is sent to the Trash.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.3.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.3.0 Added the `$previous_status` parameter.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int $post_id Post ID.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int $post_id Post ID.
+ * @param string $previous_status The status of the post about to be trashed.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- do_action( 'wp_trash_post', $post_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ do_action( 'wp_trash_post', $post_id, $previous_status );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- add_post_meta( $post_id, '_wp_trash_meta_status', $post->post_status );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ add_post_meta( $post_id, '_wp_trash_meta_status', $previous_status );
</ins><span class="cx" style="display: block; padding: 0 10px"> add_post_meta( $post_id, '_wp_trash_meta_time', time() );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $post_updated = wp_update_post(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3619,10 +3625,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Fires after a post is sent to the Trash.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.9.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 6.3.0 Added the `$previous_status` parameter.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int $post_id Post ID.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int $post_id Post ID.
+ * @param string $previous_status The status of the post at the point where it was trashed.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- do_action( 'trashed_post', $post_id );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ do_action( 'trashed_post', $post_id, $previous_status );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $post;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3656,7 +3664,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Filters whether a post untrashing should take place.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.9.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 5.6.0 The `$previous_status` parameter was added.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 5.6.0 Added the `$previous_status` parameter.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param bool|null $untrash Whether to go forward with untrashing.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_Post $post Post object.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3671,7 +3679,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Fires before a post is restored from the Trash.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.9.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 5.6.0 The `$previous_status` parameter was added.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 5.6.0 Added the `$previous_status` parameter.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $post_id Post ID.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $previous_status The status of the post at the point where it was trashed.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3717,7 +3725,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Fires after a post is restored from the Trash.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.9.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 5.6.0 The `$previous_status` parameter was added.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 5.6.0 Added the `$previous_status` parameter.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param int $post_id Post ID.
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $previous_status The status of the post at the point where it was trashed.
</span></span></pre></div>
<a id="trunktestsphpunittestspostwpTrashPostphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/post/wpTrashPost.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/wpTrashPost.php (rev 0)
+++ trunk/tests/phpunit/tests/post/wpTrashPost.php 2023-06-26 20:55:04 UTC (rev 56043)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,129 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group post
+ *
+ * @covers ::wp_trash_post
+ */
+class Tests_Post_WpTrashPost extends WP_UnitTestCase {
+ /**
+ * @var WP_Post
+ */
+ protected $post;
+
+ public function set_up() {
+ parent::set_up();
+
+ $this->post = $this->factory()->post->create_and_get(
+ array(
+ 'post_status' => 'draft',
+ )
+ );
+ }
+
+ /**
+ * Tests that wp_trash_post() returns a WP_Post object
+ * and sets the correct post meta to trash a post.
+ *
+ * @ticket 58392
+ *
+ * @covers ::wp_trash_post
+ */
+ public function test_trash_post() {
+ $result = wp_trash_post( $this->post->ID );
+
+ $this->assertInstanceOf( 'WP_Post', $result, 'wp_trash_post returned value should be an instance of WP_Post.' );
+
+ $trashed = get_posts(
+ array(
+ 'post_status' => 'trash',
+ 'fields' => 'ids',
+ )
+ );
+
+ $this->assertContains( $this->post->ID, $trashed, 'The post should be trashed.' );
+
+ $trashed_post_metas = get_post_meta( $this->post->ID );
+
+ $this->assertArrayHasKey( '_wp_trash_meta_status', $trashed_post_metas, 'Trashed post should have _wp_trash_meta_status meta set.' );
+ $this->assertCount( 1, $trashed_post_metas['_wp_trash_meta_status'], 'Trashed post should have only one _wp_trash_meta_status meta set.' );
+ $this->assertSame( $this->post->post_status, reset( $trashed_post_metas['_wp_trash_meta_status'] ), 'Trashed post should have _wp_trash_meta_status meta set to previous post status.' );
+ $this->assertArrayHasKey( '_wp_trash_meta_time', $trashed_post_metas, 'Trashed post should have _wp_trash_meta_time meta set.' );
+ $this->assertCount( 1, $trashed_post_metas['_wp_trash_meta_time'], 'Trashed post should have only one _wp_trash_meta_time meta set.' );
+ }
+
+ /**
+ * Tests that wp_trash_post() applies 'pre_trash_post' filters
+ * and passes the expected values to callbacks.
+ *
+ * @ticket 58392
+ *
+ * @covers ::wp_trash_post
+ */
+ public function test_pre_trash_post_hook() {
+ add_filter(
+ 'pre_trash_post',
+ function ( $trash, $post, $previous_status ) {
+ $this->assertNull( $trash, 'pre_trash_post first parameter should be null.' );
+ $this->assertSame( $this->post->ID, $post->ID, 'pre_trash_post second parameter should be the trashed post ID.' );
+ $this->assertSame( $this->post->post_status, $previous_status, 'pre_trash_post third parameter should be the previous trashed post status.' );
+
+ return $trash;
+ },
+ 10,
+ 3
+ );
+
+ wp_trash_post( $this->post->ID );
+
+ $this->assertGreaterThan( 0, did_filter( 'pre_trash_post' ), 'pre_trash_post filter was not called.' );
+ }
+
+ /**
+ * Tests that wp_trash_post() triggers the 'wp_trash_post' action
+ * and passes the expected values to callbacks.
+ *
+ * @ticket 58392
+ *
+ * @covers ::wp_trash_post
+ */
+ public function test_wp_trash_post_hook() {
+ add_action(
+ 'wp_trash_post',
+ function ( $post_id, $previous_status ) {
+ $this->assertSame( $this->post->ID, $post_id, 'wp_trash_post first parameter should be the trashed post ID.' );
+ $this->assertSame( $this->post->post_status, $previous_status, 'wp_trash_post second parameter should be the previous trashed post status.' );
+ },
+ 10,
+ 2
+ );
+
+ wp_trash_post( $this->post->ID );
+
+ $this->assertGreaterThan( 0, did_action( 'wp_trash_post' ), 'wp_trash_post action was not called.' );
+ }
+
+ /**
+ * Tests that wp_trash_post() triggers the 'trashed_post' action
+ * and passes the expected values to callbacks.
+ *
+ * @ticket 58392
+ *
+ * @covers ::wp_trash_post
+ */
+ public function test_trashed_post_hook() {
+ add_action(
+ 'trashed_post',
+ function ( $post_id, $previous_status ) {
+ $this->assertSame( $this->post->ID, $post_id, 'trashed_post first parameter should be the trashed post ID.' );
+ $this->assertSame( $this->post->post_status, $previous_status, 'trashed_post second parameter should be the previous trashed post status.' );
+ },
+ 10,
+ 2
+ );
+
+ wp_trash_post( $this->post->ID );
+
+ $this->assertGreaterThan( 0, did_action( 'trashed_post' ), 'trashed_post action was not called.' );
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/post/wpTrashPost.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunktestsphpunittestspostwpUntrashPostphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/post/wpUntrashPost.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/wpUntrashPost.php (rev 0)
+++ trunk/tests/phpunit/tests/post/wpUntrashPost.php 2023-06-26 20:55:04 UTC (rev 56043)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,132 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/**
+ * @group post
+ *
+ * @covers ::wp_untrash_post
+ */
+class Tests_Post_WpUntrashPost extends WP_UnitTestCase {
+ /**
+ * @var WP_Post
+ */
+ protected $trashed_post;
+
+ public function set_up() {
+ parent::set_up();
+
+ $this->trashed_post = wp_trash_post(
+ $this->factory()->post->create(
+ array(
+ 'post_status' => 'draft',
+ )
+ )
+ );
+ }
+
+ /**
+ * Tests that wp_untrash_post() returns a WP_Post object,
+ * removes post meta for an untrashed post and sets it to a 'Draft'.
+ *
+ * @ticket 58392
+ *
+ * @covers ::wp_untrash_post
+ */
+ public function test_untrash_post() {
+ $result = wp_untrash_post( $this->trashed_post->ID );
+
+ $this->assertInstanceOf( 'WP_Post', $result, 'wp_untrash_post returned value should be an instance of WP_Post.' );
+
+ $trashed = get_posts(
+ array(
+ 'post_status' => 'trash',
+ 'fields' => 'ids',
+ )
+ );
+
+ $this->assertNotContains( $this->trashed_post->ID, $trashed, 'Untrashed post should not belong to trashed posts anymore.' );
+
+ $untrashed_post_metas = get_post_meta( $this->trashed_post->ID );
+
+ $this->assertArrayNotHasKey( '_wp_trash_meta_status', $untrashed_post_metas, 'Untrashed post should not have _wp_trash_meta_status meta anymore.' );
+ $this->assertArrayNotHasKey( '_wp_trash_meta_time', $untrashed_post_metas, 'Untrashed post should not have _wp_trash_meta_time meta anymore.' );
+
+ $post = get_post( $this->trashed_post->ID );
+
+ $this->assertSame( 'draft', $post->post_status, 'Untrashed post should have its previous status set correctly.' );
+ }
+
+ /**
+ * Tests that wp_untrash_post() applies 'pre_untrash_post' filters
+ * and passes the expected values to callbacks.
+ *
+ * @ticket 58392
+ *
+ * @covers ::wp_untrash_post
+ */
+ public function test_pre_untrash_post_hook() {
+ add_filter(
+ 'pre_untrash_post',
+ function ( $trash, $post, $previous_status ) {
+ $this->assertNull( $trash, 'pre_untrash_post first parameter should be null.' );
+ $this->assertSame( $this->trashed_post->ID, $post->ID, 'pre_untrash_post second parameter should be the trashed post ID.' );
+ $this->assertSame( $this->trashed_post->post_status, $previous_status, 'pre_untrash_post third parameter should be the previous trashed post status.' );
+
+ return $trash;
+ },
+ 10,
+ 3
+ );
+
+ wp_untrash_post( $this->trashed_post->ID );
+
+ $this->assertGreaterThan( 0, did_filter( 'pre_untrash_post' ), 'pre_untrash_post filter was not called.' );
+ }
+
+ /**
+ * Tests that wp_untrash_post() triggers the 'untrash_post' action
+ * and passes the expected values to callbacks.
+ *
+ * @ticket 58392
+ *
+ * @covers ::wp_untrash_post
+ */
+ public function test_untrash_post_hook() {
+ add_action(
+ 'untrash_post',
+ function ( $post_id, $previous_status ) {
+ $this->assertSame( $this->trashed_post->ID, $post_id, 'untrash_post first parameter should be the trashed post ID.' );
+ $this->assertSame( $this->trashed_post->post_status, $previous_status, 'untrash_post second parameter should be the previous trashed post status.' );
+ },
+ 10,
+ 2
+ );
+
+ wp_untrash_post( $this->trashed_post->ID );
+
+ $this->assertGreaterThan( 0, did_action( 'untrash_post' ), 'untrash_post action was not called.' );
+ }
+
+ /**
+ * Tests that wp_untrash_post() triggers the 'untrashed_post' action
+ * and passes the expected values to callbacks.
+ *
+ * @ticket 58392
+ *
+ * @covers ::wp_untrash_post
+ */
+ public function test_untrashed_post_hook() {
+ add_action(
+ 'untrashed_post',
+ function ( $post_id, $previous_status ) {
+ $this->assertSame( $this->trashed_post->ID, $post_id, 'untrashed_post first parameter should be the trashed post ID.' );
+ $this->assertSame( $this->trashed_post->post_status, $previous_status, 'untrashed_post second parameter should be the previous trashed post status.' );
+ },
+ 10,
+ 2
+ );
+
+ wp_untrash_post( $this->trashed_post->ID );
+
+ $this->assertGreaterThan( 0, did_action( 'untrashed_post' ), 'untrashed_post action was not called.' );
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/post/wpUntrashPost.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span></div>
</body>
</html>