How to use the @wordpress/url.addQueryArgs function in @wordpress/url

To help you get started, we’ve selected a few @wordpress/url examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github getblocklab / block-lab / tests / e2e / config / setup-test-framework.js View on Github external
export async function trashExistingPosts( postType = 'post' ) {
	await switchUserToAdmin();
	// Visit `/wp-admin/edit.php` so we can see a list of posts and delete them.
	const query = addQueryArgs( '', {
		post_type: postType,
	} ).slice( 1 );
	await visitAdminPage( 'edit.php', query );

	// If this selector doesn't exist there are no posts for us to delete.
	const bulkSelector = await page.$( '#bulk-action-selector-top' );
	if ( ! bulkSelector ) {
		return;
	}

	// Select all posts.
	await page.waitForSelector( '[id^=cb-select-all-]' );
	await page.click( '[id^=cb-select-all-]' );
	// Select the "bulk actions" > "trash" option.
	await page.select( '#bulk-action-selector-bottom', 'trash' );
	// Submit the form to send all draft/scheduled/published posts to the trash.
github keesiemeijer / related-posts-by-taxonomy / editor-block / src / components / RestRequest.js View on Github external
export function rendererPath(postID, attributes = null, urlQueryArgs = {}) {
	let queryArgs = (null !== attributes) ? attributes : {};

	// Defaults
	queryArgs.is_editor = true;
	queryArgs.related = true;
	queryArgs.gallery_format = 'editor_block';

	return addQueryArgs(`/related-posts-by-taxonomy/v1/posts/${ postID }`, {
		...queryArgs,
		...urlQueryArgs,
	});
}
github woocommerce / woocommerce-gutenberg-products-block / assets / js / blocks / reviews-by-product / block.js View on Github external
getReviews( order, page = 1 ) {
		const { attributes } = this.props;
		const { perPage, productId } = attributes;
		const { reviews } = this.state;
		const orderby = order || this.state.order || attributes.orderby;

		if ( ! productId ) {
			// We've removed the selected product, or no product is selected yet.
			return;
		}

		apiFetch( {
			path: addQueryArgs( `/wc/blocks/products/reviews`, {
				order_by: orderby,
				page,
				per_page: parseInt( perPage, 10 ) || 1,
				product_id: productId,
			} ),
			parse: false,
		} ).then( ( response ) => {
			if ( response.json ) {
				response.json().then( ( newReviews ) => {
					const totalReviews = parseInt( response.headers.get( 'x-wp-total' ), 10 );
					if ( page === 1 ) {
						this.setState( { reviews: newReviews, totalReviews } );
					} else {
						this.setState( {
							reviews: reviews.filter( ( review ) => Object.keys( review ).length ).concat( newReviews ),
							totalReviews,
github ampproject / amp-wp / assets / src / edit-story / app / api / apiProvider.js View on Github external
( { mediaType, searchTerm } ) => {
			let apiPath = media;
			const perPage = 100;
			apiPath = addQueryArgs( apiPath, { per_page: perPage } );

			if ( mediaType ) {
				apiPath = addQueryArgs( apiPath, { media_type: mediaType } );
			}

			if ( searchTerm ) {
				apiPath = addQueryArgs( apiPath, { search: searchTerm } );
			}

			return apiFetch( { path: apiPath } )
				.then( ( data ) => data.map(
					( {
						guid: { rendered: src },
						media_details: { width: oWidth, height: oHeight },
						mime_type: mimeType,
					} ) => ( {
						src,
						oWidth,
						oHeight,
						mimeType,
					} ),
				) );
		},	[ media ],
github Automattic / wp-calypso / packages / jetpack-blocks / src / blocks / vr / save.jsx View on Github external
export default ( { attributes: { url, view }, className } ) => (
	<div>
		</div>
github 10up / distributor / assets / js / admin-external-connection.js View on Github external
const successURL = addQueryArgs( document.location.href,
			{
				setupStatus: 'success',
				titleField: titleField.value,
				externalSiteUrlField: siteURL,
				restRoot: response.data.rest_url,
			}
		);

		const failureURL = addQueryArgs( document.location.href,
			{
				setupStatus: 'failure'
			}
		);

		const authURL = addQueryArgs(
			`${ siteURL }wp-admin/admin.php`,
			{
				page: 'auth_app',
				app_name: dt.distributor_from, /*eslint camelcase: 0*/
				success_url: encodeURI( successURL ), /*eslint camelcase: 0*/
				reject_url:  encodeURI( failureURL ), /*eslint camelcase: 0*/
			}
		);
		document.location = authURL;
	} );
github godaddy-wordpress / coblocks / src / blocks / post-carousel / edit.js View on Github external
componentDidMount() {
		this.isStillMounted = true;
		this.fetchRequest = apiFetch( {
			path: addQueryArgs( '/wp-json/wp/v2/categories', CATEGORIES_LIST_QUERY ),
		} ).then(
			( categoriesList ) => {
				if ( this.isStillMounted ) {
					this.setState( { categoriesList } );
				}
			}
		).catch(
			() => {
				if ( this.isStillMounted ) {
					this.setState( { categoriesList: [] } );
				}
			}
		);
	}
github Automattic / wp-calypso / apps / full-site-editing / full-site-editing-plugin / full-site-editing / blocks / template / edit.js View on Github external
withSelect( ( select, { attributes, templateClientId } ) => {
		const { getEntityRecord } = select( 'core' );
		const { getCurrentPostId, isEditedPostDirty } = select( 'core/editor' );
		const { getBlock, getSelectedBlock } = select( 'core/block-editor' );
		const { isEditorSidebarOpened } = select( 'core/edit-post' );
		const { templateId } = attributes;
		const currentPostId = getCurrentPostId();
		const template = templateId && getEntityRecord( 'postType', 'wp_template_part', templateId );
		const editTemplateUrl = addQueryArgs( fullSiteEditing.editTemplateBaseUrl, {
			post: templateId,
			fse_parent_post: currentPostId,
		} );
		const selectedBlock = getSelectedBlock();

		return {
			currentPostId,
			editTemplateUrl,
			template,
			templateBlock: getBlock( templateClientId ),
			templateTitle: get( template, [ 'title', 'rendered' ], '' ),
			isDirty: isEditedPostDirty(),
			isEditorSidebarOpened: !! isEditorSidebarOpened(),
			isAnyTemplateBlockSelected: selectedBlock && 'a8c/template' === selectedBlock.name,
		};
	} ),
github WordPress / gutenberg / editor / utils / url.js View on Github external
export function getWPAdminURL( page, query ) {
	return addQueryArgs( page, query );
}
github WordPress / gutenberg / packages / editor / src / components / post-taxonomies / flat-term-selector.js View on Github external
fetchTerms( params = {} ) {
		const { taxonomy } = this.props;
		const query = { ...DEFAULT_QUERY, ...params };
		const request = apiFetch( {
			path: addQueryArgs( `/wp/v2/${ taxonomy.rest_base }`, query ),
		} );
		request.then( unescapeTerms ).then( ( terms ) => {
			this.setState( ( state ) => ( {
				availableTerms: state.availableTerms.concat(
					terms.filter( ( term ) => ! find( state.availableTerms, ( availableTerm ) => availableTerm.id === term.id ) )
				),
			} ) );
			this.updateSelectedTerms( this.props.terms );
		} );

		return request;
	}