Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 {}
}
}
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 (
useEffect( () => {
if ( ! scanningSite && ! pluginIssues ) {
setPluginIssues( getQueryArg( global.location.href, 'amp-plugin-issues' ) ? [ 'Plugin issue 1' ] : null ); // URL param is for testing.
}
}, [ scanningSite, pluginIssues ] );
useEffect( () => {
if ( ! scanningSite && ! themeIssues ) {
setThemeIssues( getQueryArg( global.location.href, 'amp-theme-issues' ) ? [ 'Theme issue 1' ] : null ); // URL param is for testing.
}
}, [ scanningSite, themeIssues ] );
( 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 ] );
Object.keys( urlKeysAndDefaults ).forEach( ( urlKey ) => {
const queryStringValue = getQueryArg(
window.location.href,
`${ urlKey }_${ queryStateContext }`
);
urlState[ urlKey ] =
queryStringValue || urlKeysAndDefaults[ urlKey ];
} );
}
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 );
};
} );
}
},
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();
}
} );
}
$( '#editor' ).on( 'click', customizerLinkSelector, e => {
e.preventDefault();
calypsoPort.postMessage( {
action: 'openCustomizer',
payload: {
unsavedChanges: select( 'core/editor' ).isEditedPostDirty(),
autofocus: getQueryArg( e.currentTarget.href, 'autofocus' ),
},
} );
} );
}
values.forEach( ( value ) => {
state[ value ] = getQueryArg(
window.location.href,
value + this.urlParameterSuffix
);
} );
}