mirror of
https://github.com/10h30/genesis-simple-sidebars.git
synced 2026-06-05 15:08:34 +09:00
[GF-3978] fix: stop corrupt sidebar data from causing errors (#56)
* fix: stop corrupt sidebar data from causing errors By filtering out sidebars without a name in get_sidebars. The name is a required field when entering new sidebars, so sidebars missing a name are likely corrupt. Designed to address "Cannot access offset of type string on string" when trying to access $sidebar['name'] for sidebars without a name. See https://wordpress.org/support/topic/php-8-2-error-6/. * chore: formatting
This commit is contained in:
@@ -15,7 +15,7 @@ class Genesis_Simple_Sidebars_Core {
|
|||||||
/**
|
/**
|
||||||
* The created sidebars.
|
* The created sidebars.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $sidebars;
|
private $sidebars;
|
||||||
|
|
||||||
@@ -161,13 +161,23 @@ class Genesis_Simple_Sidebars_Core {
|
|||||||
*/
|
*/
|
||||||
public function get_sidebars( $cache = true ) {
|
public function get_sidebars( $cache = true ) {
|
||||||
|
|
||||||
if ( ! $cache ) {
|
if ( $cache && ! is_null( $this->sidebars ) ) {
|
||||||
return stripslashes_deep( get_option( Genesis_Simple_Sidebars()->settings_field ) );
|
return $this->sidebars;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_null( $this->sidebars ) ) {
|
$sidebars = stripslashes_deep( get_option( Genesis_Simple_Sidebars()->settings_field ) );
|
||||||
$this->sidebars = stripslashes_deep( get_option( Genesis_Simple_Sidebars()->settings_field ) );
|
|
||||||
}
|
/**
|
||||||
|
* Sidebars without a name are invalid. Filtering these prevents
|
||||||
|
* corrupted sidebar data from throwing errors, as seen in:
|
||||||
|
* https://wordpress.org/support/topic/php-8-2-error-6/#post-17472734
|
||||||
|
*/
|
||||||
|
$this->sidebars = array_filter(
|
||||||
|
(array) $sidebars,
|
||||||
|
function( $sidebar ) {
|
||||||
|
return isset( $sidebar['name'] );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return $this->sidebars;
|
return $this->sidebars;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user