警告:尝试访问第 43 行 /mytheme/functions.php 中 bool 类型值的数组偏移量
Warning: Trying to access array offset on value of type bool in /mytheme/functions.php on line 43
Warning: Trying to access array offset on value of type bool in /mytheme/functions.php on line 43
// Add woocommerce support
$start_extended_woo = get_option( 'swp_woo' );
if( $start_extended_woo[0] == 'Enable' ){
add_theme_support( 'woocommerce' );
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
add_action( 'init', 'woo_remove_wc_breadcrumbs' );
function woo_remove_wc_breadcrumbs() {
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
}
}
我在将 php 从 7.4 升级到 php 8.0 后遇到此错误知道如何解决这个问题吗?
我用的是Start Wp Theme,可惜3年没更新了
根据documentation get_option()
returns false
如果找不到选项。您的选择可能不再存在。为了保持“安全”更改为
if( is_array($start_extended) && $start_extended_woo[0] == 'Enable' ){
这将防止您引用的确切错误。
另一种方法是将 get_option()
调用更改为:
$start_extended_woo = get_option( 'swp_woo' , ['Disabled'] );
这将 return 假定与您的调用相反。
或者,在数据库中为 swp_woo
添加一个选项,无需更改任何代码。
Warning: Trying to access array offset on value of type bool in /mytheme/functions.php on line 43
// Add woocommerce support
$start_extended_woo = get_option( 'swp_woo' );
if( $start_extended_woo[0] == 'Enable' ){
add_theme_support( 'woocommerce' );
add_theme_support( 'wc-product-gallery-zoom' );
add_theme_support( 'wc-product-gallery-lightbox' );
add_theme_support( 'wc-product-gallery-slider' );
add_action( 'init', 'woo_remove_wc_breadcrumbs' );
function woo_remove_wc_breadcrumbs() {
remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 );
}
}
我在将 php 从 7.4 升级到 php 8.0 后遇到此错误知道如何解决这个问题吗?
我用的是Start Wp Theme,可惜3年没更新了
根据documentation get_option()
returns false
如果找不到选项。您的选择可能不再存在。为了保持“安全”更改为
if( is_array($start_extended) && $start_extended_woo[0] == 'Enable' ){
这将防止您引用的确切错误。
另一种方法是将 get_option()
调用更改为:
$start_extended_woo = get_option( 'swp_woo' , ['Disabled'] );
这将 return 假定与您的调用相反。
或者,在数据库中为 swp_woo
添加一个选项,无需更改任何代码。