StManozz
StManozz

Reputation: 1

Warning: implode(): Invalid arguments passed in functions.php on line 674

i tried to go online after finishing the website but a error occurs Warning: implode(): Invalid arguments passed in functions.php on line 674

foreach ( $one_array_font as $font => $variants ) {
    $font = str_replace(' ', '+', $font);
    $variants = implode(',', array_values($variants['variant']) );
    $all_final_fonts[] = $font.':'.$variants;
}

$gfont = implode('|', $all_final_fonts); /* <-- This line fails */

wp_enqueue_style( 'zn_all_g_fonts', '//fonts.googleapis.com/css?family='.$gfont.''.$subset);

if ( $data['zn_main_style'] == 'dark' ) {
    wp_enqueue_style('zn-dark-style', get_template_directory_uri() . '/css/dark-theme.css',array() ,false,'all');
}

if ( !empty ( $data['g_fonts_subset'] ) ) {
   $subset = '&subset='.str_replace( ' ' , '' , $data['g_fonts_subset']);
}

Upvotes: 0

Views: 11658

Answers (2)

Spudley
Spudley

Reputation: 168655

Not really enough info in the question, but this is what I think is happening:

  • Firstly, $one_array_font is empty.

  • This means that the foreach() loop is never run.

  • This means that the line $all_final_fonts[] = $font.':'.$variants; is never run.

  • I'm guessing that $all_final_fonts was not defined earlier. Therefore it is still undefined when the code gets to the implode.

  • The implode() fails because it requires the input field to be an array, but you've given it an undefined variable.

Solution

Ensure that $all_final_fonts is defined regardless, by adding the following line before the foreach() loop:

$all_final_fonts = array();

This will initialise the variable as an array, so that implode() won't complain about it if you don't have any data.

Hope that helps.

Upvotes: 2

Rijndael
Rijndael

Reputation: 3753

You are seeing that warning because $all_final_fonts is not an array.

See http://php.net/manual/en/function.implode.php

regards

Upvotes: 0

Related Questions