• Hi, running both Code Snippets and XML Sitemap & Google News plugins together will cause the following error when requesting a public XML sitemap or the sitemap index.

    [28-Jun-2023 17:35:54 UTC] PHP Fatal error: Uncaught TypeError: Code_Snippets\Frontend::enqueue_highlighting(): Argument #1 ($posts) must be of type array, null given, called in wp-includes/class-wp-hook.php on line 310 and defined in wp-content/plugins/code-snippets/php/front-end/class-frontend.php:130
    Stack trace: 
    #0 wp-includes/class-wp-hook.php(310): Code_Snippets\Frontend->enqueue_highlighting() 
    #1 wp-includes/plugin.php(256): WP_Hook->apply_filters() 
    #2 wp-includes/class-wp-query.php(3505): apply_filters_ref_array() 
    #3 wp-includes/class-wp-query.php(3787): WP_Query->get_posts() 
    #4 wp-includes/class-wp.php(663): WP_Query->query() 
    #5 wp-includes/class-wp.php(783): WP->query_posts() 
    #6 wp-includes/functions.php(1334): WP->main() 
    #7 wp-blog-header.php(16): wp() 
    #8 index.php(17): require('/home/hmkc5789/...') 
    #9 {main} thrown in wp-content/plugins/code-snippets/php/front-end/class-frontend.php on line 130

    The XML Sitemap & Google News plugin uses add_filter( 'posts_request', '__return_false' ); to shave off a few DB queries by disabling the (redundant) main query on sitemap requests. But apparently this causes Code Snippets to freak out, expecting an array instead of a null value.

    To reproduce:

    1. Activate Code Snippets
    2. Create a PHP code snippet with add_filter( 'posts_request', '__return_false' ); that only runs on Front-end
    3. Make double sure the snippet is set to front-end only (!!!)
    4. Activate the snippet and visit the front end.

    Expected result: WordPress generated 404 page.

    Result: “Critical error”

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Fatal error caused by front end highlighting’ is closed to new replies.