cache = new CacheManager('feed', WEEK_IN_SECONDS);
add_action('init', [$this, 'registerBlock']);
}
public function registerBlock()
{
register_block_type($this->path, [
'render_callback' => [$this, 'render']
]);
}
protected function buildParams(array $attributes):array
{
if (!jvbCheck('inheritQuery', $attributes)) {
return [
'title' => $attributes['title'],
'content' => $attributes['contentTypes'],
'taxonomies'=> $this->getTaxonomies($attributes['contentTypes'])
];
}
if (isJVBUserType()) {
return $this->buildProfileConfig();
} elseif (isJVBContentTax()) {
return $this->buildShopConfig();
} elseif (is_tax()) {
return $this->buildTaxonomyConfig();
}
return [];
}
protected function buildProfileConfig():array
{
$obj = get_queried_object();
$content = jvbGetUserContentTypes($obj->ID);
return [
'is_gallery' => true,
'content' => $content,
'context' => jvbNoBase($obj->post_type),
'taxonomies' => $this->getTaxonomies($content)
];
}
protected function buildShopConfig():array
{
$type = jvbNoBase(get_queried_object()->taxonomy);
$content = jvbContentTaxContent($type);
$context = [
'content' => $content,
'taxonomies' => $this->getTaxonomies($content),
'context' => $type,
];
unset($context['taxonomies'][array_search($type, $context['taxonomies'])]);
return $context;
}
protected function buildTaxonomyConfig():array
{
$type = jvbNoBase(get_queried_object()->taxonomy);
$content = jvbContentTaxContent($type);
return [
'content' => $content,
'taxonomies' => $this->getTaxonomies($content),
'context' => $type
];
}
protected function getTaxonomies(array $content):array
{
global $jvb_taxonomy_for;
$taxonomies = [];
foreach ($jvb_taxonomy_for as $taxonomy => $for) {
if (array_intersect($for, $content)) {
$taxonomies[] = $taxonomy;
}
}
return $taxonomies;
}
public function render(array $attributes, string $content, WP_Block $block)
{
$this->config = $this->buildParams($attributes);
return $this->cache->remember(
$this->config,
function() {
return $this->renderBlock();
}
);
}
protected function renderBlock():string
{
$work = isJVBUserType() ? ' id="work"' : '';
ob_start();
?>
Try tweaking those filters a bit.
Edmonton\'s got talent - let\'s find it.