Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.

Commit c5f618a

Browse files
committed
tests + respect for spacing convention
1 parent 142fb5e commit c5f618a

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

lib/class-wp-json-posts.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ protected function check_read_permission( $post ) {
423423
}
424424

425425
//In case we are dealing with custom post status, check if it's public
426-
$post_status_obj = get_post_status_object($post['post_status']);
427-
if ($post_status_obj->public){
426+
$post_status_obj = get_post_status_object( $post['post_status'] );
427+
if ( $post_status_obj->public ){
428428
return true;
429429
}
430430

tests/test-json-posts.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,5 +666,62 @@ function test_edit_post_sticky_false() {
666666

667667
$this->assertFalse( is_sticky( $this->post_id ) );
668668
}
669+
670+
671+
function test_check_read_permission() {
672+
$publicstatusargs = array(
673+
'label' => _x( 'testpublicstatus', 'Status General Name', 'wp-api' ),
674+
'label_count' => _n_noop( 'Testpublicstatus (%s)', 'Testpublicstatuses (%s)', 'wp-api' ),
675+
'public' => true,
676+
'show_in_admin_all_list' => true,
677+
'show_in_admin_status_list' => true,
678+
'exclude_from_search' => false,
679+
);
680+
register_post_status( 'testpublicstatus', $publicstatusargs );
681+
682+
$privatestatusargs = array(
683+
'label' => _x( 'testprivatestatus', 'Status General Name', 'wp-api' ),
684+
'label_count' => _n_noop( 'Testprivatestatus (%s)', 'Testprivatestatuses (%s)', 'wp-api' ),
685+
'public' => false,
686+
'show_in_admin_all_list' => true,
687+
'show_in_admin_status_list' => true,
688+
'exclude_from_search' => false,
689+
);
690+
register_post_status( 'testprivatestatus', $privatestatusargs );
691+
692+
$publiccustom_args = array(
693+
'post_content' => 'this one is with a public status',
694+
'post_name' => 'publicstatus-post',
695+
'post_title' => 'Post with a custom public status',
696+
'post_status' => 'testpublicstatus'
697+
);
698+
699+
$privatecustom_args = array(
700+
'post_content' => 'this one is with a private status',
701+
'post_name' => 'privatestatus-post',
702+
'post_title' => 'Post with a custom private status',
703+
'post_status' => 'testprivatestatus'
704+
);
705+
706+
$publish_args = array(
707+
'post_content' => 'this one is with a publish status',
708+
'post_name' => 'publish-post',
709+
'post_title' => 'Post with publish status',
710+
'post_status' => 'publish'
711+
);
712+
713+
$publiccustom_pid = wp_insert_post( $publiccustom_args );
714+
$privatecustom_pid = wp_insert_post( $privatecustom_args );
715+
$publish_pid = wp_insert_post( $publish_args );
716+
717+
$pub_cust_post = get_post( $publiccustom_pid, ARRAY_A );
718+
$priv_cust_post = get_post( $privatecustom_pid, ARRAY_A );
719+
$pub_post = get_post( $publish_pid, ARRAY_A );
720+
721+
$this->assertTrue($pub_cust_post);
722+
$this->assertFalse($priv_cust_post);
723+
$this->assertTrue($pub_post);
724+
}
725+
669726

670727
}

0 commit comments

Comments
 (0)