


private function allowed_term_ids($age) {

$s = $this->settings();

$allowed = [];




foreach ($s['term_ages'] as $id => $min_age) {

if ((int) $min_age <= (int) $age) {

$allowed[] = (int) $id;

}

}




return $allowed;

}




public function filter_queries($query) {




if (

(is_admin() && !(defined('DOING_AJAX') && DOING_AJAX))

|| !($query instanceof WP_Query)

|| !$this->read_age()

) {

return;

}




$s = $this->settings();




if (

empty($s['taxonomy'])

|| empty($s['post_types'])

|| empty($s['term_ages'])

) {

return;

}




$pt = $query->get('post_type');




if ($pt === 'any') {

$pt = $s['post_types'];

$query->set('post_type', $pt);

} elseif (empty($pt)) {

if (!$query->is_main_query()) {

return;

}

$pt = ['post'];

}




$pts = (array) $pt;




if (!array_intersect($pts, $s['post_types'])) {

return;

}




$age = (int) $this->read_age();

$allowed = [];

$blocked = [];

$mapped_ids = [];




foreach ($s['term_ages'] as $term_id => $min_age) {

$term_id = (int) $term_id;

$min_age = (int) $min_age;




$mapped_ids[] = $term_id;




if ($min_age <= $age) {

$allowed[] = $term_id;

} else {

$blocked[] = $term_id;

}

}




if (!empty($s['block_unrated'])) {

$all_terms = get_terms([

'taxonomy' => $s['taxonomy'],

'hide_empty' => false,

'fields' => 'ids'

]);




if (!is_wp_error($all_terms)) {

$unmapped = array_diff(

array_map('intval', $all_terms),

$mapped_ids

);




$blocked = array_merge($blocked, $unmapped);

}

}




if (empty($allowed) && !empty($s['block_unrated'])) {

$query->set('post__in', [0]);

return;

}




$age_tax_query = [

'relation' => 'AND'

];




if (!empty($allowed)) {

$age_tax_query[] = [

'taxonomy' => $s['taxonomy'],

'field' => 'term_id',

'terms' => $allowed,

'operator' => 'IN'

];

}




if (!empty($blocked)) {

$age_tax_query[] = [

'taxonomy' => $s['taxonomy'],

'field' => 'term_id',

'terms' => array_values(array_unique($blocked)),

'operator' => 'NOT IN'

];

}




$existing_tax_query = $query->get('tax_query');




if (!empty($existing_tax_query)) {

$final_tax_query = [

'relation' => 'AND',

$existing_tax_query,

$age_tax_query

];

} else {

$final_tax_query = $age_tax_query;

}




$query->set('tax_query', $final_tax_query);

}


<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://mowjenow.ir/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://mowjenow.ir/wp-sitemap-posts-post-1.xml</loc></sitemap><sitemap><loc>https://mowjenow.ir/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://mowjenow.ir/wp-sitemap-posts-blog-1.xml</loc></sitemap><sitemap><loc>https://mowjenow.ir/wp-sitemap-taxonomies-category-1.xml</loc></sitemap><sitemap><loc>https://mowjenow.ir/wp-sitemap-taxonomies-post_tag-1.xml</loc></sitemap><sitemap><loc>https://mowjenow.ir/wp-sitemap-taxonomies-actor-1.xml</loc></sitemap><sitemap><loc>https://mowjenow.ir/wp-sitemap-taxonomies-actor-2.xml</loc></sitemap><sitemap><loc>https://mowjenow.ir/wp-sitemap-taxonomies-actor-3.xml</loc></sitemap><sitemap><loc>https://mowjenow.ir/wp-sitemap-taxonomies-actor-4.xml</loc></sitemap><sitemap><loc>https://mowjenow.ir/wp-sitemap-taxonomies-actor-5.xml</loc></sitemap><sitemap><loc>https://mowjenow.ir/wp-sitemap-taxonomies-director-1.xml</loc></sitemap><sitemap><loc>https://mowjenow.ir/wp-sitemap-taxonomies-genre-1.xml</loc></sitemap><sitemap><loc>https://mowjenow.ir/wp-sitemap-taxonomies-type_of_post-1.xml</loc></sitemap><sitemap><loc>https://mowjenow.ir/wp-sitemap-taxonomies-yearr-1.xml</loc></sitemap><sitemap><loc>https://mowjenow.ir/wp-sitemap-taxonomies-country-1.xml</loc></sitemap><sitemap><loc>https://mowjenow.ir/wp-sitemap-taxonomies-rate-1.xml</loc></sitemap><sitemap><loc>https://mowjenow.ir/wp-sitemap-taxonomies-blog_category-1.xml</loc></sitemap><sitemap><loc>https://mowjenow.ir/wp-sitemap-users-1.xml</loc></sitemap></sitemapindex>
