| 1 |
<?php |
| 2 |
/** |
| 3 |
* Uninstall.php for cleaning plugin database. |
| 4 |
* |
| 5 |
* Trigger the file when plugin is deleted. |
| 6 |
* |
| 7 |
* - This method should be static |
| 8 |
* - Check if the $_REQUEST content actually is the plugin name |
| 9 |
* - Run an admin referrer check to make sure it goes through authentication |
| 10 |
* - Verify the output of $_GET makes sense |
| 11 |
* - Repeat with other user roles. Best directly by using the links/query string parameters. |
| 12 |
* - Repeat things for multisite. Once for a single site in the network, once sitewide. |
| 13 |
* |
| 14 |
* @link https://smartpostshow.com/ |
| 15 |
* @since 2.0.0 |
| 16 |
* |
| 17 |
* @package Smart_Post_Show |
| 18 |
*/ |
| 19 |
|
| 20 |
// If uninstall not called from WordPress, then exit. |
| 21 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 22 |
exit; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Collect and delete all data of the plugin. |
| 27 |
* |
| 28 |
* @return void |
| 29 |
*/ |
| 30 |
function sp_post_carousel_data_delete() { |
| 31 |
// Delete plugin option settings. |
| 32 |
$option_name = 'sp_post_carousel_settings'; |
| 33 |
delete_option( $option_name ); |
| 34 |
// For a multi-site. |
| 35 |
delete_site_option( $option_name ); |
| 36 |
// Delete Smart Post Show post type. |
| 37 |
$post_carousel_posts = get_posts( |
| 38 |
array( |
| 39 |
'numberposts' => -1, |
| 40 |
'post_type' => 'sp_post_carousel', |
| 41 |
'post_status' => 'any', |
| 42 |
) |
| 43 |
); |
| 44 |
foreach ( $post_carousel_posts as $post_carousel ) { |
| 45 |
wp_delete_post( $post_carousel->ID, true ); |
| 46 |
} |
| 47 |
|
| 48 |
// Delete Smart Post Show post meta. |
| 49 |
delete_post_meta_by_key( 'sp_pcp_layouts' ); |
| 50 |
delete_post_meta_by_key( 'sp_pcp_view_options' ); |
| 51 |
} |
| 52 |
|
| 53 |
// Load Smart Post Show file. |
| 54 |
require plugin_dir_path( __FILE__ ) . '/main.php'; |
| 55 |
$pcp_options = get_option( 'sp_post_carousel_settings' ); |
| 56 |
$delete_data = isset( $pcp_options['pcp_delete_all_data'] ) ? $pcp_options['pcp_delete_all_data'] : false; |
| 57 |
|
| 58 |
if ( $delete_data ) { |
| 59 |
sp_post_carousel_data_delete(); |
| 60 |
} |
| 61 |
|