fix: get metadata on private section #184

This commit is contained in:
vnmedeiros 2022-08-09 15:20:28 -03:00
parent 00a9fc0cbb
commit 32c8aea7ff
2 changed files with 22 additions and 2 deletions

View File

@ -464,6 +464,26 @@ class Metadata extends Repository {
$args['meta_query'] = $original_meta_q;
$args['meta_query'][] = $meta_query;
if ($this->get_default_metadata_attribute() != $parent_id) {
$read_private_metasection_cap = "tnc_col_{$parent_id}_read_private_metasection";
if ( !current_user_can($read_private_metasection_cap) ) {
$private_metadata_sections_ids = \tainacan_metadata_sections()->fetch_ids(
array(
'post_status' => get_post_stati( array( 'private' => true ) ),
'meta_query' => array(
'key' => 'collection_id',
'value' => $parent_id,
)
));
$args['meta_query'][] = array(
'key' => 'metadata_section_id',
'value' => $private_metadata_sections_ids,
'compare' => 'NOT IN'
);
}
}
$results = array_merge($results, $this->fetch( $args, 'OBJECT' ));
}

View File

@ -74,8 +74,8 @@ function tainacan_roles() {
/**
* Retrieve the singleton Metadata Repository instance
* @return \Tainacan\Repositories\Metadata The Tainacan Metadata Repository
* Retrieve the singleton Metadata Sections Repository instance
* @return \Tainacan\Repositories\Metadata_Sections The Tainacan Metadata Repository
*/
function tainacan_metadata_sections() {
return \Tainacan\Repositories\Metadata_Sections::get_instance();