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.
export async function deactivateAllOtherPlugins() {
await switchUserToAdmin();
if ( ! isCurrentURL( 'wp-admin/plugins.php' ) ) {
await visitAdminPage( 'plugins.php' );
}
await page.waitForSelector( 'input[type="checkbox"][value="google-site-kit/google-site-kit.php"]' );
const activePlugins = await page.$$eval( '.active[data-plugin]', ( rows ) => {
return rows.map( ( row ) => row.dataset.plugin );
} );
// Bail if there are no plugins to deactivate
if ( 1 === activePlugins.length && 'google-site-kit/google-site-kit.php' === activePlugins[ 0 ] ) {
return;
}
// Select all plugins
async function trashExistingPosts() {
await switchUserToAdmin();
// Visit `/wp-admin/edit.php` so we can see a list of posts and delete them.
await visitAdminPage( 'edit.php' );
// 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( '#cb-select-all-1' );
await page.click( '#cb-select-all-1' );
// Select the "bulk actions" > "trash" option.
await page.select( '#bulk-action-selector-top', 'trash' );
// Submit the form to send all draft/scheduled/published posts to the trash.
await page.click( '#doaction' );
async function trashExistingPosts() {
await switchUserToAdmin();
// Visit `/wp-admin/edit.php` so we can see a list of posts and delete them.
await visitAdminPage( 'edit.php' );
// 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( '#cb-select-all-1' );
await page.click( '#cb-select-all-1' );
// Select the "bulk actions" > "trash" option.
await page.select( '#bulk-action-selector-top', 'trash' );
// Submit the form to send all draft/scheduled/published posts to the trash.
export async function deleteTheme( slug, newThemeSlug, newThemeSearchTerm ) {
await switchUserToAdmin();
if ( newThemeSlug ) {
await installTheme( newThemeSlug, newThemeSearchTerm );
await activateTheme( newThemeSlug );
} else {
await visitAdminPage( 'themes.php' );
}
if ( ! await themeInstalled( slug ) ) {
await switchUserToTest();
return;
}
await page.click( `[data-slug="${ slug }"]` );
await page.waitForSelector( '.theme-actions .delete-theme' );
await page.click( '.theme-actions .delete-theme' );