Notice: These forums are now retired and closed. For active support, please Submit a Ticket or visit our official WordPress.org community pages.
Kadence Theme | Kadence Blocks | Starter Templates | WooCommerce Email Designer | Ascend | Virtue | Pinnacle

PHP Fatal error: function get_cart_contents_count() on null

Home / Forums / Virtue Theme / PHP Fatal error: function get_cart_contents_count() on null

This topic is: Not a support question
[Not a support question]
Posted in: Virtue Theme
December 21, 2020 at 9:50 pm

Hi,

every few weeks I see this in our website logs:

[22-Dec-2020 00:11:22 UTC] PHP Fatal error: Uncaught Error: Call to a member function get_cart_contents_count() on null in /srv/data/web/vhosts/www.mysite.com/htdocs/wp-content/themes/virtue_premium/lib/custom.php:239
Stack trace:
#0 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/class-wp-hook.php(287): kt_add_search_form_to_menu('<li class=" me...', Object(stdClass))
#1 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/plugin.php(206): WP_Hook->apply_filters('<li class=" me...', Array)
#2 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/nav-menu-template.php(259): apply_filters('wp_nav_menu_ite...', '<li class=" me...', Object(stdClass))
#3 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-content/themes/virtue_premium/templates/header-style-three.php(84): wp_nav_menu(Object(stdClass))
#4 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/template.php(732): require('/srv/data/web/v...')
#5 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/template.php(676): load_template('/srv in /srv/data/web/vhosts/www.mysite.com/htdocs/wp-content/themes/virtue_premium/lib/custom.php on line 239
[22-Dec-2020 00:11:25 UTC] PHP Fatal error: Uncaught Error: Call to a member function get_cart_contents_count() on null in /srv/data/web/vhosts/www.mysite.com/htdocs/wp-content/themes/virtue_premium/lib/custom.php:239
Stack trace:
#0 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/class-wp-hook.php(287): kt_add_search_form_to_menu('<li class=" me...', Object(stdClass))
#1 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/plugin.php(206): WP_Hook->apply_filters('<li class=" me...', Array)
#2 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/nav-menu-template.php(259): apply_filters('wp_nav_menu_ite...', '<li class=" me...', Object(stdClass))
#3 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-content/themes/virtue_premium/templates/header-style-three.php(84): wp_nav_menu(Object(stdClass))
#4 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/template.php(732): require('/srv/data/web/v...')
#5 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/template.php(676): load_template('/srv in /srv/data/web/vhosts/www.mysite.com/htdocs/wp-content/themes/virtue_premium/lib/custom.php on line 239
[22-Dec-2020 00:11:31 UTC] PHP Fatal error: Uncaught Error: Call to a member function get_cart_contents_count() on null in /srv/data/web/vhosts/www.mysite.com/htdocs/wp-content/themes/virtue_premium/lib/custom.php:239
Stack trace:
#0 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/class-wp-hook.php(287): kt_add_search_form_to_menu('<li class=" me...', Object(stdClass))
#1 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/plugin.php(206): WP_Hook->apply_filters('<li class=" me...', Array)
#2 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/nav-menu-template.php(259): apply_filters('wp_nav_menu_ite...', '<li class=" me...', Object(stdClass))
#3 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-content/themes/virtue_premium/templates/header-style-three.php(84): wp_nav_menu(Object(stdClass))
#4 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/template.php(732): require('/srv/data/web/v...')
#5 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/template.php(676): load_template('/srv in /srv/data/web/vhosts/www.mysite.com/htdocs/wp-content/themes/virtue_premium/lib/custom.php on line 239
[22-Dec-2020 00:11:34 UTC] PHP Fatal error: Uncaught Error: Call to a member function get_cart_contents_count() on null in /srv/data/web/vhosts/www.mysite.com/htdocs/wp-content/themes/virtue_premium/lib/custom.php:239
Stack trace:
#0 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/class-wp-hook.php(287): kt_add_search_form_to_menu('<li class=" me...', Object(stdClass))
#1 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/plugin.php(206): WP_Hook->apply_filters('<li class=" me...', Array)
#2 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/nav-menu-template.php(259): apply_filters('wp_nav_menu_ite...', '<li class=" me...', Object(stdClass))
#3 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-content/themes/virtue_premium/templates/header-style-three.php(84): wp_nav_menu(Object(stdClass))
#4 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/template.php(732): require('/srv/data/web/v...')
#5 /srv/data/web/vhosts/www.mysite.com/htdocs/wp-includes/template.php(676): load_template('/srv in /srv/data/web/vhosts/www.mysite.com/htdocs/wp-content/themes/virtue_premium/lib/custom.php on line 239

I think these are robots/scripts trying to get into our website via a vulnerability. Just this night 4 more attempts every few seconds.

I do not know what is the problem in custom.php on line 239, but maybe this line could be hardened and add some more checks so that get_cart_contents_count() does not throw an PHP Fatal Error when null is involved. Or better: Instead of checking against null (blocklisting), it would be better to allow only numbers here (allowlisting).

We still use version 4.9.30.

Thank you and have some nice holidays!

  • The forum ‘Virtue Theme’ is closed to new topics and replies.