Skip to content

Commit 8801591

Browse files
committed
Post connector updated to account for "new" status
1 parent c1622e9 commit 8801591

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

connectors/class-connector-posts.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ public function callback_transition_post_status( $new, $old, $post ) {
170170
return;
171171
}
172172

173-
if ( in_array( $new, array( 'auto-draft', 'inherit' ), true ) ) {
173+
$start_statuses = array( 'auto-draft', 'inherit', 'new' );
174+
if ( in_array( $new, $start_statuses, true ) ) {
174175
return;
175176
} elseif ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
176177
return;
@@ -196,7 +197,7 @@ public function callback_transition_post_status( $new, $old, $post ) {
196197
'1: Post title, 2: Post type singular name',
197198
'stream'
198199
);
199-
} elseif ( 'publish' === $new && 'draft' === $old ) {
200+
} elseif ( 'publish' === $new && ! in_array( $old, array( 'future', 'publish' ), true ) ) {
200201
/* translators: %1$s: a post title, %2$s: a post type singular name (e.g. "Hello World", "Post") */
201202
$summary = _x(
202203
'"%1$s" %2$s published',
@@ -255,7 +256,7 @@ public function callback_transition_post_status( $new, $old, $post ) {
255256
);
256257
}
257258

258-
if ( 'auto-draft' === $old && 'auto-draft' !== $new ) {
259+
if ( in_array( $old, $start_statuses, true ) && ! in_array( $new, $start_statuses, true ) ) {
259260
$action = 'created';
260261
}
261262

tests/tests/connectors/test-class-connector-posts.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function test_callback_transition_post_status() {
5656
);
5757

5858
// Set expected calls for the Mock.
59-
$this->mock->expects( $this->exactly( 11 ) )
59+
$this->mock->expects( $this->exactly( 12 ) )
6060
->method( 'log' )
6161
->withConsecutive(
6262
array(
@@ -80,7 +80,7 @@ function( $subject ) {
8080
),
8181
$this->greaterThan( 0 ),
8282
$this->equalTo( 'post' ),
83-
$this->equalTo( 'updated' ),
83+
$this->equalTo( 'created' ),
8484
),
8585
array(
8686
$this->equalTo(
@@ -311,7 +311,30 @@ function( $subject ) {
311311
$this->greaterThan( 0 ),
312312
$this->equalTo( 'post' ),
313313
$this->equalTo( 'updated' ),
314-
)
314+
),
315+
array(
316+
$this->equalTo(
317+
_x(
318+
'"%1$s" %2$s published',
319+
'1: Post title, 2: Post type singular name',
320+
'stream'
321+
)
322+
),
323+
$this->callback(
324+
function( $subject ) {
325+
$expected = array(
326+
'post_title' => 'Test post',
327+
'singular_name' => 'post',
328+
'new_status' => 'publish',
329+
'old_status' => 'new',
330+
);
331+
return $expected === array_intersect_key( $expected, $subject );
332+
}
333+
),
334+
$this->greaterThan( 0 ),
335+
$this->equalTo( 'post' ),
336+
$this->equalTo( 'created' ),
337+
),
315338
);
316339

317340
// Create post/update post status trigger callbacks.
@@ -383,6 +406,15 @@ function( $subject ) {
383406
)
384407
);
385408

409+
// Expected log to be made with "created" action.
410+
wp_insert_post(
411+
array(
412+
'post_title' => 'Test post',
413+
'post_content' => 'Lorem ipsum dolor...',
414+
'post_status' => 'publish',
415+
)
416+
);
417+
386418
/**
387419
* Expected log to not be called for newly published attachment
388420
* because it's an excluded post type.

0 commit comments

Comments
 (0)