'ids', 'number' => 0, ) ); foreach ( $site_ids as $site_id ) { switch_to_blog( (int) $site_id ); self::maybe_purge(); restore_current_blog(); } } /** * Deletes everything on the current site when the owner asked for it. * * @return void */ private static function maybe_purge(): void { foreach ( Cron::hooks() as $hook ) { wp_unschedule_hook( $hook ); } $settings = get_option( Settings::OPTION, array() ); if ( ! is_array( $settings ) || empty( $settings['delete_data_on_uninstall'] ) ) { return; } global $wpdb; foreach ( Tables::all() as $table ) { $wpdb->query( "DROP TABLE IF EXISTS {$table}" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching,WordPress.DB.DirectDatabaseQuery.SchemaChange,WordPress.DB.PreparedSQL.InterpolatedNotPrepared,PluginCheck.Security.DirectDB.UnescapedDBParameter -- Table names come from the Schema whitelist. } ( new Capabilities() )->uninstall(); foreach ( self::option_names() as $option ) { delete_option( $option ); } foreach ( array( '_transient_interviewnea_', '_transient_timeout_interviewnea_' ) as $prefix ) { $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s", $wpdb->esc_like( $prefix ) . '%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching } do_action( 'interviewnea_uninstall_purge' ); } /** * Every option the plugin creates. * * @return string[] */ private static function option_names(): array { return array( Installer::VERSION_OPTION, Installer::PREFIX_OPTION, 'interviewnea_installed_at', 'interviewnea_reminders_scheduled_for', Migrator::VERSION_OPTION, Migrator::ERROR_OPTION, Migrator::LOCK_OPTION, Settings::OPTION, ); } }