Home › Forums › Support › Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array
- This topic has 5 replies, 3 voices, and was last updated 2 years, 3 months ago by Tom.
-
AuthorPosts
-
January 3, 2022 at 4:52 pm #2068203vast
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
January 3, 2022 at 7:08 pm #2068262ElvinStaffCustomer SupportHi 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.January 3, 2022 at 7:14 pm #2068266vastHi 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.
January 3, 2022 at 8:40 pm #2068307TomLead DeveloperLead DeveloperYou 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!
January 4, 2022 at 10:41 am #2069099vastThanks Tom.
January 4, 2022 at 8:51 pm #2069484TomLead DeveloperLead DeveloperNo problem!
-
AuthorPosts
- You must be logged in to reply to this topic.