Merge pull request #682 from tainacan/feature/673

fix: get public item of the private collection using internal API
This commit is contained in:
Vinícius Nunes Medeiros 2022-03-09 18:21:19 -03:00 committed by GitHub
commit d0d4d96364
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 3 deletions

View File

@ -343,7 +343,11 @@ class Collections extends Repository {
$existing_post = get_post( $args );
if ( $existing_post instanceof \WP_Post ) {
try {
return new Entities\Collection( $existing_post );
$col = new Entities\Collection( $existing_post );
if ( $col->can_read() ) {
return $col;
}
return [];
} catch (\Exception $e) {
return [];
}

View File

@ -252,7 +252,12 @@ class Items extends Repository {
$existing_post = get_post( $args );
if ( $existing_post instanceof \WP_Post ) {
try {
return new Entities\Item( $existing_post );
$item = new Entities\Item( $existing_post );
$collection = $item->get_collection();
if (isset($collection) && $collection->can_read()) {
return $item;
}
return [];
} catch (\Exception $e) {
return [];
}

View File

@ -725,7 +725,10 @@ abstract class Repository {
$entity_cap = $entity->get_capabilities();
if ( ! isset( $entity_cap->read ) ) {
if ( $entity->get_post_type() === false ) { // Allow read of not post entities
$prefix = Entities\Collection::$db_identifier_prefix;
$sufix = Entities\Collection::$db_identifier_sufix;
$is_a_item = preg_match('/^'. $prefix . '[0-9]*' . $sufix . '$/i', $entity->WP_Post->post_type);
if ( $entity->get_post_type() === false && !$is_a_item) { // Allow read of not post entities
return true;
}