Prevent fatal error if NULL is provided in array_search under Jetpack Stats (#50696)
* Avoid potential fatal error if $fields is not an array * Changelog * Prevent fatals when $data['general'] is not an object. * PHPCS
This commit is contained in:
parent
9fa6c20a24
commit
bb532b7a6f
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Prevent fatal error if NULL is provided in array_search under Jetpack Stats
|
|
@ -527,8 +527,13 @@ class Controller extends GenericController {
|
|||
*/
|
||||
public function format_data_value( $data, $stat, $report, $chart, $query_args ) {
|
||||
if ( 'jetpack/stats' === $report ) {
|
||||
$index = false;
|
||||
|
||||
// Get the index of the field to tally.
|
||||
$index = array_search( $chart, $data['general']->visits->fields, true );
|
||||
if ( isset( $data['general']->visits->fields ) && is_array( $data['general']->visits->fields ) ) {
|
||||
$index = array_search( $chart, $data['general']->visits->fields, true );
|
||||
}
|
||||
|
||||
if ( ! $index ) {
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue