revert to last healthy

This commit is contained in:
IGNY8 VPS (Salman)
2026-01-10 06:48:16 +00:00
parent 9e785f141c
commit be2c190eca
8 changed files with 142 additions and 242 deletions

View File

@@ -208,8 +208,6 @@ function igny8_parse_keywords($keywords) {
* @return array Array of badges with 'text' and 'type' keys
*/
function igny8_get_section_badges($heading, $post_id) {
static $used_keywords = [];
$badges = [];
$heading_lower = strtolower($heading);
@@ -219,44 +217,39 @@ function igny8_get_section_badges($heading, $post_id) {
$primary_kw = get_post_meta($post_id, '_igny8_primary_keyword', true);
$secondary_kws = get_post_meta($post_id, '_igny8_secondary_keywords', true);
// Priority 1: Primary keyword (if not used)
if ($primary_kw && !in_array(strtolower($primary_kw), $used_keywords) && stripos($heading_lower, strtolower($primary_kw)) !== false) {
// Priority 1: Primary keyword
if ($primary_kw && stripos($heading_lower, strtolower($primary_kw)) !== false) {
$badges[] = ['text' => $primary_kw, 'type' => 'primary'];
$used_keywords[] = strtolower($primary_kw);
return $badges; // Return only 1 badge
}
// Priority 2: Tags (if not used)
if ($tags && !is_wp_error($tags)) {
// Priority 2: Tags
if ($tags && !is_wp_error($tags) && count($badges) < 2) {
foreach ($tags as $tag) {
if (!in_array(strtolower($tag->name), $used_keywords) && stripos($heading_lower, strtolower($tag->name)) !== false) {
if (stripos($heading_lower, strtolower($tag->name)) !== false) {
$badges[] = ['text' => $tag->name, 'type' => 'tag'];
$used_keywords[] = strtolower($tag->name);
return $badges; // Return only 1 badge
if (count($badges) >= 2) break;
}
}
}
// Priority 3: Categories (if not used)
if ($categories && !is_wp_error($categories)) {
// Priority 3: Categories
if ($categories && !is_wp_error($categories) && count($badges) < 2) {
foreach ($categories as $cat) {
if (!in_array(strtolower($cat->name), $used_keywords) && stripos($heading_lower, strtolower($cat->name)) !== false) {
if (stripos($heading_lower, strtolower($cat->name)) !== false) {
$badges[] = ['text' => $cat->name, 'type' => 'category'];
$used_keywords[] = strtolower($cat->name);
return $badges; // Return only 1 badge
if (count($badges) >= 2) break;
}
}
}
// Priority 4: Secondary keywords (if not used)
if ($secondary_kws) {
// Priority 4: Secondary keywords
if ($secondary_kws && count($badges) < 2) {
$kw_array = is_array($secondary_kws) ? $secondary_kws : explode(',', $secondary_kws);
foreach ($kw_array as $kw) {
$kw = trim($kw);
if (!empty($kw) && !in_array(strtolower($kw), $used_keywords) && stripos($heading_lower, strtolower($kw)) !== false) {
if (!empty($kw) && stripos($heading_lower, strtolower($kw)) !== false) {
$badges[] = ['text' => $kw, 'type' => 'keyword'];
$used_keywords[] = strtolower($kw);
return $badges; // Return only 1 badge
if (count($badges) >= 2) break;
}
}
}