[Bug] Plugin deletes posts on uninstall
-
When uninstalling, the plugin will delete “post” entries and not just “codes”. A client had to pull his backup two times as he didn’t know what was happening.
We’ve checked the code and it seems to be a misnamed variable. This is affecting the latest version (1.1.8).
File: uninstall.php
Lines: 17-19.On line 17, an array ($ccc_post_types) is being created with the post_types to delete, however, when in the foreach loop, you’re trying to call $post_type thus resulting in a null value. This makes wordpress use the default value for the post_type field which is “post”, thus deleting posts instead of the “codes”.
As a suggestion, the post_type supports arrays thus there is no need to use a foreach to target each post_type. A simple solution would be:
$ccc_post_types = array("ccc_codes", "ccc_contestants"); $posts = get_posts( array( 'post_type' => $ccc_post_types, 'post_status' => 'any', 'numberposts' => -1, 'fields' => 'ids' ) ); if ( $posts ) { foreach ( $posts as $p ) { wp_delete_post( $p, true); } }
Thanks.
- The topic ‘[Bug] Plugin deletes posts on uninstall’ is closed to new replies.