Merge pull request #682 from tainacan/feature/673
fix: get public item of the private collection using internal API
This commit is contained in:
commit
d0d4d96364
|
@ -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 [];
|
||||
}
|
||||
|
|
|
@ -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 [];
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue