Remove extra deprecations in PHP 8.1

In our website we’ve found a few extra deprecation warning generated from Blocksy’s code.

Probably they depend a lot on our customizations and other installed plugins. This is the patch we’ve developed to fix them:

diff --git a/inc/classes/screen-manager.php b/inc/classes/screen-manager.php
index 7197a0909..00c6481a0 100644
--- a/inc/classes/screen-manager.php
+++ b/inc/classes/screen-manager.php
@@ -42,10 +42,10 @@ class Blocksy_Screen_Manager {
 		}
 
 		$result = strpos(
-			$current_template,
+			$current_template ?? '',
 			WC()->plugin_path() . '/templates/'
 		) !== false || strpos(
-			$current_template,
+			$current_template ?? '',
 			get_template_directory()
 		) !== false;
 
diff --git a/inc/components/hero-section.php b/inc/components/hero-section.php
index 8c8c06b93..3e18067b5 100644
--- a/inc/components/hero-section.php
+++ b/inc/components/hero-section.php
@@ -38,7 +38,7 @@ if (! function_exists('blocksy_get_page_title_source')) {
 			return $result;
 		}
 
-		if (strpos($prefix, 'single') !== false || (
+		if (strpos($prefix ?? '', 'single') !== false || (
 			function_exists('is_shop') && is_shop()
 		) && ! is_search()) {
 			$post_options = blocksy_get_post_options();
diff --git a/inc/sidebar.php b/inc/sidebar.php
index 0f4b1d248..20e411c88 100644
--- a/inc/sidebar.php
+++ b/inc/sidebar.php
@@ -182,7 +182,7 @@ if (! function_exists('blocksy_sidebar_position_unfiltered')) {
 		]);
 
 		if (
-			strpos($prefix, '_archive') !== false
+			strpos($prefix ?? '', '_archive') !== false
 			||
 			$prefix === 'search'
 			||
@@ -220,7 +220,7 @@ if (! function_exists('blocksy_sidebar_position_unfiltered')) {
 			&&
 			$prefix !== 'product'
 			&&
-			strpos($prefix, '_single') === false
+			strpos($prefix ?? '', '_single') === false
 			&&
 			(
 				$prefix !== 'courses_archive'

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer