UNPKG

@wordpress/api-fetch

Version:
30 lines (24 loc) 643 B
/** * WordPress dependencies */ import { addQueryArgs, hasQueryArg } from '@wordpress/url'; /** * Internal dependencies */ import type { APIFetchMiddleware } from '../types'; const userLocaleMiddleware: APIFetchMiddleware = ( options, next ) => { if ( typeof options.url === 'string' && ! hasQueryArg( options.url, '_locale' ) ) { options.url = addQueryArgs( options.url, { _locale: 'user' } ); } if ( typeof options.path === 'string' && ! hasQueryArg( options.path, '_locale' ) ) { options.path = addQueryArgs( options.path, { _locale: 'user' } ); } return next( options ); }; export default userLocaleMiddleware;