[Resolved] Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array

Home Forums Support [Resolved] Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array

Home Forums Support Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2068203
    vast

    When checking if the current user is logged in for example, the filter “generate_typography_default_fonts” produces the following below.

    // Set localized custom fonts
    function rk_typography_fonts( $fonts ) {
    if ( is_user_logged_in() ) {
            $fonts[] = 'Pacifico';
            return $fonts;
        }
    }
    add_filter( 'generate_typography_default_fonts', 'rk_typography_fonts' );
    Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, 
     null given in 
     /wp-content/themes/generatepress/inc/typography.php:844 
     Stack trace: 
     #0 
     /wp-content/themes/generatepress/inc/typography.php(844): 
     in_array('System Stack', NULL) 
     #1 
     /wp-content/themes/generatepress/inc/typography.php(64): 
     generate_get_google_font_variants('System Stack', 'font_body') 
     #2 
     /wp-includes/class-wp-hook.php(303): generate_enqueue_google_fonts('') 
     #3 
     /wp-includes/class-wp-hook.php(327): 
     WP_Hook->apply_filters('', Array) 
     #4 
     /wp-includes/plugin.php(470): 
     WP_Hook->do_action(Array) 
     #5
     /wp-includes/script-loader.php(2083): 
     do_action('wp_enqueue_scri...') 
     #6 
     /wp-includes/class-wp-hook.php(303): 
     wp_enqueue_scripts('') 
     #7 
     /wp-includes/class-wp-hook.php(327): 
     WP_Hook->apply_filters(NULL, Array) 
     #8 
     /wp-includes/plugin.php(470): 
     WP_Hook->do_action(Array) 
     #9 
     /wp-includes/general-template.php(3015): 
     do_action('wp_head') 
     #10 
     /wp-content/themes/generatepress/header.php(17): 
     wp_head() 
     #11 
     /wp-includes/template.php(770): 
     require_once('/home/rk...') 
     #12 
     /wp-includes/template.php(716): 
     load_template('/home/rk...', true, Array) 
     #13 
     /wp-includes/general-template.php(48): 
     locate_template(Array, true, true, Array) 
     #14 
     /wp-content/themes/generatepress/index.php(18): 
     get_header() #15 /wp-includes/template-loader.php(106): 
     include('/home/rk...') 
     #16 
     /wp-blog-header.php(19): 
     require_once('/home/rk...') 
     #17 /index.php(17): require('/home/rk...') 
     #18 {main} thrown in
    #2068262
    Elvin
    Staff
    Customer Support

    Hi there,

    Can you share w/ us where you’re getting this error?

    Also, is there any particular reason for adding the condition if ( is_user_logged_in() )? It seems completely unnecessary as the typography settings is automatically assumed for logged in users as it’s a backend thing to set.

    #2068266
    vast

    Hi Elvin,

    It occurs in the WordPress backend. The condition is_user_logged_in() is an example of the error occurring with WordPress’ native function.

    This will be replaced with other custom conditional functions. The test with WordPress’ native function was to rule out issues with the custom function.

    #2068307
    Tom
    Lead Developer
    Lead Developer

    You need to return outside of the condition:

    // Set localized custom fonts
    function rk_typography_fonts( $fonts ) {
        if ( is_user_logged_in() ) {
            $fonts[] = 'Pacifico';
        }
    
        return $fonts;
    }
    add_filter( 'generate_typography_default_fonts', 'rk_typography_fonts' );

    Hope this helps!

    #2069099
    vast

    Thanks Tom.

    #2069484
    Tom
    Lead Developer
    Lead Developer

    No problem!

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.