tengo este problema

function calcularPuntosIntereses($post_id, $datos)
{
    $puntosIntereses = 0;
    $datosAlgoritmo = !empty($datos['datosAlgoritmo'][$post_id]->meta_value) ? json_decode($datos['datosAlgoritmo'][$post_id]->meta_value, true) : [];
    $oneshot = ['one shot', 'one-shot', 'oneshot'];
    $esOneShot = false;

    foreach ($oneshot as $palabra) {
        if (stripos($datos['datosAlgoritmo'][$post_id]->meta_value, $palabra) !== false) {
            $esOneShot = true;
            break;
        }
    }

    foreach ($datosAlgoritmo as $key => $value) {
        if (is_array($value)) {
            foreach (['es', 'en'] as $lang) {
                if (isset($value[$lang]) && is_array($value[$lang])) {
                    foreach ($value[$lang] as $item) {
                        if (isset($datos['interesesUsuario'][$item])) {
                            $puntosIntereses += 10 + $datos['interesesUsuario'][$item]->intensity;
                        }
                    }
                }
            }
        } elseif (!empty($value) && isset($datos['interesesUsuario'][$value])) {
            $puntosIntereses += 10 + $datos['interesesUsuario'][$value]->intensity;
        }
    }

    if ($esOneShot) {
        $puntosIntereses *= 0.2;
    }

    return $puntosIntereses;
}
/*
[05-Nov-2024 09:22:07 UTC] PHP Warning:  Attempt to read property "meta_value" on null in /var/www/wordpress/wp-content/themes/2upra3v/app/Algoritm/algoritmoPosts.php on line 304
[05-Nov-2024 09:22:07 UTC] PHP Deprecated:  stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /var/www/wordpress/wp-content/themes/2upra3v/app/Algoritm/algoritmoPosts.php on line 304
[05-Nov-2024 09:22:07 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function configurarSimilarTo() in /var/www/wordpress/wp-content/themes/2upra3v/app/Logic/manejadorPosts.php:137
Stack trace:
#0 /var/www/wordpress/wp-content/themes/2upra3v/app/Logic/manejadorPosts.php(17): configuracionQueryArgs()
#1 /var/www/wordpress/wp-content/themes/2upra3v/single-social_post.php(141): publicaciones()
#2 /var/www/wordpress/wp-includes/template-loader.php(106): include('...')
#3 /var/www/wordpress/wp-blog-header.php(19): require_once('...')
#4 /var/www/wordpress/index.php(17): require('...')
#5 {main}
  thrown in /var/www/wordpress/wp-content/themes/2upra3v/app/Logic/manejadorPosts.php on line 137
[05-Nov-2024 09:22:08 UTC] PHP Warning:  foreach() argument must be of type array|object, null given in /var/www/wordpress/wp-admin/includes/plugin.php on line 1853


*/


function calcularPuntosPost($post_id, $post_data, $datos, $esAdmin, $vistas_posts_processed, $identifier = '', $similar_to = null)
{
    $autor_id = $post_data->post_author;
    $post_date = $post_data->post_date;

    $puntosUsuario = in_array($autor_id, $datos['siguiendo']) ? 20 : 0;
    $puntosIntereses = calcularPuntosIntereses($post_id, $datos);

    // Calculate points based on identifier matches
    $puntosIdentifier = 0;
    if (!empty($identifier)) {
        $puntosIdentifier = calcularPuntosIdentifier($post_id, $identifier, $datos);
    }

    // Calculate points based on similarity to the specified post
    $puntosSimilarTo = 0;
    if (!empty($similar_to)) {
        $puntosSimilarTo = calcularPuntosSimilarTo($post_id, $similar_to, $datos);
    }

    $likes = isset($datos['likes_by_post'][$post_id]) ? $datos['likes_by_post'][$post_id] : 0;
    $puntosLikes = 30 + $likes;

    $diasDesdePublicacion = (current_time('timestamp') - strtotime($post_date)) / (3600 * 24);
    $factorTiempo = pow(0.99, $diasDesdePublicacion);

    $metaVerificado = isset($datos['verificado_results'][$post_id]->meta_value) && $datos['verificado_results'][$post_id]->meta_value == '1';
    $metaPostAut = isset($datos['postAut_results'][$post_id]->meta_value) && $datos['postAut_results'][$post_id]->meta_value == '1';

    $puntosFinal = calcularPuntosFinales(
        $puntosUsuario,
        $puntosIntereses + $puntosIdentifier + $puntosSimilarTo,
        $puntosLikes,
        $metaVerificado,
        $metaPostAut,
        $esAdmin
    );

    if (isset($vistas_posts_processed[$post_id])) {
        $vistas = $vistas_posts_processed[$post_id]['count'];
        $reduccion_por_vista = 0.50;
        $factorReduccion = pow(1 - $reduccion_por_vista, $vistas);
        $puntosFinal *= $factorReduccion;
    }

    $aleatoriedad = mt_rand(0, 20);
    $puntosFinal = $puntosFinal * (1 + ($aleatoriedad / 100));
    $ajusteExtra = mt_rand(-50, 50);
    $puntosFinal = $puntosFinal * $factorTiempo;
    $puntosFinal += $ajusteExtra;

    return max($puntosFinal, 0);
}


function calcularPuntosIdentifier($post_id, $identifier, $datos)
{
    // Get datosAlgoritmo for the post
    $datosAlgoritmo = !empty($datos['datosAlgoritmo'][$post_id]->meta_value)
        ? json_decode($datos['datosAlgoritmo'][$post_id]->meta_value, true)
        : [];

    // Normalize identifier(s)
    if (is_array($identifier)) {
        $identifiers = $identifier;
    } else {
        $identifiers = preg_split('/\s+/', strtolower($identifier), -1, PREG_SPLIT_NO_EMPTY);
    }

    $count = 0;

    // Now go through datosAlgoritmo and count matches
    foreach ($datosAlgoritmo as $key => $value) {
        if (is_array($value)) {
            foreach (['es', 'en'] as $lang) {
                if (isset($value[$lang]) && is_array($value[$lang])) {
                    foreach ($value[$lang] as $item) {
                        $item_normalized = strtolower($item);
                        foreach ($identifiers as $id_word) {
                            if ($item_normalized == $id_word) {
                                $count += 1;
                            }
                        }
                    }
                }
            }
        } elseif (!empty($value)) {
            $value_normalized = strtolower($value);
            foreach ($identifiers as $id_word) {
                if ($value_normalized == $id_word) {
                    $count += 1;
                }
            }
        }
    }

    // Assign points based on occurrences
    $puntosIdentifier = $count * 50; // For example, 50 points per occurrence

    return $puntosIdentifier;
}

function calcularPuntosSimilarTo($post_id, $similar_to, $datos)
{
    // Get datosAlgoritmo for the current post
    $datosAlgoritmo_1 = !empty($datos['datosAlgoritmo'][$post_id]->meta_value)
        ? json_decode($datos['datosAlgoritmo'][$post_id]->meta_value, true)
        : [];

    // Get datosAlgoritmo for the post to compare with
    if (isset($datos['datosAlgoritmo'][$similar_to])) {
        $datosAlgoritmo_2 = json_decode($datos['datosAlgoritmo'][$similar_to]->meta_value, true);
    } else {
        // Fetch datosAlgoritmo for 'similar_to' post if not already in $datos
        $datosAlgoritmo_meta = get_post_meta($similar_to, 'datosAlgoritmo', true);
        $datosAlgoritmo_2 = !empty($datosAlgoritmo_meta) ? json_decode($datosAlgoritmo_meta, true) : [];
    }

    // Convert datosAlgoritmo to flat arrays of words
    $words_in_post_1 = extractWordsFromDatosAlgoritmo($datosAlgoritmo_1);
    $words_in_post_2 = extractWordsFromDatosAlgoritmo($datosAlgoritmo_2);

    if (empty($words_in_post_1) || empty($words_in_post_2)) {
        return 0;
    }

    // Compute similarity as the Jaccard index
    $set1 = array_unique($words_in_post_1);
    $set2 = array_unique($words_in_post_2);

    $intersection = array_intersect($set1, $set2);
    $union = array_unique(array_merge($set1, $set2));

    $similarity = count($intersection) / count($union);

    // Assign points based on similarity
    $puntosSimilarTo = $similarity * 100; // Scale to 0-100 points

    return $puntosSimilarTo;
}

function extractWordsFromDatosAlgoritmo($datosAlgoritmo)
{
    $words = [];

    foreach ($datosAlgoritmo as $key => $value) {
        if (is_array($value)) {
            foreach (['es', 'en'] as $lang) {
                if (isset($value[$lang]) && is_array($value[$lang])) {
                    foreach ($value[$lang] as $item) {
                        $item_normalized = strtolower($item);
                        $words[] = $item_normalized;
                    }
                }
            }
        } elseif (!empty($value)) {
            $value_normalized = strtolower($value);
            $words[] = $value_normalized;
        }
    }
    return $words;
}