'aumnexcart_product', 'post_status' => 'any', 'numberposts' => -1, 'fields' => 'ids', 'no_found_rows' => true, ) ); if ( ! empty( $aumnexcart_product_ids ) ) { foreach ( $aumnexcart_product_ids as $aumnexcart_product_id ) { wp_delete_post( $aumnexcart_product_id, true ); } } /* * Remove taxonomy terms. * * `uninstall.php` runs in a request where the plugin never booted, so neither the post type nor the * taxonomy is registered. `wp_delete_post()` does not care, but `get_terms()` refuses an unregistered * taxonomy and returns `WP_Error: Invalid taxonomy` — which the guard below used to swallow, leaving * every category behind for good while this file's header claimed otherwise. Register the taxonomy * for the length of this request so both the lookup and `wp_delete_term()` (which also clears * relationships, term meta and the children cache) behave normally. */ if ( ! taxonomy_exists( 'aumnexcart_category' ) ) { register_taxonomy( 'aumnexcart_category', 'aumnexcart_product', array( 'hierarchical' => true ) ); } $aumnexcart_terms = get_terms( array( 'taxonomy' => 'aumnexcart_category', 'hide_empty' => false, 'fields' => 'ids', ) ); if ( ! is_wp_error( $aumnexcart_terms ) && ! empty( $aumnexcart_terms ) ) { foreach ( $aumnexcart_terms as $aumnexcart_term_id ) { wp_delete_term( $aumnexcart_term_id, 'aumnexcart_category' ); } } /* Sweep orphan postmeta with the plugin prefix (safety net). */ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE %s", $wpdb->esc_like( '_aumnexcart_' ) . '%' ) ); /* Core's own hierarchy cache for the taxonomy — written by core, prefixed with our name. */ delete_option( 'aumnexcart_category_children' ); /* Clear any plugin transients. */ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s", $wpdb->esc_like( '_transient_aumnexcart_' ) . '%', $wpdb->esc_like( '_transient_timeout_aumnexcart_' ) . '%' ) );