• Grzegorz.Janoszka

    (@grzegorzjanoszka)


    My error log is showing:

    *344808 FastCGI sent in stderr: “PHP message: PHP Fatal error: Uncaught Error: Call to undefined function switch_to_blog() in /www/site.pl/ext/relevanssi/lib/excerpts-highlights.php:1605
    Stack trace:

    0 /www/site.pl/ext/relevanssi/lib/search.php(699): relevanssi_add_excerpt()

    1 /www/site.pl/ext/relevanssi/lib/search.php(88): relevanssi_do_query()

    2 /www/site.pl/wp-includes/class-wp-hook.php(308): relevanssi_query()

    3 /www/site.pl/wp-includes/plugin.php(256): WP_Hook->apply_filters()

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Can you provide more context for when this happens? switch_to_blog() is only defined in multisite context, but that line should only run when a post has a defined blog ID, which only happens in multisite. Is this a multisite installation?

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    Hi, it is a singlesite installation and it has always been. I was not doing anything with the website, not clicking any admin things. I have just noticed it in the logs.
    Maybe it is good to check if the function exists as the actual verification whether it is a multisite?

    Plugin Author Mikko Saari

    (@msaari)

    Well, it’s already doing that: it’s checking for $post->blog_id, which Relevanssi only sets in multisite context.

    Is this just a random single error message, or are there lots of these? Can you figure out what the user has been doing to trigger this?

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    It happens several times a day at different hours. Seems quite random.
    The query is the search, like “GET /?s=Chleb HTTP/2.0”.

    And indeed – I have just noticed that the search is totally broken. When you search for anything, you get a critical error message. Just browsed all the logs and the earliest entry I see is dated on 31st Mar 2023. Does this relate to one of the release dates?

    Plugin Author Mikko Saari

    (@msaari)

    Version 4.18.4 was released at the end of March. It was a minor update that added one filter hook and disabled Relevanssi searches in RSS feeds.

    Have you tried disabling other plugins? If something else sets the $post->blog_id attribute, that would break Relevanssi on a single-site installation. Relevanssi doesn’t do it unless it’s a multisite search, but something else can set it, and it would break Relevanssi.

    I’ll throw in function_exists() checks in Relevanssi to avoid this in the future, but that’ll be in the next version. Meanwhile, figuring out what sets the blog id in the posts would help fix this.

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    I have disabled all the other plugins and the issue remains. If I search for something that doesn’t exist, I get a normal page saying that it wasn’t found. When I search for something that exists, I get critical error.

    I did:
    function relevanssi_add_excerpt( &$post, $query ) {
    if ( isset( $post->blog_id ) && function_exists( 'switch_to_blog' ) ) {
    switch_to_blog( $post->blog_id );
    }

    and the same around restore_current_blog and it seems it helped. I would appreciate such entries in the next update, but no rush with it.
    No idea what is wrong with my site.

    Thank you for your help.

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    And btw – how do I modify what is displayed when nothing is found? I would like to add some text with links but I am unable to find where I can do that.

    Thread Starter Grzegorz.Janoszka

    (@grzegorzjanoszka)

    Ah, I think I found it. Two plugins didn’t get disabled (I think I misclicked – instead clicking twice deactivate, I deactivated and activated one of them) and one of them has a code:

               $blog_id          = get_current_blog_id();
    

    It is the top-10 plugin (https://wordpress.org/plugins/top-10/) and I guess it is the culprit.
    Anyway, appreciate the double check in future versions.

    Plugin Author Mikko Saari

    (@msaari)

    Nope, that’s not the one… that’s normal variable use, and doesn’t touch the post objects Relevanssi sees.

    But yeah, future versions will not have this problem, I’ve guaranteed that.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Call to undefined function switch_to_blog()’ is closed to new replies.