delete( $wpdb->prefix . 'submex_charge_slot', array( 'subscription_id' => $order_id ), array( '%d' ) ); $wpdb->delete( $wpdb->prefix . 'submex_activity', array( 'subscription_id' => $order_id ), array( '%d' ) ); // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching } /** * Posts-table installs delete through WordPress rather than WooCommerce. * * @param int $post_id */ public function forget_post( $post_id ): void { if ( Subscription::TYPE === get_post_type( (int) $post_id ) ) { $this->forget( $post_id ); } } /** * Rows whose subscription is already gone, from before this existed. * * @return int Rows removed. */ public static function purge_orphans(): int { global $wpdb; $removed = 0; foreach ( array( 'submex_charge_slot', 'submex_activity' ) as $table ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- a one-off sweep of our own table. $ids = (array) $wpdb->get_col( $wpdb->prepare( 'SELECT DISTINCT subscription_id FROM %i', $wpdb->prefix . $table ) ); foreach ( $ids as $id ) { if ( wc_get_order( (int) $id ) ) { continue; } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- our own table, never cached. $removed += (int) $wpdb->delete( $wpdb->prefix . $table, array( 'subscription_id' => (int) $id ), array( '%d' ) ); } } return $removed; } }