| 1 |
<?php |
| 2 |
/** |
| 3 |
* Audio Player Block – Advanced Block for Embedding Audio Files Uninstall |
| 4 |
* |
| 5 |
* This file is called when the plugin is deleted from the WordPress admin dashboard. |
| 6 |
* It cleans up all the data stored by the plugin in the database. |
| 7 |
*/ |
| 8 |
|
| 9 |
// If uninstall not called from WordPress, exit. |
| 10 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
// Only delete data if user has enabled this setting |
| 15 |
if ( get_option( 'bpmp_delete_data_on_uninstall', false ) ) { |
| 16 |
// Delete all audio_player_block custom posts |
| 17 |
$audio_player_posts = get_posts( array( |
| 18 |
'post_type' => 'audio_player_block', |
| 19 |
'numberposts' => -1, |
| 20 |
'post_status' => 'any', |
| 21 |
'fields' => 'ids', |
| 22 |
) ); |
| 23 |
|
| 24 |
if ( ! empty( $audio_player_posts ) ) { |
| 25 |
foreach ( $audio_player_posts as $post_id ) { |
| 26 |
wp_delete_post( $post_id, true ); // Force delete (bypasses trash) |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
// Delete the uninstall option itself |
| 31 |
delete_option( 'bpmp_delete_data_on_uninstall' ); |
| 32 |
} |
| 33 |
|