posts[] = $post; return $post; } /** * Method for cleaning up after the test. */ public function cleanup(): void { $this->delete_posts(); $this->unregister_block_templates(); } /** * Deletes user theme post that might be created during the test. */ public function cleanup_user_theme_post(): void { $post = get_page_by_path( 'wp-global-styles-mailpoet-email', OBJECT, 'wp_global_styles' ); if ( $post ) { wp_delete_post( $post->ID, true ); } } /** * Delete created posts. */ private function delete_posts(): void { foreach ( $this->posts as $post ) { wp_delete_post( $post->ID, true ); } $this->cleanup_user_theme_post(); } /** * Unregister block templates we may add during the tests. */ private function unregister_block_templates(): void { $registry = WP_Block_Templates_Registry::get_instance(); $templates = $registry->get_all_registered(); foreach ( $templates as $name => $template ) { if ( 'mailpoet' === $template->plugin && $registry->is_registered( $name ) ) { $registry->unregister( $name ); } } } }