Add uninstall hook to remove ticks and tickers

This commit is contained in:
2018-11-01 15:39:58 +01:00
parent c927200834
commit 9d64f9f415
2 changed files with 34 additions and 0 deletions

View File

@ -39,4 +39,37 @@ class WPLiveticker2_System extends WPLiveticker2 {
add_option( self::OPTION, $defaults );
}
}
/**
* Plugin uninstall handler.
*
* @return void
*/
public static function uninstall() {
// Delete all ticks.
$ticks = new WP_Query( array( 'post_type' => 'wplt2_tick' ) );
foreach ( $ticks->get_posts() as $tick ) {
wp_delete_post( $tick->ID, true );
}
// Temporarily register taxonomy to delete it.
register_taxonomy( 'wplt2_ticker', array( 'wplt2_tick' ) );
// Delete tickers.
$tickers = get_terms(
array(
'taxonomy' => 'wplt2_ticker',
'hide_empty' => false,
)
);
foreach ( $tickers as $ticker ) {
wp_delete_term( $ticker->term_id, 'wplt2_ticker' );
}
// Unregister taxonomy again.
unregister_taxonomy( 'wplt2_ticker' );
// Delete the option.
delete_option( self::OPTION );
}
}