set_permalink_structure( '/%postname%/' ); flush_rewrite_rules(); break; case 'attachment_pages': update_option( 'wp_attachment_pages_enabled', 0 ); break; case 'sample_content': $s = Checks::sample_content(); foreach ( $s['posts'] as $id ) { wp_trash_post( $id ); } foreach ( $s['comments'] as $id ) { wp_trash_comment( $id ); } break; case 'host_backups': update_option( 'pumpaudit_wp_host_backups', 1, false ); break; case 'xmlrpc': update_option( 'pumpaudit_wp_xmlrpc_off', 1, true ); break; case 'database': self::clean_database(); break; } } /** * Deletes revisions beyond the last five of each post, and spam comments. */ private static function clean_database() { global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- finds the posts to tidy once. $parents = $wpdb->get_col( "SELECT post_parent FROM {$wpdb->posts} WHERE post_type = 'revision' GROUP BY post_parent HAVING COUNT(*) > 5" ); foreach ( $parents as $parent ) { $revisions = wp_get_post_revisions( (int) $parent, array( 'order' => 'DESC', 'orderby' => 'date ID', ) ); foreach ( array_slice( $revisions, 5 ) as $rev ) { wp_delete_post_revision( $rev->ID ); } } $spam = get_comments( array( 'status' => 'spam', 'fields' => 'ids', 'number' => 5000, ) ); foreach ( $spam as $id ) { wp_delete_comment( (int) $id, true ); } } }