How to use the @wordpress/url.getQueryArg 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 google / site-kit-wp / tests / e2e / config / bootstrap.js View on Github external
function observeRestRequest( req ) {
	if ( req.url().match( 'wp-json' ) ) {
		// eslint-disable-next-line no-console
		console.log( '>>>', req.method(), req.url(), req.postData() );
	}
	if ( req.url().match( 'google-site-kit/v1/data/' ) ) {
		const rawBatchRequest = getQueryArg( req.url(), 'request' );
		try {
			const batchRequests = JSON.parse( rawBatchRequest );
			if ( Array.isArray( batchRequests ) ) {
				batchRequests.forEach( ( r ) => {
					// eslint-disable-next-line no-console
					console.log( '>>>', r.key, r.data );
				} );
			}
		} catch {}
	}
}
github Automattic / vip-go-mu-plugins-built / jetpack / extensions / shared / components / stripe-nudge / index.jsx View on Github external
export default ( { blockName, postId, stripeConnectUrl } ) => {
	if ( ! isURL( stripeConnectUrl ) ) {
		return null;
	}

	let url = stripeConnectUrl;

	if ( postId ) {
		try {
			const state = getQueryArg( stripeConnectUrl, 'state' );
			const decodedState = JSON.parse( atob( state ) );
			decodedState.from_editor_post_id = postId;
			url = addQueryArgs( stripeConnectUrl, { state: btoa( JSON.stringify( decodedState ) ) } );
		} catch ( err ) {
			if ( process.env.NODE_ENV !== 'production' ) {
				console.error( err ); // eslint-disable-line no-console
			}
		}
	}

	return (
github ampproject / amp-wp / assets / src / setup / components / site-scan-context-provider.js View on Github external
useEffect( () => {
		if ( ! scanningSite && ! pluginIssues ) {
			setPluginIssues( getQueryArg( global.location.href, 'amp-plugin-issues' ) ? [ 'Plugin issue 1' ] : null ); // URL param is for testing.
		}
	}, [ scanningSite, pluginIssues ] );
github ampproject / amp-wp / assets / src / setup / components / site-scan-context-provider.js View on Github external
useEffect( () => {
		if ( ! scanningSite && ! themeIssues ) {
			setThemeIssues( getQueryArg( global.location.href, 'amp-theme-issues' ) ? [ 'Theme issue 1' ] : null ); // URL param is for testing.
		}
	}, [ scanningSite, themeIssues ] );
github ampproject / amp-wp / assets / src / setup / components / options-context-provider.js View on Github external
( async () => {
			setFetchingOptions( true );

			try {
				const fetchedOptions = await apiFetch( { url: addQueryArgs( optionsRestEndpoint, { 'amp-new-onboarding': '1' } ) } );

				if ( true === hasUnmounted.current ) {
					return;
				}

				setSavedThemeSupport( fetchedOptions.theme_support );
				setOptions(
					true === fetchedOptions.wizard_completed && ! getQueryArg( global.location.href, 'setup-wizard-first-run' ) // Query arg available for testing.
						? { ...fetchedOptions, theme_support: null } // Reset mode for the current session to force user to make a choice.
						: {},
				);
			} catch ( e ) {
				setError( e );
				return;
			}

			setFetchingOptions( false );
		} )();
	}, [ fetchingOptions, options, optionsRestEndpoint, setError ] );
github woocommerce / woocommerce-gutenberg-products-block / assets / js / base / hooks / use-url-query-string.js View on Github external
Object.keys( urlKeysAndDefaults ).forEach( ( urlKey ) => {
			const queryStringValue = getQueryArg(
				window.location.href,
				`${ urlKey }_${ queryStateContext }`
			);
			urlState[ urlKey ] =
				queryStringValue || urlKeysAndDefaults[ urlKey ];
		} );
	}
github Automattic / wp-calypso / apps / wpcom-block-editor / src / calypso / iframe-bridge-server.js View on Github external
editTemplatePartLinks.forEach( link => {
		const templatePartId = parseInt( getQueryArg( link.getAttribute( 'href' ), 'post' ), 10 );

		const { port1, port2 } = new MessageChannel();
		calypsoPort.postMessage(
			{
				action: 'getTemplatePartEditorUrl',
				payload: { templatePartId },
			},
			[ port2 ]
		);
		port1.onmessage = ( { data } ) => {
			link.setAttribute( 'target', '_parent' );
			link.setAttribute( 'href', data );
		};
	} );
}
github Automattic / wp-calypso / apps / wpcom-block-editor / src / calypso / iframe-bridge-server.js View on Github external
},
				false
			);

			//overrides the all posts link just in case the user treats the link... as a link.
			if ( calypsoifyGutenberg && calypsoifyGutenberg.closeUrl ) {
				lockedDialogButtons[ 0 ].setAttribute( 'target', '_parent' );
				lockedDialogButtons[ 0 ].setAttribute( 'href', calypsoifyGutenberg.closeUrl );
			}

			//changes the Take Over link url to add the frame-nonce
			lockedDialogButtons[ 2 ].setAttribute(
				'href',
				addQueryArgs( lockedDialogButtons[ 2 ].getAttribute( 'href' ), {
					calypsoify: 1,
					'frame-nonce': getQueryArg( window.location.href, 'frame-nonce' ),
				} )
			);

			unsubscribe();
		}
	} );
}
github Automattic / wp-calypso / apps / wpcom-block-editor / src / calypso / iframe-bridge-server.js View on Github external
$( '#editor' ).on( 'click', customizerLinkSelector, e => {
		e.preventDefault();

		calypsoPort.postMessage( {
			action: 'openCustomizer',
			payload: {
				unsavedChanges: select( 'core/editor' ).isEditedPostDirty(),
				autofocus: getQueryArg( e.currentTarget.href, 'autofocus' ),
			},
		} );
	} );
}
github woocommerce / woocommerce-gutenberg-products-block / assets / js / base / hocs / with-query-string-values.js View on Github external
values.forEach( ( value ) => {
					state[ value ] = getQueryArg(
						window.location.href,
						value + this.urlParameterSuffix
					);
				} );
			}