wp 1.3.0
This commit is contained in:
@@ -129,6 +129,28 @@ function igny8_get_featured_image_prompt($post_id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get featured image caption from imported images meta
|
||||
*
|
||||
* @param int $post_id Post ID
|
||||
* @return string|null Image caption or null
|
||||
*/
|
||||
function igny8_get_featured_image_caption($post_id) {
|
||||
$imported_images = get_post_meta($post_id, '_igny8_imported_images', true);
|
||||
|
||||
if (empty($imported_images) || !is_array($imported_images)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($imported_images as $img) {
|
||||
if (isset($img['is_featured']) && $img['is_featured'] && isset($img['caption'])) {
|
||||
return $img['caption'];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format status label for display
|
||||
*
|
||||
@@ -202,12 +224,21 @@ function igny8_parse_keywords($keywords) {
|
||||
|
||||
/**
|
||||
* Get section badges based on keyword/tag matching
|
||||
* Returns only ONE badge per section and tracks used keywords to avoid repeats
|
||||
*
|
||||
* @param string $heading Section heading text
|
||||
* @param int $post_id Post ID
|
||||
* @return array Array of badges with 'text' and 'type' keys
|
||||
* @param array &$used_keywords Reference to array tracking already-used keywords
|
||||
* @return array Array of badges with 'text' and 'type' keys (max 1)
|
||||
*/
|
||||
function igny8_get_section_badges($heading, $post_id) {
|
||||
function igny8_get_section_badges($heading, $post_id, &$used_keywords = null) {
|
||||
// Initialize static variable to track used keywords across calls if not passed
|
||||
static $static_used_keywords = [];
|
||||
|
||||
if ($used_keywords === null) {
|
||||
$used_keywords = &$static_used_keywords;
|
||||
}
|
||||
|
||||
$badges = [];
|
||||
$heading_lower = strtolower($heading);
|
||||
|
||||
@@ -217,39 +248,49 @@ 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 ($primary_kw && stripos($heading_lower, strtolower($primary_kw)) !== false) {
|
||||
$badges[] = ['text' => $primary_kw, 'type' => 'primary'];
|
||||
// Priority 1: Primary keyword (if not already used)
|
||||
if ($primary_kw && !in_array(strtolower($primary_kw), $used_keywords)) {
|
||||
if (stripos($heading_lower, strtolower($primary_kw)) !== false) {
|
||||
$badges[] = ['text' => $primary_kw, 'type' => 'primary'];
|
||||
$used_keywords[] = strtolower($primary_kw);
|
||||
return $badges; // Return only 1
|
||||
}
|
||||
}
|
||||
|
||||
// Priority 2: Tags
|
||||
if ($tags && !is_wp_error($tags) && count($badges) < 2) {
|
||||
// Priority 2: Tags (if not already used)
|
||||
if ($tags && !is_wp_error($tags) && count($badges) < 1) {
|
||||
foreach ($tags as $tag) {
|
||||
if (stripos($heading_lower, strtolower($tag->name)) !== false) {
|
||||
$tag_lower = strtolower($tag->name);
|
||||
if (!in_array($tag_lower, $used_keywords) && stripos($heading_lower, $tag_lower) !== false) {
|
||||
$badges[] = ['text' => $tag->name, 'type' => 'tag'];
|
||||
if (count($badges) >= 2) break;
|
||||
$used_keywords[] = $tag_lower;
|
||||
return $badges; // Return only 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Priority 3: Categories
|
||||
if ($categories && !is_wp_error($categories) && count($badges) < 2) {
|
||||
// Priority 3: Categories (if not already used)
|
||||
if ($categories && !is_wp_error($categories) && count($badges) < 1) {
|
||||
foreach ($categories as $cat) {
|
||||
if (stripos($heading_lower, strtolower($cat->name)) !== false) {
|
||||
$cat_lower = strtolower($cat->name);
|
||||
if (!in_array($cat_lower, $used_keywords) && stripos($heading_lower, $cat_lower) !== false) {
|
||||
$badges[] = ['text' => $cat->name, 'type' => 'category'];
|
||||
if (count($badges) >= 2) break;
|
||||
$used_keywords[] = $cat_lower;
|
||||
return $badges; // Return only 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Priority 4: Secondary keywords
|
||||
if ($secondary_kws && count($badges) < 2) {
|
||||
// Priority 4: Secondary keywords (if not already used)
|
||||
if ($secondary_kws && count($badges) < 1) {
|
||||
$kw_array = is_array($secondary_kws) ? $secondary_kws : explode(',', $secondary_kws);
|
||||
foreach ($kw_array as $kw) {
|
||||
$kw = trim($kw);
|
||||
if (!empty($kw) && stripos($heading_lower, strtolower($kw)) !== false) {
|
||||
$kw_lower = strtolower($kw);
|
||||
if (!empty($kw) && !in_array($kw_lower, $used_keywords) && stripos($heading_lower, $kw_lower) !== false) {
|
||||
$badges[] = ['text' => $kw, 'type' => 'keyword'];
|
||||
if (count($badges) >= 2) break;
|
||||
$used_keywords[] = $kw_lower;
|
||||
return $badges; // Return only 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -257,6 +298,15 @@ function igny8_get_section_badges($heading, $post_id) {
|
||||
return $badges;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the used keywords tracker (call at start of template)
|
||||
*/
|
||||
function igny8_reset_used_keywords() {
|
||||
// Reset the static variable by calling with empty reference
|
||||
$empty = [];
|
||||
igny8_get_section_badges('', 0, $empty);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if section content contains a table
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user