Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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.
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,
});
}
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,
( { 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 ],
export default ( { attributes: { url, view }, className } ) => (
<div>
</div>
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;
} );
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: [] } );
}
}
);
}
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,
};
} ),
export function getWPAdminURL( page, query ) {
return addQueryArgs( page, query );
}
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;
}