Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions features/site-empty.feature
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ Feature: Empty a WordPress site of its data
Success: Created post_tag 2.
"""

When I run `wp post create --post_type=page --post_title='Sample Privacy Page' --post_content='Sample Privacy Terms' --porcelain`
Then save STDOUT as {PAGE_ID}

When I run `wp option set wp_page_for_privacy_policy {PAGE_ID}`
Then STDOUT should be:
"""
Success: Updated 'wp_page_for_privacy_policy' option.
"""

When I run `wp option get wp_page_for_privacy_policy`
Then STDOUT should be:
"""
{PAGE_ID}
"""

When I run `wp site empty --yes`
Then STDOUT should be:
"""
Expand All @@ -42,6 +57,12 @@ Feature: Empty a WordPress site of its data
When I run `wp term list post_tag --format=ids`
Then STDOUT should be empty

When I run `wp option get wp_page_for_privacy_policy`
Then STDOUT should be:
"""
0
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also include a test that makes sure there's a non-zero value before wp site empty is run?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how to do that, should I create a dummy page and assign it as privacy page?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I create a dummy page and assign it as privacy page?

Yes, this would be fine.


Scenario: Empty a site and its uploads directory
Given a WP multisite installation
And I run `wp site create --slug=foo`
Expand Down
9 changes: 9 additions & 0 deletions src/Site_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ private function _insert_default_terms() {
$wpdb->insert( $wpdb->term_taxonomy, array('term_id' => $cat_id, 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 0));
}

/**
* Reset option values to default.
*/
private function _reset_options() {
// Reset Privacy Policy value to prevent error.
update_option( 'wp_page_for_privacy_policy', 0 );
}

/**
* Empties a site of its content (posts, comments, terms, and meta).
*
Expand Down Expand Up @@ -186,6 +194,7 @@ public function _empty( $args, $assoc_args ) {
$this->_empty_comments();
$this->_empty_taxonomies();
$this->_insert_default_terms();
$this->_reset_options();

if ( ! empty( $upload_message ) ) {
$upload_dir = wp_upload_dir();
Expand Down