插件类中的未定义偏移量'0'

时间:2019-09-26 17:24:12

标签: undefined offset php-7.2

插件代码中未定义的偏移PHP错误。

尝试使用空合并运算符,但这并不能解决。

$fontoptions = array(
    get_option( 'wpfl_s1-heading' ),
    get_option( 'wpfl_s1-body' ),
    get_option( 'wpfl_s1-alt' ),
    get_option( 'wpfl_s1-mono' ),
);

$subsets = array_filter( $fontoptions );

ob_start(); // buffer foreach output.
foreach ( $subsets as &$subset ) {
    $subset .= 'Subset, ';
    echo wp_kses( $subset, $arr );
}

$subsetstrim = ob_get_clean(); // get buffer.
$clean       = rtrim( $subsetstrim, ', ' ); // trim final comma & space.
echo wp_kses( $clean, $arr );

$observer  = 'A';
$observer2 = 'A';

$fam = array();

foreach ( $files as &$file ) {

    $font   = basename( $file, '.woff' ); // remove the file type.
    $font   = str_replace( $suffix, '', $font ); // remove the -webfont suffix.
    $family = explode( '-', $font );
    $fam[]  = $family[0]; // First needle.

}

$results = array_unique( $fam );
$result  = array( $results[0] ) ?? '';  // Undefined offset here
foreach ( $results as &$result ) {
    $obs      = $observer++;
    $observed = 'var font' . $obs . '=new FontFaceObserver(\'' . $result . '\');';
    echo wp_kses( $observed, $arr );

预期没有错误,du!尽管出现错误,该插件仍可正常工作。

PHP Notice: Undefined offset: 0 in /wp-content/plugins/path/to/plugin/includes/class-plugin-head.php on line 324

0 个答案:

没有答案