get_site_suffix(); $args = wp_parse_args( $args, array( 'site' => $site_suffix ) ); $source_key = 'source'; if ( 0 === strpos( $source, 'https://' ) ) { $source_key = 'url'; $source_url = \wp_parse_url( $source ); // discard any query and fragments. $source = 'https://' . $source_url['host'] . ( isset( $source_url['path'] ) ? $source_url['path'] : '' ); } $to_be_added = array( $source_key => rawurlencode( $source ), ); foreach ( $args as $arg_name => $arg_value ) { if ( empty( $arg_value ) ) { continue; } $to_be_added[ $arg_name ] = rawurlencode( $arg_value ); } if ( ! empty( $to_be_added ) ) { $url = add_query_arg( $to_be_added, $url ); } return $url; } }