$data ) { if ( strtolower( dirname( (string) $file ) ) === $own || empty( $data['RequiresPlugins'] ) ) { continue; } $required = array_map( 'trim', explode( ',', strtolower( (string) $data['RequiresPlugins'] ) ) ); if ( in_array( $own, $required, true ) ) { $out[] = ! empty( $data['Name'] ) ? (string) $data['Name'] : (string) $file; } } return $out; } /** * Removes the tables, the key and the data on orders of the site it runs on. * * @return void */ public static function erase() { global $wpdb; foreach ( self::TABLES as $table ) { $wpdb->query( 'DROP TABLE IF EXISTS `' . esc_sql( $wpdb->prefix . $table ) . '`' ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.SchemaChange -- the plugin's own tables, by the shop's choice. } delete_option( self::KEY_OPTION ); // The order data: in the order tables (HPOS), in the posts' meta (posts // storage, or both while they are kept in sync), and on order lines. foreach ( array( $wpdb->prefix . 'wc_orders_meta', $wpdb->postmeta, $wpdb->prefix . 'woocommerce_order_itemmeta' ) as $table ) { self::delete_meta( $table ); } } /** * Deletes the rows of a meta table whose key starts with META_PREFIX, a * chunk at a time. * * @param string $table Full table name. * @return void */ private static function delete_meta( $table ) { global $wpdb; $exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table ) ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery if ( $table !== $exists ) { return; } $like = $wpdb->esc_like( self::META_PREFIX ) . '%'; $safe = esc_sql( $table ); do { $deleted = (int) $wpdb->query( $wpdb->prepare( "DELETE FROM `{$safe}` WHERE meta_key LIKE %s LIMIT %d", $like, self::CHUNK ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery,WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- a core or WooCommerce meta table, by its own name. } while ( $deleted >= self::CHUNK ); } }