HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: /var/www/kevin-demo/wp-content/plugins/allspice/includes/seo.php
<?php
// seo.php
if (!defined('ABSPATH')) exit;

function allspice_seo_should_inject_metadesc(): bool {
    if (!function_exists('allspice_buttons_cache_get')) return false;
    $buttons = allspice_buttons_cache_get();
    if (!is_array($buttons) || empty($buttons)) return false;
    foreach ($buttons as $b) {
        if (!is_array($b)) continue;
        $id = isset($b['id']) ? (string)$b['id'] : '';
        if ($id !== 'WIDCON-y17r' && $id !== 'WIDCON-u34j') continue;
        $opts = $b['options'] ?? null;
        if (!is_array($opts)) return false;
        return !empty($opts['inject_meta_description']);
    }
    return false;
}

function allspice_seo_get_valid_metadesc_for_current_page(): string {
    if (!function_exists('allspice_is_recipe_page') || !allspice_is_recipe_page()) return '';
    if (!function_exists('allspice_current_url_key')) return '';
    $uk = allspice_current_url_key();
    if (!is_string($uk) || $uk === '') return '';
    if (!function_exists('allspice_recipes_get_overview_by_url_key')) return '';
    $row = allspice_recipes_get_overview_by_url_key($uk);
    if (!is_array($row)) return '';
    $desc = isset($row['meta_description']) ? trim((string)$row['meta_description']) : '';
    if ($desc === '') return '';
    if (!array_key_exists('meta_description_valid', $row)) return '';
    if ($row['meta_description_valid'] !== true) return '';
    return $desc;
}

function allspice_seo_should_run_now(): bool {
    if (!is_singular()) return false;
    if (!allspice_seo_should_inject_metadesc()) return false;
    return true;
}

add_filter('wpseo_metadesc', function ($desc) {
    if (is_admin()) return $desc;
    if (!allspice_seo_should_run_now()) return $desc;
    $d = allspice_seo_get_valid_metadesc_for_current_page();
    return ($d !== '') ? $d : $desc;
}, 999);

add_filter('wpseo_opengraph_desc', function ($og_desc) {
    if (is_admin()) return $og_desc;
    if (!allspice_seo_should_run_now()) return $og_desc;
    $d = allspice_seo_get_valid_metadesc_for_current_page();
    return ($d !== '') ? $d : $og_desc;
}, 999);

add_filter('wpseo_twitter_description', function ($tw_desc) {
    if (is_admin()) return $tw_desc;
    if (!allspice_seo_should_run_now()) return $tw_desc;
    $d = allspice_seo_get_valid_metadesc_for_current_page();
    return ($d !== '') ? $d : $tw_desc;
}, 999);