cache_path = trailingslashit( $cache_path ); $this->config_path = $config_path; $this->tables = [ $rucss_usedcss_table, $rocket_cache, $atf_table, $lrc_table, ]; } /** * Deletes all plugin data and files on uninstall. * * @since 3.5.2 * * @return void */ public function uninstall() { $this->delete_plugin_data(); $this->delete_cache_files(); $this->delete_config_files(); foreach ( $this->tables as $table ) { $this->delete_table( $table ); } } /** * Deletes a table * * @param Table $table Table instance. * * @return void */ private function delete_table( $table ) { if ( $table->exists() ) { $table->uninstall(); } if ( ! is_multisite() ) { return; } foreach ( get_sites( [ 'fields' => 'ids' ] ) as $site_id ) { switch_to_blog( $site_id ); if ( $table->exists() ) { $table->uninstall(); } restore_current_blog(); } } /** * Deletes WP Rocket options, transients and events. * * @since 3.5.2 * * @return void */ private function delete_plugin_data() { delete_site_transient( 'wp_rocket_update_data' ); // Delete all user meta related to WP Rocket. delete_metadata( 'user', '', 'rocket_boxes', '', true ); // Delete all post meta related to WP Rocket. foreach ( $this->post_meta as $post_meta ) { delete_post_meta_by_key( "_rocket_exclude_{$post_meta}" ); } array_walk( $this->transients, 'delete_transient' ); array_walk( $this->options, 'delete_option' ); foreach ( $this->events as $event ) { wp_clear_scheduled_hook( $event ); } } /** * Deletes all WP Rocket cache files. * * @since 3.5.2 * * @return void */ private function delete_cache_files() { foreach ( $this->cache_dirs as $dir ) { $this->delete( $this->cache_path . $dir ); } } /** * Deletes all WP Rocket config files. * * @since 3.5.2 * * @return void */ private function delete_config_files() { $this->delete( $this->config_path ); } /** * Recursively deletes files and directories. * * @since 3.5.2 * * @param string $file Path to file or directory. */ private function delete( $file ) { if ( ! is_dir( $file ) ) { wp_delete_file( $file ); return; } try { $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $file, FilesystemIterator::SKIP_DOTS ), RecursiveIteratorIterator::CHILD_FIRST ); } catch ( UnexpectedValueException $e ) { return; } foreach ( $iterator as $item ) { if ( $item->isDir() ) { @rmdir( $item ); //phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_operations_rmdir continue; } wp_delete_file( $item ); } @rmdir( $file ); //phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_operations_rmdir } }