• I was trying to solve an unrelated problem but couldn’t find any logs for it due to the high volume of PHP warnings that array_merge expects the first parameter to be an array.

    I tracked down the function where the error was taking place and this is my fix.

    If it turns out that args['class'] exists but isn’t an array, make it into an array.

    function sempress_pre_get_avatar_data( $args, $id_or_email ) {
    	if ( ! isset( $args['class'] ) ) {
    		$args['class'] = array();
    	}
        if( ! is_array($args['class'])){
            $args['class'] = array($args['class']);
        }
    	// Adds a class for microformats v2
    	$args['class'] = array_unique( array_merge( $args['class'], array( 'u-photo' ) ) );
    	$args['extra_attr'] = 'itemprop="image"';
    
    	return $args;
    }
  • The topic ‘Edge case: array expected in sempress_pre_get_avatar_data’ is closed to new replies.