Skip to content

Commit 0019ed7

Browse files
authored
Merge pull request #459 from pfefferle/458-php-fatal-error-uncaught-typeerror-cannot-access-offset-of-type-string
fix fatal error
2 parents 8299a62 + 837570d commit 0019ed7

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

includes/Handler/class-mf2.php

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,20 @@ public function find_representative_item( $mf_array, $target ) {
427427
}
428428
// Make sure this is a numeric array before checking this.
429429
if ( wp_is_numeric_array( $obj_values ) ) {
430+
$obj_value = current( $obj_values );
430431
// check content for the link
431-
if ( 'content' === $obj_key &&
432-
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $obj_values[0]['html'], $context ) ) {
432+
if (
433+
'content' === $obj_key &&
434+
! empty( $obj_value['html'] ) &&
435+
is_string( $obj_value['html'] ) &&
436+
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $obj_value['html'], $context )
437+
) {
433438
return $item;
434-
} elseif ( 'summary' === $obj_key &&
435-
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $obj_values[0], $context ) ) {
439+
} elseif (
440+
'summary' === $obj_key &&
441+
is_string( $obj_value ) &&
442+
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $obj_value, $context )
443+
) {
436444
return $item;
437445
}
438446
}
@@ -444,13 +452,23 @@ public function find_representative_item( $mf_array, $target ) {
444452

445453
// check properties if target urls was mentioned
446454
foreach ( $item['properties'] as $key => $values ) {
447-
// check content for the link
448-
if ( 'content' === $key &&
449-
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $values[0]['html'], $context ) ) {
450-
return $item;
451-
} elseif ( 'summary' === $key &&
452-
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $values[0], $context ) ) {
453-
return $item;
455+
if ( wp_is_numeric_array( $values ) ) {
456+
$value = current( $values );
457+
// check content for the link
458+
if (
459+
'content' === $key &&
460+
! empty( $value['html'] ) &&
461+
is_string( $value['html'] ) &&
462+
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $value['html'], $context )
463+
) {
464+
return $item;
465+
} elseif (
466+
'summary' === $key &&
467+
is_string( $value ) &&
468+
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $value, $context )
469+
) {
470+
return $item;
471+
}
454472
}
455473
}
456474
}

0 commit comments

Comments
 (0)