• When editing a post (with WP Statistics for this post visible) somehow a lot of PHP Notice are triggered in error log:

    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 255
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 262
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 266
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 270
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 274
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 278
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 282
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 286
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 290
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 294
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 298
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 302
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 306
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 309
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 318
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 318
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 318
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 318
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 318
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 324
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 329
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 333
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 337
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 341
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 345
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 349
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 353
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 357
    [17-Dec-2021 21:45:33 UTC] PHP Notice:  Trying to access array offset on value of type bool in /xx/wp-content/plugins/wp-statistics/includes/class-wp-statistics-widget.php on line 361

    Problem seems to be in file wp-statistics/includes/class-wp-statistics-widget.php which actually seems to create a Statistics widget to “Show site stats in sidebar.”

    Sidenote: We have no Statistics widget in any Design > Widgets > Widget Area present.

    Not sure why the “Outputs the options form on admin” code, which triggers the notices, is even called when editing a post.

    Obviously class-wp-statistics-widget.php line 251 does not return valid options:

    $widget_options = WP_STATISTICS\Option::get('widget');
    

    So line 255 and below fail because there is no array:

    echo esc_attr($widget_options['name_widget']);
    

    Suggested fix:

    Add a check after line 255 similar to the check in line 31 in same file:

    if (!is_array($widget_options)) {
        return;
    }

    or better find the reason why this code is called on post edit screen where it is not used.

    Thanks for the plugin.

    WordPress 5.8.2, WP Statistics 13.1.2

  • The topic ‘PHP Notice: Trying to access array offset on value of type bool …’ is closed to new replies.