diff --git a/includes/admin/feedzy-rss-feeds-admin.php b/includes/admin/feedzy-rss-feeds-admin.php index 91c6d77a..ce55b9fa 100644 --- a/includes/admin/feedzy-rss-feeds-admin.php +++ b/includes/admin/feedzy-rss-feeds-admin.php @@ -266,6 +266,7 @@ public function register_post_type() { $supports = array( 'title', ); + $capability = feedzy_current_user_can(); $args = array( 'labels' => $labels, 'supports' => $supports, @@ -280,6 +281,15 @@ public function register_post_type() { 'show_in_rest' => true, 'rest_base' => 'feedzy_categories', 'rest_controller_class' => 'WP_REST_Posts_Controller', + 'map_meta_cap' => true, + 'capabilities' => array( + 'publish_posts' => $capability, + 'edit_posts' => $capability, + 'edit_others_posts' => $capability, + 'delete_posts' => $capability, + 'delete_others_posts' => $capability, + 'read_private_posts' => $capability, + ), ); $args = apply_filters( 'feedzy_post_type_args', $args ); register_post_type( 'feedzy_categories', $args ); diff --git a/phpunit.xml b/phpunit.xml index 44f0fdb6..f177514f 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,7 +7,7 @@ convertWarningsToExceptions="true" > - + ./tests/ diff --git a/tests/test-post-access.php b/tests/test-post-access.php new file mode 100644 index 00000000..15fc1532 --- /dev/null +++ b/tests/test-post-access.php @@ -0,0 +1,65 @@ +get_rand_name(); + $admin_id = $this->factory->user->create( + array( + 'role' => 'administrator', + ) + ); + wp_set_current_user( $admin_id ); + $p = $this->factory->post->create_and_get( + array( + 'post_title' => $random_name, + 'post_type' => 'feedzy_categories', + 'post_author' => $admin_id, + ) + ); + do_action( 'save_post', $p->ID, $p ); + $this->assertEquals( $p->post_title, $random_name ); + $this->assertEquals( $p->post_type, 'feedzy_categories' ); + + $this->assertTrue( feedzy_current_user_can() ); + $this->assertTrue( current_user_can( 'edit_post', $p->ID ) ); + + + $contributor_id = $this->factory->user->create( + array( + 'role' => 'contributor', + ) + ); + wp_set_current_user( $contributor_id ); + + $this->assertFalse( feedzy_current_user_can() ); + $this->assertFalse( current_user_can( 'edit_post', $p->ID ) ); + + } + +}